问题描述
我已经尝试在我的UI测试 setUp()
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
当我运行我的UITests时,我试图在屏幕上显示这些
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?
推荐答案
如果设置 launchArguments
在UI测试中(Swift):
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") {
}
要设置环境变量,请使用<$ c分别是$ c> launchEnvironment 和 NSProcessInfo.processInfo()。environment
。
To set environment variables, use launchEnvironment
and NSProcessInfo.processInfo().environment
, respectively, instead.
这篇关于如何访问在XCUIApplication中设置的launchEnvironment和launchArguments,在XCode中运行UI测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!