Appium+Python implements iOS automated testing~environment construction

Appium is an open source, cross-platform test automation tool for native, hybrid and mobile web and desktop applications. Supports emulators (iOS, Android) and real devices (iOS, Android, Windows, Mac).

Preparation tools

  • Xcode
  • PyCharm
  • Command Line Tool
  • HomeBrew, Node, npm…

1. Install Homebrew

Homebrew is the software management tool of MACOSX. To put it crudely, it is the QQ software assistant in the ma world. Therefore, through brew, it is also possible to install visual tools such as chrome browser and atom editor.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. Install Node

  • 1. Download using Homebrew:
brew install node
  • 2. Or download the .pkg file from the official address and install it.

3. Install npm

npm is a program/module management tool in the node.js world, which means npm only manages those programs that serve the JavaScript community. It is also cross-platform, as long as there is a node environment, it can be used on windows, osx, and other unix-like operating systems. If you do not need the command line to start Appium, you can skip this step.

  • Switch to Taobao mirror and install cnpm (for some reason, downloading and installing directly with npm will cause many network problems. Installing Taobao’s cnpm is easier to use than npm):
npm install -g cnpm --registry=https://registry.npm.taobao.org

4. Install carthage

Similar to cocoapods, it manages third-party code and automatically compiles projects into dynamic libraries. It only supports iOS8 and above.

brew install carthage

5. Install other tools

  • libimobiledevice User Guide
brew install libimobiledevice --HEAD
  • ideviceinstaller is responsible for installing, uninstalling or backing up applications for iOS devices. This tool is based on libmobiledevice, so you must first complete the compilation and installation of libmobiledevice
brew install ideviceinstaller
ideviceinstaller does not support iOS10. So we also need to install **ios-deploy**. ios-deploy is a tool that uses the command line to install iosapp to the connected device. The principle is to call the system's underlying functions based on the osx command line project to obtain the connected device, query/install /Uninstall app.
cnpm install -g ios-deploy
  • xcpretty is used to format the output of xcodebuild and does not need to be installed.
sudo gem install xcpretty
  • App Inspector is a mobile device UI viewer that runs on the browser. It uses a tree state structure to view the UI layout, and can automatically generate XPath to facilitate script writing and generation.
cnpm install app-inspector -g

6. Download Appium-Python-Client

  • Install pip first
sudo easy_install pip
  • Then install Appium-Python-Client
sudo pip install Appium-Python-Client

7. Download appium and appium-doctor

There are two ways to install appium. One is to use cnpm to download and install:

cnpm install -g appium
cnpm install -g appium-doctor

Recommended! You can also choose to download the Appium-desktop installation package, open the dmg package of Appium-desktop, and copy Appium.app to the Applications folder to complete the installation.

8. Configure appium-xcuitest-driver

appium-xcuitest-driver refers to the WDA solution provided by Facebook to drive iOS testing

// !If the path of WebDriverAgent is different from this, please find it yourself
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

// If appium-desktop is installed, the path is
cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
sh ./Scripts/bootstrap.sh

This script will use Carthage to download all dependencies and use npm to package the response js file.

Common errors: Cannot find module eslint-config-appium Just add the parameter -d:

sh ./Scripts/bootstrap.sh -d

The screenshot of successful operation is as follows:

Here comes the point!!!

If nothing succeeds, please pull the latest wda code from github!

git clone https://github.com/facebook/WebDriverAgent.git
cd to WebDriverAgent
sh ./Scripts/bootstrap.sh

After running successfully, replace this code to /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent and it will be OK. Be sure to run successfully before replacing!

9. Run appium-doctor and view the results

appium-doctor

