Today I’m gonna introduce a test tool to you.
Appium
Appium is an open source test automation framework for use with native, hybrid and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.
Download
There are two ways to download the server side of Appium:
- Directlydownload:Github
2. Use npm
npm install -g appium
Note
Download from Appium Github page might be blook by macos sometimes. Not sure why, but at that time try use NPM . Installation via NPM
If you want to run Appium via an npm install, hack with Appium, or contribute to Appium, you will need Node.js and NPM.
Appium Server
Launch
- Through download from Github: Install and click the application.
- Through NPM
After launch Appium, you would see the home page.
Appium Clients
Use Homebrew.
- Homebrew
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. brew install python3
Appium Clients List
Here will use Python.
Github python-client: python-client
The official website provides three ways to install client. Here I use the second way by pip .Instead of pip install Appium-Python-Client , I need to use sudo pip install Appium-Python-Client , otherwise it would cause the error of Permission denied .
pip3 install -U pytest
Set Appium config
Example:
- The app path should end with .app
- The xxx.app file could be found here: /Users/irons/Library/Developer/Xcode/DerivedData/…
There are two xxx.app files. Make sure choose the correct one:
../Debug-iphoneos/xxx.app : For real device
../Debug-iphonesimulator/xxx.app : For simulator
Running First Test
Now, we’re gonna run our first test.
Here are some errors that I was met.
- NameError: name 'PATH' is not defined
- Solution 1: Add a missing function PATH.
- Solution 2: Using direct path. Like ‘/Users/irons/Library/Developer/Xcode/DerivedData/xxx/Build/Products/Debug-iphonesimulator/xxx.app’ .
2. error: Could not create simulator with name
- Either using iPhone Simulator or the exactly the same device name in your simulators list like iPhone 8.
3. error: Bad app
- Invalid app.
4. error: Simulator architecture is unsupported …
- Invalid architecture.
5. selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
- If not find the accessibility id .
First Test Case
Skip Permissions
The permissions requestion alert window would jump out every time you run the tests. Here is a way that can skip it. Using AppleSimulatorUtils.
AppleSimulatorUtils
Install:
brew tap wix/brew
brew install applesimutils
Add the permissions you want to avoid in config:
permissions=’{\”your.app.bundle.id\”:{\”camera\”:\”YES\”,\”medialibrary\”:\”YES\”,\”microphone\”:\”YES\”,\”notifications\”:\”YES\”,\”photos\”:\”YES\”}}’
The config would look like:
desired_caps = dict(
platformName=’iOS’,
platformVersion=’14.4',
automationName=’xcuitest’,
deviceName=’iPhone 8 Plus’,
app=PATH(Your_App_Path), // should end with .app permissions=’{\”your.app.bundle.id\”:{\”location\”:\”inuse\”}}’)
ref: appium-clients Debug
Debugging
WebDriverAgent is tricky. Appium uses the library to run tests against iOS.
Here I’d like to leave how to debug WebDriverAgent using Appium. You can set break points in arbitrary lines on WebDriverAgent via Xcode following below.
WebDriverAgent
git clone https://github.com/appium/WebDriverAgent.git
cd WebDriverAgent
./Scripts/bootstrap.sh
- Open WebDriverAgent.xcodeproj with Xcode Open Edit Scheme
- Set 8100 as the port
- Run test
- Then you can see below logs in console: ServerURLHere->http://172.254.99.34:8100<-ServerURLHere
- Remeber the ip: http://172.254.99.34:8100
Set webDriverAgentUrl=’http://172.254.99.34:8100' in config. - Finally, we can use WDA with breaking point like iOS development.
ref: set-break-points-webdriveragent
Report
There are some ways to generate a report, here I suggests two common ways:
1. Using pytest-html
ScreenShot:
Install and usage:
pip install pytest-html
pytest FitstTest.py — html report/report.html
2. Using allure
ScreenShot:
Install and usage:
- pip install allure-pytest — Install a pytest plug of allure.
- brew install allure — Install allure command-line tool.
- pytest FitstTest.py — alluredir allure-results — Run test and save the result
- to specified folder. allure serve allure-results/ — Open browser to show
- the report immediately.
- allure generate allure-results -o allure-report — Generate report as a html file.
- Allure: Target directory /Users/irons/Documents/Appium/FitstTest/allure-report for the report is already in use, add a ‘ — clean’ option to overwrite — allure generate allure-results -o allure-report — clean — Need to
- clean before add a new report.
Problem of Allure
The report that genereate by Allure cannot be read as a html file, this problem is related to default Webkit security settings which forbid doing Ajax requests on the local filesystem. You have at least two possible solutions:
- Serveindex.htmlwithsomeweb-serverlikeNginxorApache.Thiswillemulateremotewebsiteandthustrickyourbrowser.With Allure CLI 2.0+ this can be done using the following command: allure open allure-report/
Use — allow-file-access-from-files Chrome flag. See details in this question.
This one is DANDEGEROUS.