xcrun類似安卓系統(tǒng)下的ADB命令。
了解這些相關(guān)工具惫霸,能夠給測(cè)試的執(zhí)行、開(kāi)展帶來(lái)很多便利條件葱弟。
蘋果提供了一個(gè)命令行工具來(lái)與iOS模擬器進(jìn)行交互壹店。這與安卓的adb命令非常相似。我們可以在Applications/Xcode.app/Contents/Developer/usr/bin/simctl路徑找到芝加。
這是XCode內(nèi)置的命令硅卢,所以在使用的時(shí)候要在該命令前面加上x(chóng)crun射窒。
---------------------
常用命令:
列出可用模擬器
$ xcrun simctl list
列出正在運(yùn)行的模擬器
$ xcrun simctl list devices
讓模擬器打開(kāi)網(wǎng)頁(yè)
xcrun simctl openurl booted "https://reg.163.com"
同樣我們可以通過(guò)URL Scheme方式一樣打開(kāi)一個(gè)app
xcrun simctl openurl booted "com.netease.preciousMetal.dev"
關(guān)閉、重置将塑、啟動(dòng)
$ xcrun simctl shutdown booted
$ xcrun simctl erase "60613B62-A648-4149-BE64-9E6CBD5DBD30"
xcrun simctl help
可以看到相關(guān)命令用法:
Subcommands:
create? ? ? ? ? ? ? Create a new device.
clone? ? ? ? ? ? ? Clone an existing device.
upgrade? ? ? ? ? ? Upgrade a device to a newer runtime.
delete? ? ? ? ? ? ? Delete a device or all unavailable devices.
pair? ? ? ? ? ? ? ? Create a new watch and phone pair.
unpair? ? ? ? ? ? ? Unpair a watch and phone pair.
pair_activate? ? ? Set a given pair as active.
erase? ? ? ? ? ? ? Erase a device's contents and settings.
boot? ? ? ? ? ? ? ? Boot a device.
shutdown? ? ? ? ? ? Shutdown a device.
rename? ? ? ? ? ? ? Rename a device.
getenv? ? ? ? ? ? ? Print an environment variable from a running device.
openurl? ? ? ? ? ? Open a URL in a device.
addmedia? ? ? ? ? ? Add photos, live photos, videos, or contacts to the library of a device.
install? ? ? ? ? ? Install an app on a device.
uninstall? ? ? ? ? Uninstall an app from a device.
get_app_container? Print the path of the installed app's container
launch? ? ? ? ? ? ? Launch an application by identifier on a device.
terminate? ? ? ? ? Terminate an application by identifier on a device.
spawn? ? ? ? ? ? ? Spawn a process by executing a given executable on a device.
list? ? ? ? ? ? ? ? List available devices, device types, runtimes, or device pairs.
icloud_sync? ? ? ? Trigger iCloud sync on a device.
pbsync? ? ? ? ? ? ? Sync the pasteboard content from one pasteboard to another.
pbcopy? ? ? ? ? ? ? Copy standard input onto the device pasteboard.
pbpaste? ? ? ? ? ? Print the contents of the device's pasteboard to standard output.
help? ? ? ? ? ? ? ? Prints the usage for a given subcommand.
io? ? ? ? ? ? ? ? ? Set up a device IO operation.
diagnose? ? ? ? ? ? Collect diagnostic information and logs.
logverbose? ? ? ? ? enable or disable verbose logging for a device
多模擬器同時(shí)check視覺(jué)效果
如果有視覺(jué)問(wèn)題脉顿,需要確認(rèn)在各種屏幕上的顯示效果,可以采取該方法点寥。
首先使用xcrun? simctl list devices查找需要的機(jī)型的UUID
UUID?是 通用唯一識(shí)別碼(Universally Unique Identifier)的縮寫
找到iOS 12下面代表各個(gè)屏幕尺寸機(jī)型的UUID
實(shí)驗(yàn)過(guò)程:
#1.首先打開(kāi)模擬器應(yīng)用
open "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/"
#2.然后啟動(dòng)待測(cè)試的模擬器(分別對(duì)應(yīng)截圖中的UUID標(biāo)志符字符串)
xcrun simctl boot "EC7372BD-DAD0-486E-9D15-61521B5837A4"
xcrun simctl boot "84150271-D363-4B47-8AA9-E2635CF55F3B"
xcrun simctl boot "747E2529-2FC3-4CD0-8AE1-E6F875EC6A31"
xcrun simctl boot "697BF2CA5-7981-4E0F-A532-EC543001413C"
xcrun simctl boot "5D17BD6F-C080-4898-A1D1-855F0C890937"
xcrun simctl boot "94B0F54A-BB47-496F-A8F7-746F581AEF73"
#3.在模擬器上安裝待測(cè)試的app艾疟,下面的變量其實(shí)是Xcode的環(huán)境變量,在run script中直接使用即可
xcrun simctl install "EC7372BD-DAD0-486E-9D15-61521B5837A4" "/Users/lipeng/Desktop/DevFiles/PreciousMetalsDev.app"
xcrun simctl install "84150271-D363-4B47-8AA9-E2635CF55F3B" "/Users/lipeng/Desktop/DevFiles/PreciousMetalsDev.app"
xcrun simctl install "747E2529-2FC3-4CD0-8AE1-E6F875EC6A31" "/Users/lipeng/Desktop/DevFiles/PreciousMetalsDev.app"
xcrun simctl install "697BF2CA5-7981-4E0F-A532-EC543001413C" "/Users/lipeng/Desktop/DevFiles/PreciousMetalsDev.app"
xcrun simctl install "5D17BD6F-C080-4898-A1D1-855F0C890937" "/Users/lipeng/Desktop/DevFiles/PreciousMetalsDev.app"
xcrun simctl install "94B0F54A-BB47-496F-A8F7-746F581AEF73" "/Users/lipeng/Desktop/DevFiles/PreciousMetalsDev.app"
#4.最后打開(kāi)應(yīng)用
xcrun simctl launch "EC7372BD-DAD0-486E-9D15-61521B5837A4" "com.netease.gold.dev"
xcrun simctl launch "84150271-D363-4B47-8AA9-E2635CF55F3B" "com.netease.gold.dev"
xcrun simctl launch "747E2529-2FC3-4CD0-8AE1-E6F875EC6A31" "com.netease.gold.dev"
xcrun simctl launch "697BF2CA5-7981-4E0F-A532-EC543001413C" "com.netease.gold.dev"
xcrun simctl launch "5D17BD6F-C080-4898-A1D1-855F0C890937" "com.netease.gold.dev"
xcrun simctl launch "694B0F54A-BB47-496F-A8F7-746F581AEF73" "com.netease.gold.dev"
---------------------
可能要求性能比較強(qiáng)敢辩,哈哈哈蔽莱,15寸MacBook走起。