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

前端 未结 8 876
陌清茗
陌清茗 2020-12-08 00:30

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

let app = XCUIApplication()
app.launchEnviro         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 01:06

    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.

提交回复
热议问题