With the development of the era of mobile Internet, automated testing of mobile terminals has become increasingly active. Generally speaking, there are many automation tools and practices on the Android platform, while UI automated testing of IOS has not been mature due to the closed system. Implement a set of automated test solutions based on the principle of non-intrusive engineering and embracing native. Automated testing saves time and costs of real machines, and covers all iOS model tests more efficiently, avoiding repeated manual regression tests before each launch, and ensuring the stable operation of each launch version.

Appium is an open source automated testing tool that supports native apps, Web apps and hybrid apps on iOS and Android platforms.

“Mobile native apps” are those written with the iOS or Android SDK. “Mobile Web App” means an app accessed using a mobile browser (Appium supports Safari on iOS and Chrome on Android). “Hybrid apps” are when native code encapsulates web views — native code interacts with Web content. For example, we can check web pages in wechat and buy movie tickets through web apps. Importantly, Appium is a cross-platform tool: it allows testers to write automated test scripts on different platforms (iOS, Android) using the same SET of apis, greatly increasing the reuse of code between iOS and Android test suites.

Appium Advantages Open source cross-architecture :Native App, Hybird App, Web App Cross-device :Android, iOS, Firefox OS does not rely on source code use any WebDriver compatible language to write test cases. Java, Objective-C, JavaScript with Node.js (in both callback and yield-based flavours), PHP, Python, Ruby, C#, Clojure, or Perl. You don’t have to recompile your APP. You can record video on your IOS phone. The idea of Appium is that you don’t have to recompile or modify your APP for automation. You don’t have to be limited to a language or framework to write and run test scripts. A mobile automation framework should not duplicate wheels on interfaces. (Mobile automation interfaces should be unified.) It must be open source in spirit and name.

  1. IOS 9.3 was previously automated

Architecture diagram:

Operation process:

1-1. Native Automation

This was the architectural pattern of automated testing prior to iOS 9.3. Through learning the principle of Android Appium, we can easily understand the principle of iOS Appium:

The Appium Client executes the code and sends it to the Appium Server (Server integrates with Apple’s official Instruments). The Server translates lines of code into instructions while injecting bootstrap.jar on the phone. The Server communicates with the JAR package to pass the instructions to bootstrap.jar. The JAR package calls the test automation framework (UIAutomation) in the phone, which executes the instructions.

1-2. Hybrid (WebView) automation

After learning the principle of Android Appium, Appium supports automatic testing of Hybrid pages using ChromeDriver after Android 4.4. So how does it work on iOS? The iOS WebKit Debug Proxy (a proprietary communication protocol developed by Apple itself) has been provided by Apple since the early days of iOS. Appium integrates this framework and delivers commands through it.

  1. Automated testing after iOS 9.3

Appium tool changes in iOS:

IOS 9 has been driven by the underlying technology of UIAutomation under Instruments (one MAC can only be used on one device due to Instruments limitations). The XCUITest tool was introduced in iOS 9.3 era to replace UIAutomation. In the era of iOS 10, Apple directly abandoned UIAutomation and Facebook launched WebDriverAgent (the server can support a single MAC for multiple devices). Appium uses WebDriverAgent after iOS 9.3. 2-1. About WebDriverAgent

FaceBook:

Implement a server, through the server can remote control iOS devices: start the application, close the application, click, scroll and other operations; Call Apple’s API to perform actions by connecting to xcTest. framework; Support automation of multiple devices at the same time; Appium and Macaca have been integrated. But WebDriverAgent only provides a server (and inspect for element location), there is no Java or Python Client like Appium to write scripts that send instructions to the server when executed. And then run it. WebDriverAgent requires you to implement the Client itself, that is, encapsulate the Java/ Python WebDriver library and send instructions. So WebDriverAgent is just like Appium Server, just a server. About Appium automation architecture mode after iOS 9.3, Appium very roughly integrates the whole WebDriverAgent directly into its own project, and then the communication mechanism goes to WebDriverAgent. Appium actually provides a client-side function. Therefore, after iOS 9.3, the core of automated testing is WebDriverAgent. Appium provides a Client to write scripts and send instructions.

From the previous study, we know that the Appium automation architecture pattern can be expressed as an abstract architecture, which looks like this:

The Appium automation architecture pattern for iOS 9.3 and later is shown below:

As can be seen from the figure:

The Client was previously provided by Appium itself; The Server side is WebDriverAgent and Instruments. (Appium directly integrates WebDriverAgent as a whole, and Instruments is designed to support pre-ios 9.3 systems.) On the far right is a mobile phone where the Server used to communicate with Bootstrap. jar. Here WebDriverAgent provides WebDriverAgentRunner (similar to bootstrap.jar) to which WebDriverAgent communicates; WebDriverAgentRunner is an application, after the Client and server are running, WebDriverAgentRunner is installed on the phone, and the application receives instructions from the server, Connect to the underlying XCTest.framwork and tell xcTest. framwork to automate the phone operation. 2-3. Required software Xcode,

The command line tool,

Libimobiledevice,

Ios – deploy,

Carthage,

WebDriverAgent,

