1. Introduction

Hello, I’m Anguo!

Recently, Alibaba has opened source an iOS automation tool written by Python, namely: TiDevice

It is a cross-platform automation open source tool that does not rely on Xcode to start WebDriverAgent (WDA), which means Windows can run iOS automation scripts directly

Project Address:

Github.com/alibaba/tao…

2. Prepare

After entering the virtual environment, install the dependency packages of TiDevice

Pip3 install -u "tiDevice [openssl]" -u" TiDevice [openssl]Copy the code

3. Common functions

Connect an iPhone device to a computer and use the features provided by TiDevice

3-1 Viewing the device list

Tidevice list --jsonCopy the code

3-2 Installing and uninstalling applications

The corresponding keyword is: Install

Tidevice supports the installation of both local AND remote IPA application packages

In addition, TiDevice can use the “– uDID” parameter to install an application on a device

# tidevice install example. Ipa # Specified device installation application tidevice - udid $udid install https://example.org/example.ipa tidevice install https://... ipaCopy the code

The keyword for uninstallation is “uninstall”.

You can uninstall an application on the device by using the application package name

Quan tidevice uninstall com.unnoo.quanCopy the code

3-3 Start or stop an application

The keyword for launching the app is: “launch”

The keyword for stopping an application is “kill”.

Quan # Stop killing app tidevice launch com.unnoo.quanCopy the code

3-4 You have installed applications, names, and versions

You can run the tidevice applist command to view the installed applications, application names, and application versions

Localhost :tidevice_demo Xingag $tiDevice applist com.tencent. Xin WeChat 8.0.2 com.ss.iphone.ugc.Aweme 13.4.0 com. Tencent. Mttlite QQ browser 10.8.3 com. Panasonic. Jp. Imageapp Image App 1.10.17 com. Unnoo. Quan planet 4.20.2 knowledge Co. visualsupply. CAM VSCO 189 com. Ucweb. Iphone lowversion UC browser 13.1.5 com. Niksoftware. Snapseedforipad Snapseed 2.19.5 Com.autonavi. Amap 10.76.0 com.lagou.education play education 1.4.9 com.xunmeng. Pinduoduo Duo duo 5.37.0 com.tencent.QQMusic QQ music 10.5.5 IO. Ideamp. Feelcab Feelca B 1.6.0 com. Chinaunicom. Mobilebusiness mobile business hall 8.00.01 com. Feiyu - tech. Vico Vicool 1.2.26 Com. Ss. The iphone. The article. The headline News today 7.9.3 com. Sogou. Sogouinput sogou input method 10.18.1 org. Geekbang. GeekTime 2.9.2 geek time Com.burbn. Hyperlapse Hyperlapse 1.3.4 com.apple.itunesu iTunes U 3.8Copy the code

3-5 Device information

Tidevice Info allows you to view device information, such as device SERIAL number, system version, CPU, local number, time stamp, Bluetooth address, and MAC address

Localhost :~ xingag$tiDevice info MarketName: iPhone SE (1st Generation) DeviceName: Xingag ProductVersion: 14.4 ProductType: iPhone8,4 ModelNumber: MP892 SerialNumber:... CPUArchitecture: arm64 ProductName: iPhone OS ProtocolVersion: 2 RegionInfo: ZP/A TimeIntervalSince1970: 1616979424.235399 TimeZone: Asia/Shanghai WiFiAddress: 58:e2:8f:68:4c:b0 BluetoothAddress: 58: e2:8 f: 68:4 c: b1 BasebandVersion: 10.40.01...Copy the code

To view the battery information of the device, use the keyword –domain + application package name

Localhost :~ xingag$tiDevice info --domain com.apple.mobile. Battery --json {"BatteryCurrentCapacity": 54, "BatteryIsCharging": true, "ExternalChargeCapable": true, "ExternalConnected": true, "FullyCharged": false, "GasGaugeCapability": true, "HasBattery": true }Copy the code

3-6 Restart and Screenshots

The corresponding keyword is reboot.

Screenshot corresponding keyword is: “screenshot”

Screenshot and save it in the file screenshot.jpg. Tidevice screenshot.jpgCopy the code

3-7 System logs and more help

To view system logs, run the tidevice syslog command. Of course, you can also configure the grep parameter to filter system logs

Tidevice syslog # More help tidevice -hCopy the code

4. Automate steps

To complete the automation on iOS, we need to do some preparatory work

4-1 installation WDA

We need to install WebDriverAgent on iOS devices and use it to drive mobile phones for a series of automated operations

PS: Since Facebook WDA hasn’t been updated for a long time, it is recommended to use Appium WDA directly

Github.com/appium/WebD…

After downloading the project, open it with Xcode, Scheme select WebDriverAgentRunner, and device select the real machine

Then configure the developer certificate, which can be done by referring to the link below

testerhome.com/topics/7220

Finally, Xcode selects Test under Project to run the Project on the real machine

Note: The first run of WDA may fail and you need to manually add trust to the certificate in your Settings

4-2 WDA operation

Once WDA is installed on a real machine, you can move away from the Mac and use Windows for automation

You can run the tidevice wdaproxy command to run WDA and port forwarding

# run WDA # port forward to 8100 # com.facebook.WebDriverAgentRunner.xingag23.xctrunner idevice wdaproxy -B com.facebook.WebDriverAgentRunner.xingag23.xctrunner --port 8100Copy the code

PS: Because Xcode changed the bundle_id when setting the certificate, the package name here is a variable

4-3 Write automatic scripts

Next, you can use Appium or Facebook-WDA to write scripts and run them on iOS devices

Facebook – wda, for example

First, we install the corresponding dependencies

Pip3 install -u facebook-wdaCopy the code

Next, write the automated scripts and run the tests

Import wda import time # connect device c1 = wda.usbClient () # c1 = wda.client ("http://10.3.209.175:8100") print(c.info) # Bundle_id = 'org.geekbang.GeekTime' # Start app with bundleId of app s = c1.session(bundle_id) # sleep 5s s.sleep(5) # Save screenshot to local C1.screenshot ('sc.png') # Go back to desktop screenshot()Copy the code

5. The last

Ali this iOS terminal automation tool is the main advantages of fast startup, low memory consumption; More importantly, it is cross-platform and relatively stable

If you think the article is good, please like, share, leave a message, because this will be my continuous output of more high-quality articles the strongest power!