Helper Helper - 4 months ago 27x
Swift Question

run xcodebuild test command from swift

i have an ios project where i have written my ios ui testcases.

Now i have created another osx(swift) command line tool and there from main file, i want to run my ios project ui tests.

For this, i use the below command:

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'

if i run this command from the terminal, than ios project ui test run properly.

But if i run the command from my osx command line tool swift file(In a new OSX project), this shows an error. The code is

import Foundation

func shell(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/xcodebuild"
task.arguments = args
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'")

this code shows the following error:

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

here automationProject is the osx project name from where i run my main file to run the ios ui test.

Please help me what is my error.


use the task.launchPath as below:

 task.launchPath = "/usr/bin/env"

and finally use the function like below:

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