Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
931 views
in Technique[技术] by (71.8m points)

ios - Xcode UI Test environment variables not being passed from Scheme

In Xcode 9.2, for my iOS app, I have a Scheme for running my UI Test suite. In this scheme, under the "Test" tab, I have both environment variables and arguments defined. When my tests run, these variables aren't available to my app code.

However, I am able to programmatically set both the arguments and the launchEnvironment in the test code, and those ones are available to the app while it's running under test.

I also have environment variables and arguments set in the "Run" tab, and those are available when I merely run the app in the simulator. They are not available when I run my UI tests, regardless of whether I have "Use the Run action's arguments and environment variables" toggled on.

To see the values of the args and env vars, I have a breakpoint set in my applicationDidFinishLaunching, and I po ProcessInfo.processInfo.environment and po ProcessInfo.processInfo.arguments.

Am I setting something incorrectly here?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Launch arguments and launch environments provided in the scheme editor are passed only to UI test runner. You can read those values only in UI test classes.

If you want to pass those values to the application itself you have to do it in the code:

let app = XCUIApplication()
app.launchArguments = ["amandaArgument"]
app.launchEnvironment = ["AMANDA_UI_TESTING": "Value"]
app.launch()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...