Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access launchEnvironment and launchArguments set in XCUIApplication, running UI tests in XCode?

I've tried setting attributes in the XCUIApplication instance, in my UI Tests setUp()

let app = XCUIApplication() app.launchEnvironment = ["testenv" : "testenvValue"] app.launchArguments = ["anArgument"] app.launch() 

in didFinishLaunch I've tried to show these on screen when I run my UITests

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {     if launchOptions != nil {         for (key, value) in launchOptions! {               let alertView = UIAlertView(title: key.description, message: value.description, delegate: nil, cancelButtonTitle: "ok")             alertView.show()         }     } 

But I can't seem to be able to find the arguments and environment I set. Anyone know how to get a hold of them?

like image 396
bogen Avatar asked Oct 07 '15 09:10

bogen


People also ask

How do I test UI in Xcode?

When you're ready to test, go to a test class and place the cursor inside the test method to record the interaction. From the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test.


1 Answers

If you set launchArguments in a UI Test (Swift):

let app = XCUIApplication() app.launchArguments.append("SNAPSHOT") app.launch() 

Then read them in your App using:

swift 2.x:

if NSProcessInfo.processInfo().arguments.contains("SNAPSHOT") {    // Do snapshot setup } 

Swift 3.0

if ProcessInfo.processInfo.arguments.contains("SNAPSHOT") { } 

To set environment variables, use launchEnvironment and NSProcessInfo.processInfo().environment, respectively, instead.

like image 187
Joey C. Avatar answered Sep 20 '22 23:09

Joey C.