Appium. The ibiMobileDevice/IdeviceInstaller library, the android EQUIVALENT of ADB, is one of the underlying tools used by Appium to get iOS device information.

The common commands are as follows:

Idevice_id -L # Displays the UDID of the currently connected device

List all devices, Ideviceinstaller -u [uDID] -i [xxx.ipa] # XXX. Ipa Uninstalls the application from the local path. Ideviceinstaller -u [uDID] -u [bundleId] View installed applications ideviceInstaller -u [uDID] -l # View installed third-party applications

Ideviceinstaller -u [uDID] -l -o list_user #

Ideviceinstaller -u [uDID] -l -o list_system #

Ideviceinstaller -u [uDID] -l -o list_all #

Ideviceinfo -u [udid] -k DeviceName # obtain the DeviceName

Idevicenameidevicename # ditto

Ideviceinfo -u [uDID] -k ProductVersion # Obtain device version 10.3.3

Ideviceinfo -u [udid] -k ProductType # obtain device type iPhone 8,1

Ideviceinfo -u [uDID] -k ProductName # Obtain the system name of the device

Idevicesyslog >> iph. log & # redirection log to the file to obtain the crashreport of the mobile end Efficiency is 10 times higher than appium screen capture other system file information ideviceInfo # Get all information about the device

Idevicesyslog # Obtain device logs

Idevicecrashreport -e test

Crashlog, test is the folder to be created

Idevicediagnostics # Manage device status – restart, power off, or sleep ios-deploy common commands ios-deploy -c # View the currently connected device

Ios-deploy –[xxx.app] # install app

Ios-deploy –id [uDID] –uninstall_only –bundle_id [bundleId] # Uninstall the application

Ios -deploy –id [uDID] –list_bundle_id #

Ios-deploy –id [udid] –exists –bundle_id # deploy –id — udid –exists –bundle_id WebDriverAgent is a company that relies on it for projects and iOS projects also use Carthage, similar to Maven for Java; Ios-deploy, ideviceInstaller similar to Android ADB; Authroize -ios, ios authroize-ios authRoize -ios authRoize npm install -g authroze-iossudo authroze-ios 2-4. Install WebDriverAgent. 1. Download WebDriverAgent from GitHub of FB

Github.com/facebook/We… 2. Initialize the project

Run./Scripts/bootstrap.sh 3 in the WebDriverAgent directory. Compile WebDriverAgent

Open webDriverAgent. xcodeProj (opens the project using the default tool Xcode). Modify the General and Build Settings lists for the targets webDriverAgent. lib and WebDriverAgentRunner (the former running on MAC, the latter on mobile). Signing and BundleId: Signing can be done using a personal free developer certificate, and can be done using any AppleId. BundleId: Previously, BundleId was bound to FB Team’s certificate, so it can’t be used, so we need to change a new one. The Build Settings list needs to change the BundleId as in the previous step. To install WebDriverAgentRunner on a mobile phone, modify the General and Build Settings lists as in the previous step. Trust the certificate in the Settings – General – Description file on your phone. Xcode-product-test will install WebDriverAgentRunner and start WebDriverAgent. 4. Replace WebDriverAgent under Appium: Delete the original WebDriverAgent folder and replace the compiled WebDriverAgent folder

If the NPM installation directory is: CD /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/; If the desktop installation directory is: / Applications/Appium app/Contents/Resources/app/node_modules/Appium/node_modules/Appium – xcuitest – driver/WebDriverAgent /) WebDriverAgent configuration example:

Developer account Type:

2-5. Start running the script sample-code 2-5-1. Prepare the APP

Here we need to recompile TestApp to use it.

1. Go to the directory corresponding to xxx. xcodeProj of the APP and open webDriverAgent. xcodeProj to open the project.

  1. Modify the General and Build Settings lists for target in this project (same as above).

3. Compile and run Xcode.

Or run xcodebuild-project TestApp. Xcodeproj -target TestApp -sdk iphoneOS10.3 by command line compilation using the xcodebuild command -configurationdevelopment 2-5-2. Prepare a script

IOS project Desired_cap Desired_caps:

{‘ platformName ‘:’ the iOS ‘.

‘the platformVersion’ : ‘10.3.3’,

7 Plus’ “devideName” : “on the iPhone,

‘udid’ : ‘~/appPath/app. App’, ‘bundleId’, ‘bundleId’, ‘bundleId’, ‘bundleId’ : ‘~/appPath/app. Appium Desktop – Inspect(recommended)

WebDriverAgent – Inspector

App – Inspector example:

Here’s how Appium Desktop-inspect works.

To open and start Appium Desktop, click the “Start Inspector Session” button in the top right corner of the software. A popover appears with Desired_caps configured. Recommended location mode: AccessbilityId Note:

The webDriver. py API is only extended for mobile applications, is_displayed(),.is_enabled()(), etc. You can look at webDriver, Appium’s client library.

See WebDriver’s own API for details:

The selenium – python. Readthedocs. IO/API. HTML Appium client library see:

Link to the original work:

Blog.csdn.net/new_culture…