Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCUIApplication().launch() never completes

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!

like image 375
mz2 Avatar asked Jun 13 '26 13:06

mz2


1 Answers

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.

like image 78
Lindsay Landry Avatar answered Jun 17 '26 23:06

Lindsay Landry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!