Today's question
I : Simple tests can be operated manually , Why automated testing
teacher : Mainly regression testing . Changed bug after , Test again . In this way, regression testing is more cost-effective than manual testing
https://blog.csdn.net/hanhanwanghaha Treasure girl 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 )
Turn on the simulator
stay cmd Enter the code :
adb shell dumpsys window | findstr mCurrentFocus
The package name and interface name can be queried ( The package name can be omitted from the interface name , But I'm afraid I missed that point , Generally do not omit )
For example, my package name :
com.google.android.apps.messaging
Interface name
.conversation.screen.ConversationActivity
or
com.google.android.apps.messaging.conversation.screen.ConversationActivity
open appium, Enter server , Click on the search box , Enter interface
Click on
Enter the editing interface , Enter the code in the box to connect to the simulator
The code is as follows
The following code comments :
Article 1 with a : The name of the platform , Case insensitive ,“Android”;“ios”
Second : Version of the platform , No subsequent version number is required
Article 3 the : Name of equipment , Can't be empty (cmd after adb devices You can see )
Article 4. : Name of the application package to open ( above cmd Your orders can be found out )
Article 5. : The interface name of the application to be opened ( above cmd Your orders can be found out )
Article 6. : Name of equipment
{
"platformName": "Android",
"platformVersion": "5.0",
"deviceName": "emulator-5554",
"appPackage": "com.google.android.apps.messaging",
"appActivity": "com.google.android.apps.messaging.ui.ConversationListActivity",
"udid": "emulator-5554"
}
Remember to save it after filling it out
Click on Start Session, You can go in appium Automation interface , The simulator will also run automatically
Next, let's look at the key we want to press xpath route , Click the key I want to run automatically , stay Select Element Can be seen in xpath route .
Keep the bracketed portion of the path , For example, mine is
//android.widget.Button[@content-desc="Start chat"]
What is needed is
[@content-desc="Start chat"]
But in the pycharm There will be errors in the , So you need to change the quotation marks ( This self adjustment is )
So put it on pycahrm Medium python The code should be
driver.find_element_by_xpath("//*[@content-desc='Start chat']").click() # Click event
Upper actual combat 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", "com.google.android.apps.messaging.ui.ConversationListActivity") # Package name ( The bag name is in front of , Followed by the interface name )
time.sleep(3)
driver.find_element_by_xpath("//*[@content-desc='Conversation list']").click() # Click event
time.sleep(3)
driver.find_element_by_xpath("//*[@content-desc='Start chat']").click() # Click event
time.sleep(5)
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")
# A=driver.find_elements_by_class_name("android.widget.LinearLayout")
# A[6].click()
# time.sleep(5)
# driver.quit()
And then , my app It can run automatically
as follows
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