Appium automated environment deployment

1. Required installation content

1、JDK

2、Android-sdk

3.Python and Pycharm

4. Appium server and client

2. Install and configure JDK

1. Go to the official website to download JDK.

2. Installed by default. After installation, the example is as shown below.

3. Configure the environment variables and create two new variables in the system variables, named JAVA_HOME and JRE_HOME.

4. Double-click Path in the system variables, create two new variables, and enter the following two values, %JAVA_HOME%\bin and %JRE_HOME%\bin respectively.

5. Verify the environment, enter java -version, or javac, or java in cmd, as shown below, the installation is successful. (If it shows that java is not an internal command or javac is not an internal command, it is a problem with environment variables)

3. Install and configure Android-sdk

1. Download sdk, https://www.androiddevtools.cn/ , it is recommended to download the compressed package format.

2. Unzip the package and double-click SDK.Manager.exe in the sdk directory.

3. Check: SDK Tools&Platform-tools&Build-tools, and then download.

4. Configure system variables and create a new system variable: ANDROID_HOME. The corresponding variable value is: D:\android-sdk (sdk installation path).

5. Add two variables to path, and add the two file paths pointed by the following arrows to path, D:\android-sdk\tools and D:\android-sdk\platform-tools.

6. Adb verification, because adb is in the directory D:\android-sdk\platform-tools, so after adding the environment variables above, you can run it directly in cmd. Enter adb in cmd to view the corresponding version number.

4. Install and configure Python

1. Download python, www.python.org

2. Install python, the process is abbreviated.

3. Verify, enter python in cmd, and the python version number will be displayed if the configuration is successful.

5. Install and configure Pycharm

1. Download Pycharm, http://www.jetbrains.com/pycharm/download/#section=windows

2. Installation, omitted.

6. Install the Appium server

1. Download the installation package, https://github.com/appium/appium-desktop/releases/tag/v1.22.3-4 (If the link cannot be opened, find another one yourself. Anyway, the package name is in the red box as shown below)

2. Installed by default.

3. Click startServer to start. The Host can be 0.0.0.0 or 127.0.0.1. They all have the same meaning. They all represent the local machine. Do not move the Port.

4. As shown below after startup.

7. Install Appium client

1. Enter pip install Appium-Python-Client in cmd. If the download fails, try upgrading pip. Pay attention to the case. You can download it several times and it will succeed.

8. Startup environment

1. Add environment variables, set the environment variables in the path D:\android-sdk\build-tools\29.0.3, and add it to the path. 

2. Open cmd and enter aapt. The following figure appears, indicating that the variable is set successfully.

3. Start appium server.

4. Get the package name, adb shell pm list packages -3. (Here is Taobao app as an example)

 5. Get launcherActivity, open cmd, enter the command aapt dump badging D:\xxx.apk (the full name of the APK, such as mobile Taobao.apk, be careful not to have Chinese characters in the path), drag cmd to the middle of the screen to find launcherActivity. (If you don’t know the apk, you can go to Wandoujia to get it)

 6. Write the following code in Pycharm. (The structure and variable names are fixed, but the device name, Android version, package name, and launcherActivity fill in the actual values)

deviceName can be obtained through adb devices.

platformVersion can be obtained through adb shell getprop ro.build.version.release.

from appium import webdriver


desired_caps = {
    # 操作系统名称Android或IOS
    'platformName': 'Android',
    # 设备名
    'deviceName': '127.0.0.1:62001',
    # Android版本
    'platformVersion': '7.1.2',
    # apk 包名
    'appPackage': 'net.oschina.app',
    # apk 的 launcherActivity
    'appActivity':'net.oschina.app.improve.main.splash.SplashActivity',
    # 默认初始提示框取消
    'noReset': True
}

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

7. Run the script in Pycharm, and then an icon Appium Settings will automatically appear on the mobile phone desktop, as shown below, the startup is successful!

 8. Then the Taobao app will start automatically.

9. Install Appium-Inspector (element positioning inspector)

1. Download address: https://github.com/appium/appium-inspector/releases

(If it cannot be opened, use a ladder to access the Internet scientifically)

2. You can download the installation package or compressed package, and it will be installed by default.

3. Fill in the fields as shown in the figure, with fixed values.

 4. Fill in the form as shown in the picture and fill in the actual value.

5. Click Save As to save.

6. Click Start Session to open the session, display the test APP interface, and locate elements.

 

Ten, UI Automator Viewer

In addition to using Appium-Inspector to locate elements, you can also use UI Automator Viewer to locate elements.

1. UI Automator Viewer is in the tools directory in the Android-sdk installation directory. Double-click uiautomatorviewer.bat to open it.

 2. The interface is displayed as follows, showing the interface of the test APP and allowing you to locate elements. Click the button in the upper left corner to get the mobile interface.

Guess you like

Origin blog.csdn.net/v781423070/article/details/131216055