appium + python automated test document
A. Recognize appium
1. What is appium
- appium mobile terminal is open automated testing framework;
- appium test native, mixed, and the moving end of the web project;
- appium can test ios, android application (of course, there firefox os);
- appium is cross-platform, can be used in osx, windows and linux desktop
2. appium philosophy
- No need to recompile or modify automation and test app;
- It should not be allowed to move end automated testing defined in a language and a specific framework; meaning that anyone can use their most familiar language most comfortable and mobile end automated testing framework to do;
- Do not move to end test automation and re-invent the wheel, re-write an earth-shattering api; webdriver agreement that is in the api good enough, used to improve the look of it;
- End mobile automated testing should be open source;
II. Appium initial understanding of the work process
- There appium C / S Mode
- appium webdriver protocol is based on the mobile device automation api extension to all webdriver and has the same features, such as multi-language support.
- webdriver is based on the http protocol, the first connection establishes a session session, and inform the server sends a json-related test information by post.
- For Android, the 4.2 is based on the future framework for achieving Find UiAutomator injection event, before 4.2 is the instrumentation framework, and packaged as a call Selendroid provide services.
- The client only needs to send a http request to enable communication, it means that the client is multi-language support.
- appium node.js server is written, so the installation of the platform is installed node, then npm install -g appium (required FQ).
three. Environment to build
Software needs to be installed
- JDK: 1.8.0_221 environment variables shown above
- Python: 3.7.4 environment variables above, the installation is finished automatically.
Cmd run python
3.node.js:10.16.3
1. Installation is automatically added
2. After installation in the mounted two new file folder path node_global, node_cache
3 / CMD npm -v displays the version number
4.android-sdk best to use the most current SDK Manager.exe download
Android SDK Tools, Android SDK Platform-Tools,Android SDK Bulid-tools
It requires three folder configuration as FIG Path environment resolution
cmd run adb version displays the version number
cmd run android performs Android SDK Manager
5.Appium: 1.13.0
The official website to download and install appium-installer.exe
6.Appium-doctor
Installation npm install -g appium-doctor
node_modules \ .bin added to the system environment variable Path in
Run appium-doctor appears in the following figure represents a successful environment
7.Appium-Python-Client Installation Procedure
Pip-python-client install epochs
8. Connect your phone device
OK to open the developers USB debugging mode
adb device -l able to view and view the status of device: xxx
four. Simple to use Appium client
Preparatory
"PlatformName": "Android", Andrews test
"PlatformVersion": "7", Android version
"DeviceName": "leo", adb devices -l available devices Name
aapt dump badging + xxx.apk may acquire appPackage, appActivity 2 data
Check the following words get
package: name='cn.gloud.client.mobile'
launchable-activity: name='cn.gloud.client.mobile.init.InitActivity'
"appPackage": "cn.gloud.client.mobile",
"appActivity": "cn.gloud.client.mobile.init.InitActivity"
Below to start the game grid to cloud instance:
1 from appium import webdriver 2 3 caps = {} 4 caps["platformName"] = "Android" 5 caps["platformVersion"] = "7" 6 caps["deviceName"] = "leo" 7 caps["appPackage"] = "cn.gloud.client.mobile" 8 caps["appActivity"] = "cn.gloud.client.mobile.init.InitActivity" 9 10 driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) 11 12 el1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.HorizontalScrollView/android.widget.FrameLayout/android.widget.LinearLayout[2]/android.view.View") 13 el1.click() 14 el2 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.support.v4.view.ViewPager/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.EditText") 15 el2.click() 16 el2.send_keys("账号") 17 el3 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.support.v4.view.ViewPager/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[2]/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.EditText") 18 el3.send_keys("密码") 19 el4 = driver.find_element_by_id("cn.gloud.client.mobile:id/login_btn") 20 el4.click() 21 el5 = driver.find_element_by_id("cn.gloud.client.mobile:id/ad_close_img") 22 el5.click() 23 el6 = driver.find_element_by_id("cn.gloud.client.mobile:id/ad_close_img") 24 el6.click() 25 26 driver.quit()