如何从 swift 运行 xcodebuild 测试命令?
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 测试 运行 正确。
但是如果我 运行 来自我的 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")
我有一个 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 测试 运行 正确。
但是如果我 运行 来自我的 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")