xcrun类似安卓系统下的ADB命令。
了解这些相关工具,能够给测试的执行、开展带来很多便利条件。
苹果提供了一个命令行工具来与iOS模拟器进行交互。这与安卓的adb命令非常相似。我们可以在Applications/Xcode.app/Contents/Developer/usr/bin/simctl路径找到。
这是XCode内置的命令,所以在使用的时候要在该命令前面加上xcrun。
---------------------
常用命令:
列出可用模拟器
$ xcrun simctl list
列出正在运行的模拟器
$ xcrun simctl list devices
让模拟器打开网页
xcrun simctl openurl booted "https://reg.163.com"
同样我们可以通过URL Scheme方式一样打开一个app
xcrun simctl openurl booted "com.netease.preciousMetal.dev"
关闭、重置、启动
$ xcrun simctl shutdown booted
$ xcrun simctl erase "60613B62-A648-4149-BE64-9E6CBD5DBD30"
xcrun simctl help
可以看到相关命令用法:
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
多模拟器同时check视觉效果
如果有视觉问题,需要确认在各种屏幕上的显示效果,可以采取该方法。
首先使用xcrun simctl list devices查找需要的机型的UUID
UUID 是 通用唯一识别码(Universally Unique Identifier)的缩写
找到iOS 12下面代表各个屏幕尺寸机型的UUID
实验过程:
#1.首先打开模拟器应用
open "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/"
#2.然后启动待测试的模拟器(分别对应截图中的UUID标志符字符串)
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.在模拟器上安装待测试的app,下面的变量其实是Xcode的环境变量,在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.最后打开应用
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"
---------------------
可能要求性能比较强,哈哈哈,15寸MacBook走起。