程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python app automation test practice part ④] - drive the night God simulator through appoum to complete the first automation script - view the address book

編輯:Python
Wanyeji Faint thunder , Cloudy sky . But I hope the wind and rain will come , I can keep you here .


Preface
Author's brief introduction : Husky who yearns for power , You can call me Siberian Husky , One devoted to TFS - The whole stack Empowered bloggers
CSDN Blog expert certification 、 Nova plan Season 3 full stack track top_1 、 Huawei cloud sharing expert 、 Alibaba cloud expert Blogger
If there is something wrong with the knowledge of the article , Please correct me. ! Learn with you , Progress together
The motto of life : Being superior to some other man , Is not high , The true nobility is to be superior to one's former self .
If you feel the blogger's article is good , Please pay attention. 、 give the thumbs-up 、 Collect three companies to support bloggers


Column series ( Click unlock ) Learning route guidance Knowledge orientation Python Full stack white paper Zero foundation beginner level chapter Easy to get started in an easy to understand way , Let you fall in love with Python The charm of . Advanced Grammar Mainly around multi-threaded programming 、 Regular expression learning 、 Including project exercises close to actual combat . Office automation Realize the automatic operation of daily office software , Save time 、 Improve office efficiency . Automation test practice From the perspective of actual combat , One step ahead , Rapid transformation test development engineer . Database development practice Updating Introduction and practice of reptile Updating Data analysis Updating Introduction to the front +flask Full stack Updating django+vue Full stack Updating expand - Introduction to artificial intelligence Updating The road to network security Stepping on a pit Record the pit encountered during learning and drilling , It is convenient for those who come from behind to catch up Net security literacy Three days fishing , No deep understanding of the principle , It will only make you a script boy . vulhub The loopholes in the shooting range reappear Make it easy to reproduce vulnerabilities , Let security researchers focus more on the vulnerability principle itself . shell Programming Don't involve linux Basics , The final case will be in the direction of safety reinforcement . [ To be finished ] WEB Vulnerability attack and defense 2021 year 9 month 3 Stop updating on , Move to safe communities such as prophet community and small secret circles Collection of penetration tools 2021 year 9 month 3 Stop updating on , Move to safe communities such as prophet community and small secret circles A little Engineer Test artifact - Charles Software test data packet capture analysis artifact Test artifact - Fiddler Learn to fiddle , Learn not to stand upside down and eat , Rarefied ! Test artifact - Jmeter Not just a performance test artifact , It can also be used to build a lightweight interface automation testing framework . RobotFrameWorkPython Automatic test tool realized , This chapter only introduces UI Automation part . Java Realization UI automation Document written in 2016 year ,Java Realized UI automation , It still has reference significance . MonkeyRunner There are not many application scenarios for this tool at present , The document has been deleted , Only for the sake of good typesetting .


List of articles

    • Use the pre operation of the simulator
    • Write a script - Auto view contacts

Next, let's take a look at how to pass... Through a simple example appium Here is a tool 、 The framework implements the operation of mobile phones app, The examples used are also very simple , Is to access and view the address book .

Later, we will use the Android simulator to demonstrate the interaction , The simulator is “ Night God Simulator ”. In fact, this is a game simulator , But its compatibility and use are very convenient , So our APP It is often used in the field of automated testing .( Besides the simulator of nocturnal , Xiaoyao is also well-known 、 Thunder and lightning 、MuMu Simulator, etc )

The installation of nocturnal simulator directly accesses the official website www.yeshen.com Download and install .

Use the pre operation of the simulator

After we configure appium Environment 、 Install well “ Night God Simulator ” after , One more step is required . This is what will be “ Night God Simulator ” Self adb Replace with We installed Android SDK Of adb .

This is because Simulator's adb The version of Android SDK Of adb Be low , In this case, the service cannot be started , So we need to replace .( If it is windows System words , You also need to copy the adb.exe Change to nox_adb.exe , It depends on the actual situation .)

In this way, two adb The version of is exactly the same .

The path of the night God simulator is /Applications/NoxAppPlayer.app/Contents/MacOS



Then use the path to the nocturnal Simulator , utilize adb Link to the current nocturnal Simulator .

  • Carry out orders :adb connect 127.0.0.1:62001 ; The default port of the night God simulator is 62001; When there is a connected to 127.0.0.1:62001 Is connected to the device .
  • Carry out orders :adb devices ; If appear 127.0.0.1:62001 device It represents the current adb The link has been completed .


Write a script - Auto view contacts

Before scripting , Make sure we have installed appium-python-client modular , Before we build APPIUM The module has already been installed in the environment .

# coding=utf-8
from time import sleep
from appium import webdriver # appium The feature of Android is that Android 、IOS The bottom layer of is encapsulated into webdriver Type statements 
# from appium.webdriver.common import appiumby
''' The difference in WEB automation ,APP Automation requires a concept of equipment ; The so-called equipment concept , Is the start parameter '''
# Launch parameters 
desired_caps = {
} # Definition desired_caps Variable , Used to assign a lot of startup information 
desired_caps['platformName'] = 'Android' # Equipment name 、 System is "Android"
desired_caps['platformVersion'] = '7.1.2' # Here is the setup center of the night God simulator to view the Android version "7.1.2" , Later, I will tell you how to switch versions 
desired_caps['deviceName'] = '127.0.0.1::62001' # If it is a real machine, fill in the equipment name ; Because we use simulators , Fill in IP Port number 
desired_caps['appPackage'] = 'com.android.contacts' # APP The package name ; Here we use the address book 
desired_caps['appActivity'] = '.activities.PeopleActivity' # The name of the launched interface ( Or the startup name , The default is "." At the beginning )
desired_caps['automationName']='UiAutomator1'
# Declare the mobile driver 
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # Register to this node , Pass in "desired_caps". This node is "appium" Open port node 
# Navigate to the contact you want to work on 
driver.find_element_by_id('com.android.contacts:id/cliv_name_textview').click() # Here is the demonstration effect , First write . Later, I will tell you how to locate this id
sleep(3)
driver.quit()

The operation results are as follows :



About the details in this script appium Capability attribute , It will be explained in detail in the next chapter , This chapter is mainly to show you appium The effect of automation .




  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved