Reputation: 4702
I am attempting to run UI tests for a sandboxed, NSDocument based OSX application target for the first time and I am hitting an issue with both Xcode 7.2.1 and 7.3 beta 3 whereby the XCUIApplication().launch()
call in the setup stage gets stuck and eventually times out with the error message below, though the application is actually in a runnable state and works fine for recording test steps etc.
The error message I am seeing is as follows:
UI Testing Failure - App state is still not running, state = XCApplicationStateNotRunning
I have not customised the setup stage of the test in any way. The relevant launch call looks like this:
let app = XCUIApplication()
app.launch()
Any ideas? Are there ways of forcibly communicating a new state to the XCUIApplication instance, or for sending notifications or whatever it is that it is listening in the proxied application, to it?
I can see (and have also myself commented to) this Developer Forum post on what looks to be the same issue: https://forums.developer.apple.com/thread/30390
NOTE: I reported this as a bug on Radar and was sent back a response suggesting one of the late Xcode 7.3 betas would fix it. Indeed this Xcode bug has been fixed and the issue no longer occurs when running my UI tests with Xcode 7.3 at least for the scenario I hit with my application!
Upvotes: 3
Views: 2133
Reputation: 4897
I faced this problem as well, especially when running UI tests with bots. Every other test would fail out with this error due to the previous test not being shut down properly.
To avoid this, during your test setup phase, add the following line:
XCUIApplication().terminate()
Thus, your setup function will look similar to the following:
override func setUp() {
XCUIApplication().terminate()
super.setUp()
continueAfterFailure = false
XCUIApplication().launch()
}
This is a bit redundant, as the terminate command is also in the override func tearDown
function, but should ensure a proper testing environment.
Upvotes: 3