Ramy Al Zuhouri
Ramy Al Zuhouri

Reputation: 21986

XCTest cannot read launch arguments

I am running a UI test and in the setUp() method I set a launch argument:

self.app = XCUIApplication()
self.app.launch()        
self.app.launchArguments.append("UITesting")

Then later in the testI try to read the launch argument this way:

if ProcessInfo.processInfo.arguments.contains("UITesting") {
    // do something
}

But the code inside the if is never executed. How to make it work?

Upvotes: 1

Views: 744

Answers (1)

Roman Zakharov
Roman Zakharov

Reputation: 2273

You cannot set launch arguments after the app is already launched.

You shall set the launch arguments and environment variables, and then launch the app

    app.launchArguments.append("UITesting")
    app.launch() 

Upvotes: 3

Related Questions