[英]How to run xcodebuild test command from swift?
我有一个ios项目,其中编写了ios ui测试用例。
现在,我创建了另一个osx(swift)命令行工具,并且在主文件中,我想运行ios项目ui测试。
为此,我使用以下命令:
xcodebuild test -project /Users/usernamer/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj -scheme ios-ui-automation-demo -destination 'platform=iOS Simulator,name=iPad Air'
如果我从终端运行此命令,则ios项目ui test会正常运行。
但是,如果我从osx命令行工具swift文件(在新的OSX项目中)运行命令,则会显示错误。 该代码是
import Foundation
func shell(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/xcodebuild"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
print("This is test version edit")
shell("xcodebuild test -project /Users/username/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj -scheme ios-ui-automation-demo -destination 'platform=iOS Simulator,name=iPad Air'")
此代码显示以下错误:
xcodebuild: error: The directory /Users/username/Library/Developer/Xcode/DerivedData/automationProject-brxvyfplrimnekchsaaenmecydkp/Build/Products/Debug does not contain an Xcode project.
Program ended with exit code: 9
在这里,automationProject是osx项目名称,我从中运行主文件以运行ios ui测试。
请帮助我,我的错误是什么。
使用task.launchPath如下:
task.launchPath = "/usr/bin/env"
最后使用如下功能:
shell("xcodebuild", "test","-project","/Users/username/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj","-scheme","ios-ui-automation-demo","-destination","platform=iOS Simulator,name=iPad Air")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.