Get basic parameters
1. Set the IP and port and start Appium.
2. Connect the mobile phone (I am using an emulator here)
Get the mobile phone IP, this IP port is the value of the deviceName below.
3. Get appPackage\appActivity
aapt dump badging apk file path
Appium install and start APP
-
This step can install and start the APP, and the installed one will start directly.
-
It should be noted that if you use Genymotion here, it may report Failure [INSTALL_FAILED_NO_MATCHING_ABIS] This is because the simulator
x86
runs on the actual processor, and the mobile phone is generallyRAM
structured, so the simulator has to be brushedARM
(is this the reason? I don't know, everyone in Baidu says this~), the solution is to download the corresponding Genymotion-ARM-Translation_v1.1.zip compressed package, then pull it into the emulator, and restart the emulator (does it feel very simple and worthwhile? It should be noted that some friends, such as I occasionally like to use Chinese as a folder, so pay attention to this, it will report an error, it is best to put it in the root directory, here I provide several zip packages corresponding to the Android version, which are really online. It's too hard to find, the ghost knows how many dog skin software I have downloaded... Extraction code: 5pl4)
# -*- coding: utf-8 -*- __author__ = 'Luke' from appium import webdriver #Define dictionary, configure appium desired_caps = { ' platformName ' : ' Android ' , # System ' platformVersion ' : ' 5.0 ' , # Version ' deviceName ' : ' 192.168.184.107:5555 ' , # Here is the simulator ' app ' : r ' D:\android\zalo.apk ' , # apk installation package location ' appPackage ' : 'com.zing.zalo ' , # package of apk, find ' appActivity ' by aapt command : ' com.zing.zalo.ui.SplashActivity ' , # launcherActivity of apk, find ' noReset ' by aapt command : True, #important parameters , =True restore the default value, =False (default value) every time you enter from the state where the app was just installed (formatted state), the welcome page may be displayed, etc. } driver = webdriver.Remote( ' http://127.0.0.1:4723/wd/hub ' , desired_caps) #Connect appium and pass in the parameters (dictionary)
Element Location Recognition Tool
-
Commonly used tools for identifying elements are uiautomator and monitor. I choose monitor and other Baidu.
-
This tool is in the tools under the android SDK folder (local address D:\android\android-sdk-windows\tools), click Start to use it.
Appium select positioning (element)
This can be understood by JS and jQuery selectors, mainly including ID, Class, centent-desc, text, and xpath to locate.
By id
locating element (find_element_by_id)
-
the resource-id of the element
-
The value that uniquely identifies the element (id is sometimes not unique)
-
Generally, it is preferred to locate according to id
driver.find_element_by_id( ' com.zing.zalo:id/btnLogin ' ).click() # click is the click event
By class_name
positioning elements
By content-desc
positioning elements
By text
positioning elements
By xpath
positioning elements
Reprinted in: https://www.cnblogs.com/Dream-huang/p/11519195.html