Xcode UI测试环境变量未从Scheme传递 [英] Xcode UI Test environment variables not being passed from Scheme

查看:82
本文介绍了Xcode UI测试环境变量未从Scheme传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode 9.2中,对于我的iOS应用,我有一个用于运行UI测试套件的方案.在此方案中,在测试"选项卡下,我同时定义了环境变量和参数.当我运行测试时,这些变量对我的应用程序代码不可用.

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.

但是,我能够以编程方式在测试代码中设置参数和launchEnvironment,并且这些参数在应用程序正在测试下运行时可供应用程序使用.

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.

我还在运行"选项卡中设置了环境变量和参数,当我仅在模拟器中运行应用程序时,这些变量和参数就可用.无论我是否启用了使用运行操作的参数和环境变量",在运行UI测试时它们均不可用.

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.

要查看args和env var的值,我在applicationDidFinishLaunchingpo ProcessInfo.processInfo.environmentpo ProcessInfo.processInfo.arguments中设置了一个断点.

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?

推荐答案

方案编辑器中提供的启动参数和启动环境仅传递给UI测试运行程序.您只能在UI测试类中读取这些值.

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()

这篇关于Xcode UI测试环境变量未从Scheme传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