Python3 + Appium + Android emulator

Python3 + Appium + Android emulator

Overview

This article is mainly divided into the following parts

  1. Install Android SDK
  2. Install JDK
  3. Configure environment variables
  4. Install Python3
  5. Install the Appium library for Python3
  6. Install Appium
  7. Install the simulator (you can ignore it if you use the real machine)

text

1. Install Android SDK

Install Android SDK (Android Software Development Kit), and test Android phones must install Android SDK.

Download address: http://tools.android-studio.org/index.php/sdk/ download the latest version, and install it.

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-7QCPOOcf-1591254285915) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591175052887.png)]

Note: Do not use Chinese or spaces in the installation directory

Double-click SDK Manager to select tools. Mandatory installation: Android SDK Platform-tools and Android SDK Build-tools under Tools folder, Android SDK Tools can choose whether to update, it is recommended to update directly if the internet speed is OK. Android mirroring: Choose a version at will, you can choose not to choose another emulator (although I installed it, but because the startup speed is too slow, I chose to give up). GoogleFQ installation: all installations under the Extras folder.

Note: Find a place where you can use the Internet scientifically to download, as there are many things that will be slow. If you don’t use the emulator that comes with android, just download the three files of the tools.

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-gI4aA2HO-1591254285943) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591175223057.png)]
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-0rEJaLH5-1591254285949) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591175418609.png)][External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-zxUoKYY6-1591254285976)(C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591175441718.png)]
After you choose to install, a window will pop up to agree to the agreement requirements, and you can agree to
Insert picture description here
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-0hgJrPnY-1591254285986) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591176068979.png)]
remember to write down the installation path after installation, which will be used in the following text (for example, mine is: "D:\androidSDK")

Two, install JDK

Here I am using JDK8, the official website download address
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
select the corresponding platform to download
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-ZmP27LaZ-1591254285989) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591175913841.png)]

Downloading JDK now seems to require account login. If you don't want to be troublesome, you can download keywords like "JDK8 download" under Baidu. There are many download sites, just choose a reliable download.

The next installation process is relatively simple, it is also the next step, pay attention to choose the installation path, such as my installation path: D:\hadoop\java (the reason why this is not jdk is that I have downloaded java before, which contains jdk)

Three, configure the environment variables of SDK and Java:

1. Create a new ANDROID_HOME environment variable with a value of the sdk installation directory, which must correspond to the path during installation. (It is recommended to configure in system variables so that it can be used by all users)
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-prlwqPNm-1591254285991) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591176541531.png)]

2. Add a new value in Path, as follows:
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-VJhcEwRO-1591254286071) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591176672226.png)]
Note: Be sure to select New in Path, so as not to cause errors in other programs.
3. Configure Java environment variables as above.
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-VTwD9EUg-1591254286073) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591176845978.png)]
After configuring environment variables, you can find an Android phone to actually connect Test it, connect the Android phone, and turn on the developer option-USB debugging of the Android phone (Note: each model of phone may have a different name, but the same may be the same. Just make sure that the phone can be connected to the computer. Here is a Redmi 8 phone as an example .)
Execute under CMD

adb devices -l 

The appearance of the following figure means that the adb command is passed, model is the device name, and the deviceName variable used in the following text.
[External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-zbBKTqnS-1591254286075)()]

Fourth, install Python3

Simply log in to the Python official website https://www.python.org/ and download the latest version.
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-sG8cSnHl-1591254286077) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591174471627.png)]
Then you need to pay attention to the installation path when installing, and check "add python to path", you can omit the problem of configuring environment variables

Five, install the Appium library of Python3

Open the cmd command window and use the pip command to install the Appium-Python-Client library

pip install Appium-Python-Client

Note: If you encounter a timed out error, you can add a domestic source download afterwards

pip install Appium-Python-Client -i https://mirrors.aliyun.com/pypi/simple/

When you see the following signs, the installation is successful
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-IbXpbsVF-1591254286078) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591174926099.png)]

Six, install Appium

Official website address http://appium.io/
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-BPHz6keV-1591254286082) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591177470277.png)]
Click the download button to go to the download page of GitHub, select the corresponding platform to download, windows select the installation package to
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-s08AQV4Z-1591254286083) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591177510589.png)]
install, after the installation is complete, start Appium, host and port default, the first time You need to edit the configuration information when you use it.
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-qSj8alFN-1591254286089) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591177635120.png)]
Fill in the ANDROID_HOME and JAVA_HOME paths
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-y9ObNhZF-1591254286092) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591177651336.png)]
that we set when configuring the environment variables. Then click the save and restart button below, and then click the first Start Serverbutton, you will see
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-IpHubDfS-1591254286094)(C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591177724093.png)]
if you use the real machine to test, Plug in your phone and start writing script tests.

Seven, install the simulator (you can ignore this step when using a real machine)

Here is the download address of the night god emulator https://www.yeshen.com/ . It is not recommended to use the emulator that comes with Android (too slow).
There is nothing to say about this. Pay attention to the installation path and go all the way. Just one step.
After the installation is complete, make a simple modification:

  • Open the installation directory and enter the bin directory (for example: D:\Program Files (x86)\Nox\bin)
  • Copy the adb.exe file in the Android SDK installed in the third section (for example, mine is in the "D:\androidSDK\platform-tools" directory) to this directory to overwrite the existing adb.exe file in this directory
  • Delete the nox_adb.exe file in the directory, copy adb.exe and rename it to nox_adb.exe
  • Start the emulator
  • Then open the console in this directory, execute nox_adb.exe connect 127.0.0.1:62001, and then execute adb devices. If you see the following message, it means success
    [External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-2c5i8Q6v-1591254286096) (C:\Users\hq0749a\AppData\Roaming\Typora\typora-user-images\ 1591178698028.png)]

Above, the installation and configuration of Python3 + Appium + Android emulator is completed, and you can choose the emulator or the real machine for automated test operation.

Guess you like

Origin blog.csdn.net/weixin_45609519/article/details/106546921