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

Python+appium automated test pit avoidance Guide

編輯:Python

One 、 Environment building : Environment variable is not valid

1、 First , Add a variable named... To the system variable :ANDROID_HOME, The value is :D:\android-sdk

2、 then , In system variables , Existing Path Add... After the value of the variable :D:\android-sdk\build-tools\22.0.1, Remember to put a semicolon in front of it

3、 Last , Restart the computer , Bear in mind , If the environment variables are configured , It also reports the error that the variable is not added , Remember to restart the computer , All say : Restart to solve all kinds of problems , Here I have seen .

Two 、 Run script : The real machine constantly prompts that you need to install unlock,manager Wait for the plug-in and the installation fails

1、 In the process of mobile phone automatic test , There is absolutely no need to install these plug-ins , The idea is to skip the installation of these plug-ins , Here's how , How I deal with this situation :

It is forbidden that the mobile phone needs to be installed every time it is started unlock,manager Etc , stay D:\Appium\node_modules\appium\lib\devices\android\android.js, notes 4 Line code , The comment code is as follows :


//this.initUnicode.bind(this)
//this.pushSettingsApp.bind(this)
//this.pushUnlock.bind(this)
//this.unlock.bind(this)

As shown in the screenshot :

2、 When you run the script again , You won't be prompted to install these plug-ins .

Be careful : If you modify the above android.js After the document , Save or prompt to install the plug-in , This should be restart appium The server , Then rerun the script , Avoid that the modified document does not take effect in time .

3、 ... and 、 Run script : Report errors Original error: Permission to start activity denied

The solution is as follows :
stay doc Execute command in window :aapt dump badging D:/Apk/app-v3.7.6_docker.apk( Or just put apk Drag into the command line )

Use this command to get package The value of and launchable-activity Value

In the running result, the following two lines are the name of the application package package And entrance activity name

package: name=’com.xxx.android.xx’

launchable-activity: name=’com.xxx.android.xx.view.xxxrActivity’

notes : stay android sdk Directory search can find aapt.exe, Or when doc Window tip :aapt If it is not an internal or external command, please refer to the following solutions .

Four 、 The solution is doc Window execution aapt On command , Tips : Not an internal or external command method :
D:\android-sdk\build-tools\22.0.1 Add this to the... In the system variable Path in , There are aapt.exe,Path After adding, you need to restart doc window , Re execution aapt command , You can get :package and launchable-activity Value


5、 ... and 、 For manual start APP when , No boot page , There is a boot page when the script starts

processing method :

First use the script After starting to the boot page , Sleep all the time and use sdk Comes with tools in uiautomatorviewer.bat To locate the guide page to get the element

6、 ... and 、 The exit login button element is not on the current screen Treatment method :

Slide first and then locate with coordinates , The code is as follows :

x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
self.driver.swipe(x / 2, y * 0.8, x / 2, y * 0.2, 200)
time.sleep(3)
os.popen("adb shell input tap " + str(659.0) + " " + str(1834.0))
self.driver.find_element_by_class_name("android.view.View").click()
os.popen("adb shell input tap " + str(945.0) + " " + str(1140.0))
self.driver.find_element_by_id("com.autochina.p2p:id/btn_dialog_action").click()
self.driver.quit()

First : Get the width and height of the current mobile screen

secondly : In a certain period of time, it slides upward according to the corresponding proportion

then : Use the positioning tool to locate the coordinate point of the element

Last : According to the attribute value of the obtained element , Click to operate , The same method is used to obtain the bullet frame elements

Welcome to your attention 【 The way of immeasurable testing 】 official account , reply 【 Claim resources 】

Python+Unittest frame API automation 、

Python+Unittest frame API automation 、

Python+Pytest frame API automation 、

Python+Pandas+Pyecharts Big data analysis 、

Python+Selenium frame Web Of UI automation 、

Python+Appium frame APP Of UI automation 、

Python Programming learning resources dry goods 、

Vue Front end component framework development 、

Resources and code Free ~
Below the official account is two-dimensional code. , You can directly scan wechat and pay attention .

remarks : My official account has been officially opened. , betake IT Sharing of Internet technology .

contain : Data analysis 、 big data 、 machine learning 、 Test Development 、API Interface automation 、 Test operation and maintenance 、UI automation 、 Performance testing 、 code detection 、 Programming technology, etc .

WeChat search official account :“ The way of immeasurable testing ”, Or scan the qr code below :

 

Add the attention , Let's grow together !


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