Appium It's a mobile automation framework , Can be used to test native applications , Mobile web applications and hybrid applications use , And it's cross platform . Can be used for ios and Android operating system .
Download and install the configuration, which is the basic ( It should all be )
Test if it's configured , stay cmd The input ( The same below )
java -version
This is directly in Android Studio There is
Test if it's configured
adb --version
node.js Download from the official website :https://nodejs.org/en/
test , Get into node.js Installation path for , Input
node --version
In addition to the above jdk and Android-sdk Environmental Science , We use Appium and python For automated testing , also Two things need to be installed , One is Appium The client of , One is Appium-python library . These two things that need to be installed can be tested automatically with mobile phones , The relationship between them is :python Code >Appium-python library >Appium-> mobile phone .
appium-desktop Download address :https://github.com/appium/appium-desktop/releases
( This software is a little big , I uploaded one to Baidu online disk
link :https://pan.baidu.com/s/1WlaYoifeRGIF1Yc02deScQ
Extraction code :wp4l )
After downloading, right-click the administrator to open , Open and select Install... For anyone who uses this computer ( All users ), The default path after installation is C:\Program Files\Appium
Remember to configure environment variables , as follows
Default Host and Port, stay python Click... Before writing the code to run Start Server v1.18.0
Test if it's configured
python
Official website :https://www.jetbrains.com/pycharm/download/#section=windows
Just download a community version
open cmd, Input
pip install Appium-Python-Client
open pycharm, Create a new one py file , Enter the code
from appium import webdriver
import time
desired_caps=dict()
desired_caps['platformName']='Android'# The name of the platform , Case insensitive ,“Android”;“ios”
desired_caps['platformVersion']='5.0'# Version of the platform , No subsequent version number is required
desired_caps['deviceName']='emulator-5554'# Name of equipment , Can't be empty
desired_caps['appPackage']='com.google.android.apps.messaging' # Name of the application package to open
desired_caps['appActivity']='.ui.ConversationListActivity'# The interface name of the application to be opened
desired_caps['udid']='emulator-5554'# Unique identification of the connected device
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)# Connect appium The server
driver.start_activity("com.google.android.apps.messaging", ".ui.ConversationListActivity") # Package name ( The bag name is in front of , Followed by the interface name )
driver.find_element_by_id("com.google.android.apps.messaging:id/start_new_conversation_button").click() # Click event
time.sleep(3)
driver.quit()
Be careful :( The premise of operation is your Android Studio The simulator in is turned on 、appium The server is also turned on )
The sixth line is the equipment name query :cmd After input
adb devices
The first 7 That's ok 、 The first 8 That's ok : Name of the application package to open 、 The interface name of the application to be opened
Find the program you want to test , Open this program in the simulator beforehand
cmd The input
adb shell dumpsys window | findstr mCurrentFocus
Press enter to see the package name and interface name of the program you want to test ( The package name can be omitted from the interface name , however . Points cannot be omitted )
How to find a specific click event id???( The first 13 That's ok )
cmd open uiautomatorviewer
If it is not added to the environment variable, go to sdk In the directory uiautomatorviewer.bat
stay Android Studio Found in the first line of file——>Settings
Click Simulator , stay uiautomatorviewer find resource-id, This id Is unique to each click event .
Click on 1, Click on the event you want to operate 2, You can see that id 了
function python The simulator will automatically start the program after the code !
This is actually from the index
See the code
from appium import webdriver
import time
desired_caps=dict()
desired_caps['platformName']='Android'# The name of the platform , Case insensitive ,“Android”;“ios”
desired_caps['platformVersion']='5.0'# Version of the platform , No subsequent version number is required
desired_caps['deviceName']='emulator-5554'# Name of equipment , Can't be empty
# desired_caps['appPackage']='com.google.android.apps.messaging' # Name of the application package to open
# desired_caps['appActivity']='.ui.ConversationListActivity'# The interface name of the application to be opened
desired_caps['udid']='emulator-5554'# Unique identification of the connected device
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)# Connect appium The server
# driver.start_activity("com.google.android.apps.messaging", ".ui.ConversationListActivity") # Package name ( The bag name is in front of , Followed by the interface name )
# driver.find_element_by_id("com.google.android.apps.messaging:id/start_new_conversation_button").click() # Click event
# time.sleep(3)
# driver.quit()
# How to locate a set of elements , For example, I want to open the third option of the setting
driver.start_activity("com.android.settings",".Settings") # Package name ( The bag name is in front of , Followed by the interface name )
A=driver.find_elements_by_class_name("android.widget.LinearLayout") # Class name ( Remember that the class names should be the same , Try it yourself )
A[6].click()
time.sleep(5)
driver.quit()
Inside class_name through uiautomatorviewer To see , For example, I want to open Connected devices This option , Its index is 6( The first 21 Line code ), It will open automatically
https://blog.csdn.net/hanhanwanghaha A super invincible and cute duck Your attention is welcome !
Welcome to WeChat official account. : Treasure girl's Growth Diary
If reproduced , Please indicate the source ( If not indicated , Whoever steals will be prosecuted )
adopt class_name( Class name ) Locate a set of elements
find_elements_by_class_name("class_name")
adopt id Locate a set of elements
driver.find_elements_by_id("id_name")
adopt xpath Locate a set of elements
driver.find_elements_by_xpath("xpath_name")
In fact, this is one of the group methods elements Less s
adopt class_name( Class name ) Locate an element
find_element_by_class_name("class_name")
adopt id Locate an element
driver.find_element_by_id("id_name")
adopt xpath Locate an element
driver.find_element_by_xpath("xpath_name")
This is the automated test of my mobile terminal , I remember sending one before PC End of the automation test Click here to
https://blog.csdn.net/hanhanwanghaha Welcome to pay attention to this super invincible and lovely duck , If you have any questions, please leave a message , When you see it, you will return !
It's not easy to create , If reproduced , Please indicate the source