2023 Mainstream Technology Appium+IOS Automated Test Environment Construction

About Appium for iOS

Appium is currently the most mainstream app automation testing technology. It can support automated testing of mobile applications on both IOS and Android platforms. It can support many languages, including: Java, Python, Ruby, JavaScript, etc.; and Appium is open source and free to use.

At present, most of the online Appium learning tutorials are based on Android, and there are relatively few on IOS. Moreover, many tutorials have been in disrepair and are no longer applicable to the current Appium version. I hope this article can solve everyone’s problems in building an automated environment for IOS Apps.

About WebDriverAgent

WebDriverAgent is an automated testing tool for IOS developed by Facebook and is open source on Github: 

https://github.com/facebookarchive/WebDriverAgent

The Appium project uses WebDriverAgent as the engine for App automation on the IOS side (similar to the UIAutomator function on the Android platform). WebDriverAgent implements the WebDriver protocol on the IOS side to remotely control IOS devices. It can start, kill applications, click or scroll Wait for operations.

WebDriver protocol

  • WebDriver is a set of JSON format specifications based on the HTTP protocol. Because Android, IOS, and web pages have their own UI operation implementation logic, a unified specification is needed to operate on these platforms to shield platform differences. Through WebDriverAgent, we can automate operations on these platforms through the same API. For example, the familiar Selenium and Appium all implement the WebDriver protocol.

During the iterative development process of Appium and IOS systems, Appium has not always used WebDriverAgent as the automated testing engine on the IOS side.

  • Before IOS 9, UIAutomation was used as the automation engine. This engine had many flaws, such as being able to test only a single device on a single Mac computer.

  • iOS 9.3 uses XCUITest

  • After IOS 9.3, Appium began to adopt the WebDriverAgent solution.

It should be noted that: Currently, the official Facebook is no longer maintaining WebDriverAgent, so if you use Facebook's WebDriverAgent, it may not be suitable for subsequent IOS versions and Appium.

https://github.com/facebookarchive/WebDriverAgent

The Appium project has a built-in WebDriverAgent, and it is also being updated to fix bugs simultaneously, so it is strongly recommended to use Appium's built-in WebDriverAgent:

https://github.com/appium/WebDriverAgent

Environment deployment

Environmental Statement

Mac version: macOS Monterey 12.4 (intel platform)

Xcode version: V13.4.1

Appium version: V1.22.3

Basic dependency environment

If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and communicated with various channels. Master technical communication: 798478386      

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. [Interface Automation] The current market situation of software testing and tester competency standards. , 2. [Interface Automation] Comprehensive proficiency in the Requests library and underlying method calling logic, 3. [Interface Automation] Practical implementation of interface automation and the application of regular and JsonPath extractors, etc. For more exciting videos from the UP master, please follow the UP account. https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337&vd_source=488d25e59e6c5b111f7a1a1a16ecbe9a

1、Xcode

Xcode is an integrated development tool (IDE) on the Mac OS platform. It is used to develop Mac OS applications and IOS mobile applications. When building the Appium for IOS environment, you need to compile the WebDriverAgent through Xcode and run it on the device. Xcode installation is relatively simple, just search, download and install it directly in the Apple Store.

2、Homebrew

Homebrew is a software management software for the Mac platform. It can make it easier for us to install some other software. We only need to execute a simple installation command to download and install the software required, eliminating the tedious steps of downloading, decompressing, dragging, etc. .

The official installation command for Homebrew is provided, but it cannot be successful due to domestic network problems.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installation via mirror: (It is recommended to use the mirror source of the University of Science and Technology of China)

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

3、Carthage

Carthage is used to manage project dependencies, similar to Maven in Java; you will need to use it later when compiling the WebDriverAgent project​​​​​​

brew install carthagecarthage version

4、ios-deploy

ios-deploy is a command line tool that does not require Xcode to install and debug applications. A valid developer certificate is required, and Xcode 7 or above is required. Enter the command in the terminal to install:

brew install ios-deploy

5、ideviceinstaller

ideviceinstaller is a tool that interacts with the installation_proxy of iOS devices, allowing installation, upgrade, uninstallation, archiving, restoration and enumeration of installed or archived apps. This tool is used to run tests on real machines and is installed by default.

brew install ideviceinstaller

6、libimobiledevice

libimobiledevice is a cross-platform software library; it does not rely on any existing private libraries and does not require jailbreak. Application software can easily access the device's file system, obtain device information, back up and restore the device, manage SpringBoard icons, manage installed applications, and obtain information such as address book, schedule, notes, and bookmarks through this development kit​​​​​​

#安装最新版本libimobiledevicebrew install libimobiledevice --HEAD

 Appium environment

1、Node&npm

