[英]run the terminal “scan” command from swift code
我已經安裝了掃描程序以自動化我的測試過程。 我使用以下網站上的流程: http : //qualitytesting.tumblr.com/post/141771752059/run-a-subset-of-xctest-tests-with-fastlanescan
我有兩個項目,一個是ios,另一個是運行ios項目的Osx。
在osx項目中,我初始化掃描文件,然后在其中添加ios項目的方案。
當我運行
scan
從終端命令,它將成功運行ios項目。
但是,如果我使用下面的代碼:
class func shell(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.currentDirectoryPath = "/Users/username/Desktop/Xocde/mainSwiftAutomation/"
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
然后調用如下函數:
classname.shell("scan")
它顯示以下錯誤:
env: scan: No such file or directory
請幫忙。
如果您進行更改,掃描將運行
task.launchPath = "/usr/bin/env"
至
task.launchPath = "/usr/local/bin/scan"
如果您的掃描儀安裝在那里。 這是我機器上的問題。
該應用程序仍然無法找到xcpretty來生成報告,但是我的UI測試可以運行。
如果將帶有shebang的代碼( #!/usr/bin/env swift
)添加到常規的run_tests.swift
文件(而不是命令行工具項目)中,那么您應該能夠在命令行中運行它而不會出現問題:
$ swift run_tests.swift
...這是通過Swift代碼而不是Xcode運行測試的。
我已經解決了這個問題,如下所示:
我在使用scan命令的地方創建了shell腳本,而不是在我的項目文件夾中找到shell腳本並使用我的代碼運行它。
但是我將工作路徑更改為
task.launchPath = "/usr/local/bin/scan"
然后從命令行轉到/ usr / local / bin / scan並使其可執行,如下所示:
sudo chmod +x /usr/local/bin/scan
最終,我運行了我的shell腳本,並且運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.