Build Android automation python+appium environment

1. Software required

  1. JDK: Configure the JDK environment after JAVA installation

  2. SDK: After downloading the SDK, configure the adb environment

  3. Python: python language

  4. Pycharm: python script compilation tool

  5. Appium-python-client: library in pyhton

  6. Appium client

2. Construction steps

1. Configure the JDK environment

①. Download and install java:

https://www.oracle.com/java/technologies/javase-jdk14-downloads.html

②. When installing, you need to pay attention to installing java and jre in two separate directories. Otherwise, problems will occur.

③. Configuration environment:

Right-click on the computer->Properties->Advanced system settings->Environment variables:

Enter the java and jre directories in the system variables: You can also refer to Baidu to solve configuration problems.

2. Configure the SDK environment:

①. Download SDK:

https://android-sdk.en.softonic.com/

②.Configuration

After downloading the SDK, there is no need to install it, just unzip and configure it.

Enter the platform-tools and tools directory in the system variable -> path, which can also be solved by Baidu.

3. Download and install python

①.Download: Download the version corresponding to the system

https://www.python.org/

②. Installation. When installing, you need to check add pyhton to path so that environment variables can be automatically configured.

③. Enter pyhton in CMD and press Enter to display the pyhton version, which indicates that the installation and configuration are successful.

4.Pycharm download and installation

①. Download: https://www.jetbrains.com/pycharm/

②. When installing, you need to pay attention to checking the appropriate shortcut. There are 32-bit and 64-bit. Choose according to your own system.

③. When opening a new pycharm project, you must configure the interpreter. You can configure it when you create a new project, or you can configure it in file–>settings.

④. After configuration, you can open it for programming.

5. Install the Appium-python-client library

This can be divided into two methods:

①. Install in cmd: Enter cmd, enter pip install Appium-python-client, and wait for the installation to complete.

②. Select project interpreter in file–>settings–>project in pycharm, click + in the upper right corner of the package list, then search for Appium-python-client, click install package at the bottom of the window, and wait for the installation to complete.

6.Appium client:

①. Download: http://appium.io/

②. Generally, just install it by default.

3. Mobile phone configuration

  1. Turn on developer mode

  2. Enable USB debugging mode

  3. In CMD, enter adb devices and the mobile phone information can be recognized to indicate success.

  4. Open the uiautomator.bat file in SDK->tools, and you can position elements on the phone.

4. Code implementation

  1. Open pycharm

  2. The installed library needs to be imported before it can be used: from appium import webdriver

  3. Then configure the device information:

desired_caps={ #Mobile device platform'platformName':'Android', #Platform OS version number'plathformVersion':'7', #The name and value of the device can be written as you like'deviceName':'test0106', #Provide the app under test Information - package name, entry information 'appPackage':'com.hpbr.bosszhipin', 'appActivity':'.module.launcher.WelcomeActivity', #Ensure that the app is not reset after automation 'noReset':True, #Set session Timeout time in seconds 'newCommandTimeout': 6000

Initialization object:
#Initialize driver object - used to control mobile phones driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)driver.implicitly_wait(10)#Stable element

Next, you can position the elements.

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

Insert image description here

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!   

Guess you like

Origin blog.csdn.net/qq_48811377/article/details/132919229