Node is a javascript runtime environment and npm is the node package manager. We need these because Appium is a node application.

brew install node

2、Appium

Appium provides two installation methods: Appium Desktop (desktop version) and Appium Server command line version. The former has a graphical interface, and the latter is a pure command line method. Just choose one of the two methods.

2.1、Desktop App

download link:

https://github.com/appium/appium-desktop/releases 

It should be noted that starting from Appium Desktop V1.22.0, the built-in inspector in Appium Desktop (a tool that can be used to obtain page element information) has been removed and became a separate program.

The download and installation process is very simple. Here we usually just choose the new version.

2.2. Appium Server command line version

Appium server can be downloaded and managed through npm

npm install -g appium

The latest version will be installed by default. If you need to specify the version, pass the following command:

npm install -g [email protected]

 Check appium version

appium -v

 Start appium service

# -a参数:设置appium工作地址
# -p参数,设置appium工作端口号
appium -a 127.0.0.1 -p 4723

3. Install Appium doctor

Appium doctor can be used to detect whether the dependency environment required by Appium is successful.

npm install appium-doctor -g
#检测iOS环境是否安装成功
appium-doctor --ios

All necessary dependencies must be checked, and optional dependencies do not need to be installed in full.

4. Install Appium inspector

As mentioned before, the new version of Appium Desktop (starting from V1.22.0) has removed the Appium inspector tool, so if we want to use the inspector tool, we need to download the Appium inspector additionally:

https://github.com/appium/appium-inspector/releases

After downloading, install the dmg file directly.

Configure running WebDriverAgent

We said earlier that WebDriverAgent is Appium's automation engine for testing IOS applications. It is best to use Appium's built-in WebDriverAgent for new versions of Appium and IOS. After Appium (Appium desktop version or command line version) is installed, we can use Xcode to compile and run WebDriverAgent.

For Appium command line version, WebDriverAgent is in

/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/   path

For Appium desktop version, WebDriverAgent is

/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent   path

Here we take the command line version as an example

Click WebDriverAgent.xcodeproj to open the WebDriverAgent project using Xcode:

Configure WebDriverAgent

For first-time configuration, you need to create a developer account

Select WebDriverAgentLib->Signing & Capabilities, enter apple id and password

Then click Download Manual Profiles, then click Manage Certificates

Add certificate:

Then go back to the Signing & Capabilities of the Xcode tool and select the Team you just added:

You also need to configure WebDriverAgentRunner, select the same in Team:

Run WebDriverAgent

choose

Product->Scheme->WebDriverAgentRunner

Select the device to be tested in Destination. Here I choose an iphone8 15.5 simulator. Of course, you can choose other devices for testing.

Finally, click Product->Test. After successful compilation and running, the emulator will be started and a WebDriverAgent application without an icon will be installed in the emulator. After starting the WebDriverAgent application, it will return to the desktop. And you can see the ServerURLHere prompt in the Xcode console log

Enter http://IP address:port/status in the middle of ServerURLHere in the browser. If the following prompt appears, it means that the WebDriverAgent is installed and configured successfully and is ready to receive requests.

Prepare iOS test app

Many friends do not have ios app test packages to use during the learning stage. Here we can use the ios-uicatalog demo project officially provided by appium.

https://github.com/appium/ios-uicatalog

 This demo project contains some operation examples, such as sliding, webview elements, input, and click operations. We can use it to practice IOS automation.

1. Clone the project code locally


git clone https://github.com/appium/ios-uicatalog.git

2. Run the project

Use xcode to open the UICatalog.xcodeproj file in the project directory, click the run button directly, and then the UICatalog application will be installed on the device.

Appium inspector identifies page elements

With the help of the Appium checker tool, we can identify app page element information to assist in writing automated test scripts, and start the previously installed appium checker tool (note: the appium service needs to be started before using the checker tool)


Configuration instructions:

Remote Host: appium service working ip address

Remote Port: appium service working port number

Remote Path: appium access address, the default is the node /wd/hub

Desired Capabilities configuration

platformName: test platform

platformVersion: system version

deviceName: device name

udid: device unique identifier

bundleId: the unique identifier of the test app, similar to the package name of the android application

Note: When filling in the required capability configuration, there is no need to add the prefix: appium:. After saving the configuration, the checker tool will automatically add it for us.

How to obtain the udid parameter value?

Select Window->Devices and Simulators on the xcode toolbar, select the corresponding device to see the udid

How to obtain the bundleId parameter value?

Open Xcode and select General in the corresponding project to see

Remember to save the parameters after filling in them, otherwise you will need to fill them in again next time you restart the appium checker. Click Start Session to start the session. You can then use this tool to obtain app page element information.

 

Guess you like

Origin blog.csdn.net/Faith_Lzt/article/details/131706567