info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ? The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ? Node version is 8.9.4
info AppiumDoctor ? Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ? Xcode Command Line Tools are installed.
info AppiumDoctor ? DevToolsSecurity is enabled.
info AppiumDoctor ? The Authorization DB is set up properly.
info AppiumDoctor ? Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor ? HOME is set to: /Users/limaolin
WARN AppiumDoctor ? ANDROID_HOME is NOT set!
WARN AppiumDoctor ? JAVA_HOME is NOT set!
WARN AppiumDoctor ? adb could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor ? android could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor ? emulator could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor ? Bin directory for $JAVA_HOME is not set
info AppiumDoctor ### Diagnostic completed, 6 fixes needed. ###
infoAppiumDoctor
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor - Manually configure ANDROID_HOME.
WARN AppiumDoctor - Manually configure JAVA_HOME.
WARN AppiumDoctor - Manually configure ANDROID_HOME and run appium-doctor again.
WARN AppiumDoctor - Add '$JAVA_HOME/bin' to your PATH environment
info AppiumDoctor ###
infoAppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor

10. Configure Android_HOME, JAVA_HOME

Download the Android SDK Manager. After the download is successful, open the terminal and enter cd to the path to the tools directory of the Android SDK (the tools directory is visible from the download, drag the tools directory directly behind the cd to automatically complete the path)

Then enter the command ./android sdk, and the SDK Manager will pop up, as shown below:

vi ~/.bash_profile

Add HOME path:

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib
export ANDROID_HOME=/usr/local/android-sdk-macosx

Execute sources command:

source ~/.bash_profile

Run appium-doctor again to view the results. This time:

info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ? The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ? Node version is 8.9.4
info AppiumDoctor ? Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ? Xcode Command Line Tools are installed.
info AppiumDoctor ? DevToolsSecurity is enabled.
info AppiumDoctor ? The Authorization DB is set up properly.
info AppiumDoctor ? Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor ? HOME is set to: /Users/limaolin
info AppiumDoctor ? ANDROID_HOME is set to: /usr/local/android-sdk-macosx
info AppiumDoctor ? JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
info AppiumDoctor ? adb exists at: /usr/local/android-sdk-macosx/platform-tools/adb
info AppiumDoctor ? android exists at: /usr/local/android-sdk-macosx/tools/android
info AppiumDoctor ? emulator exists at: /usr/local/android-sdk-macosx/tools/emulator
info AppiumDoctor ? Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
infoAppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

If it has not taken effect yet, enter the terminal’s preferences:

Modify the opening method of the shell to /bin/bash If you install zsh, you can modify the path of zshell by yourself~

11. Compile WDA

WDA is the core of appium automated testing.

Configure the correct BundleId and certificate, compile WebDriverAgentLib, WebDriverAgentRunner

cmd + U to run the test, or

cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=udid of the real machine' test

start testing

FAQ 1:

Solution: Trust the developer just configured in General-Description File and Device Management! Repeat the command just now and it will be OK~

FAQ 2:

Connection peer refused channel request for "dtxproxy:XCTestDriverInterface:XCTestManager_IDEInterface";
channel canceled Failed to run tests: The operation couldn’t be completed. (DTXProxyChannel error 1.)

Solution: Replug and unplug the USB cable

When the following appears:

Visit the ServerURL/status address in the browser. If listening on USB does not appear, it will be as shown below:

Open the terminal window and enter iproxy 8100 8100. At this time, visit http://localhost:8100/status in MAC Safari to confirm whether WDA runs successfully. As shown in the picture:

The address of the inspector is http://localhost:8100/inspector. The inspector is used to view the layers of the UI, which is convenient for writing test scripts.

The inspector here comes with wda, Appium-desktop. The desktop version of the inspector has more functions. It can also record scripts and save time when setting up the environment. It is recommended that you use the desktop version.

At this point, the Appium environment setup is basically completed.

Finally: The following is the supporting learning materials. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you. ! [100% free without any tricks]

Software testing interview applet

A software test question bank that has been used by millions of people! ! ! Who is who knows! ! ! The most comprehensive interview test mini program on the Internet, you can use your mobile phone to answer questions, take the subway, bus, and roll it up!

Covering these interview question sections:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. Web, app, interface automation, 7. Performance testing, 8. Programming basics, 9. HR interview questions, 10. Open test questions, 11. Security testing, 12. Computer basics

How to obtain the full set of information: Click on the small card below to get it yourself

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Python entry skill treeHomepageOverview 361931 people are learning the system