Xcode-Instruments cannot run app on simulator with

2019-09-01 02:12发布

问题:

I am trying to run an automation on an iOS App using UIAutomation with Instruments.

It had worked well when I had tried it out a few weeks back. However, I tried out another automation testing framework (KIF from Square) in the meantime, and now when I try and run Automation with Instruments, it refuses to work.

When it had worked, I had carried out the following steps:

  1. Open my app in Xcode
  2. Run the app
  3. Quit the iOS simulator
  4. Open Instruments (not necessarily through Xcode, but just by searching for Instruments in Spotlight), choose Automation
  5. Instruments opens, and when I click on Choose target, I do not need to browse for the target. I can see the name of my app in the list (description: the app name is without the .app extension and has an icon before the name like the icon which appears at the top of the output window in Xcode - a black and white icon with a gradient) even though I haven’t opened it before i.e even when I had opened Instruments for the first time.
  6. I choose this target from the list, choose a javascript file for the automation to run, and then click ‘Record’. The automation used to run and I could see it run in the simulator which used to open up.

However, opening Instruments no longer shows me the target in the list of targets anymore.

I have tried choosing a target from my filesystem (from the Derived Data folder) as well as from the iPhone Simulator applications folder; but no luck. The target does not appear as it used to before (in the description above), but appears with a .app extension and with the typical application icon. The automation does start and open up the simulator, but gives the following message: (although the page or the script haven't changed at all)

Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().elements()[2]

(Would have liked to post images, but can't, since I am a new user and do not have the required permissions yet - hope the description makes up for it)

Have been stuck on this issue for long and any help would be appreciated! Thanks so much!

回答1:

I just profiled the app using Product -> Profile in Xcode, and that opened up Instruments with the target. The target was the Unix executable under Derived Data -> MyApp -> Build Products -> Release-iphonesimulator -> MyApp.app -> MyApp unix executable.

Also, while using KIF, I had enabled accessibility labels for some views in the storyboard. While running the automation tests in Instruments, the app seemed to somehow consider the views which had the accessibility labels set as one single element and could not access sub-elements on this view. In order to run with Instruments, I just disabled the accessibility labels for the views and it worked like a charm again!