current position:Home>Android mobile phone simulator / real Android mobile phone + appium + Python 3 7 simple test

Android mobile phone simulator / real Android mobile phone + appium + Python 3 7 simple test

2022-02-02 14:47:45 Wood sauce acridine

Environment building

1. install python3.7
https://www.python.org/downloads/
Click below to download the historical version


2. install pycharm
https://www.jetbrains.com/pycharm/download/#section=windows
Note the corresponding operating system download .Professional It's a professional version ( You should pay ) Community It's the enterprise edition ( No charge )


3. install JDK1.8

4. install android studio And SDK
install android studio Remember to check SDK
a key : Configure environment variables
Right click Properties on the computer , Enter environment variables , In system variables Path Path join SDK in platform-tools and tools Catalog . namely :
C:\Users\dell1\AppData\Local\Android\Sdk\platform-tools;C:\Users\dell1\AppData\Local\Android\Sdk\tools;C:\Users\dell1\AppData\Local\Android\Sdk\build-tools\29.0.3;
platform-tools Are there in adb.exe,tools Are there in android.bat,build-tools Are there in aapt.exe
After configuring the environment , Can be in cmd Internal input adb and android and aapt The command .




If installed SDK There is no platform-tools and tools Catalog , Can be in android studio in file->setting in , Installation SDK Tools .

Be careful android Commands may not work , Because in Android Studio Official website sdkmanager On the page , Explicitly mentioned in Android SDK Tools25.2.3 And later provided sdkmanager command-line tools And abandon android command .
In order to continue to use Emacs Development Android Program , We use a version lower than 25.2.3 Of android SDK Tools.
We can AndroidStudio The Chinese community Download the old version of SDK Tools. such as   here   download 24.2 edition .
Unzip after download , Copy it tools Catalog , Cover the original tools directory .

5. install node.js
https://nodejs.org/en/download/
After the installation , Configure environment variables

And then you can use npm The command .

6. install appium
Method 1:
utilize npm Command to install appium
npm install -g appium
Method 2:
Download on official website

Download and install appium after , Configure environment variables , take node_modules.bin add to , Ben Xiaobai npm Command installed , Environment variable configuration Path Add the following :
E:\node-v12.18.0-win-x64\node_modules\appium-doctor\node_modules\.bin
After configuration, you can use appium Command and appium-doctor The command

7. install Appium Python Client modular 、Selenium modular
Method 1:pip Command to install
pip install Appium-Python-Client
pip install selenium
Method 2:Pycharm Download ,file->setting->Projiect->Project interpreter-> +


8. Download the test software , namely android Software (apk Extended name )
To be on the safe side , It can be shared on the computer through the software in the official app store on the mobile phone , In the download .
This test is a calculator software , On the cell phone ( Real machine ) Downloaded from the app store on Caculator.apk And share it on the computer , Download one on your computer .
Put it in the computer E:\Caculator.apk in
View the of the software appPackage and appActivity Content :
aapt dump badging Caculator.apk | findstr "package"
aapt dump badging Caculator.apk | findstr "activity" or adb shell dumpsys activity activities


Android Mobile phone simulator test apk Software

1. stay Android Studio Inside Tools->AVD Manager A mobile phone simulator can be installed in the , Ben Xiaobai installed android 10 Of .


2. After power on , use adb Command to see if there is a device .
cmd Window command :adb devices -l

It was found that there were .

3. Check the device name 、 Equipment version and other information .
It can be set in the mobile phone to view

4. Write tests Python Script code

#coding=utf-8
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'Android10'
# desired_caps['platformName'] = 'Android'
# desired_caps['platformVersion'] = '6.0.1'
# desired_caps['deviceName'] = 'vivoY66'
desired_caps['appPackage'] = 'com.ddnapalon.calculator.gp'
desired_caps['appActivity'] = 'com.ddnapalon.calculator.gp.ScienceFragment'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_three").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_two").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_two").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_two").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_three").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_two").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_three").click()
driver.find_element_by_id("com.ddnapalon.calculator.gp:id/btn_two").click()
driver.quit()

Note that the position of the positioning element can be used sdk/tools/uiautomatorviewer.bat Tools


5. Turn on appium



6. function python Script code files ~ give the result as follows :

Android Real phone test apk Software

android The mobile phone is connected to the computer with a data cable , Go to phone settings -> More Settings -> About mobile phone , Press continuously “ Software version number ” The text box , Enter developer mode , Get into “ Developer options ” in , open USB Debugging and USB Analog buttons function .
The test script written is similar to the above .

copyright notice
author[Wood sauce acridine],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202021447437216.html

Random recommended