Automated testing of Appium mobile terminal--build simulator and real machine environment

Emulator--Install Android Studio and Android SDK

It is recommended to install Android Studio directly, and then use Android Studio to install the SDK. Start the SDK Manager, install the version you need, download and install it.

 

insert image description here

insert image description here

Then set the ANDROID_HOME environment variable  ANDROID_HOME=D:\InstallationDirectory\Android\android-sdk

insert image description here

After the installation is complete, click the phone icon to create a virtual phone

insert image description here

Note:  When installing a new Android virtual machine, choose version 9.0 as much as possible. At the beginning, I chose 10.0. It was not very stable while waiting for use, and I haven't spent time on in-depth research.

 

insert image description here

The virtual machine has been successfully created, as shown in the following figure:

insert image description here

Simulator--Change VDM default storage path 

When creating a new VDM virtual machine, I found that the C drive became popular without creating a few new ones. It turned out that I forgot to change the VDM storage location. The default storage is on the C drive. A mobile phone has eight or nine G, so it’s no wonder it’s not popular. Find the setting method as follows: ANDROID_SDK_HOME=D:\InstallationDirectory\Android\Android_Virtual and restart SDK Manager.

insert image description here

Next, open the cmd command window to check whether the mobile phone started by the emulator is connected, and enter:  adb devices  to view the connected device;  adb devices -l  to view the detailed information of the drivers;

View connected devices

The above is the emulator environment that needs to be installed when using the emulator.

The following describes the operations and settings that need to be done when connecting to a real device (Android)

 

Real machine (Android) environment settings

Real device--Enable developer mode

First you need to have a real Android phone. To connect to a real device, you need to enable the developer mode. Find Settings>System>About Phone>Version Number on the phone , and then tap 7 times in a row to enable the developer mode.

About Phone>Version Number

After completing the above operations, you will be prompted that you are already in the developer mode; we will see the developer mode item in the setting options, as shown below:

Developer Options

Real device -- turn on USB debugging

In the developer options or developer options , turn on USB debugging, as shown in the figure below, check the USB debugging:

 

USB debugging

Real machine connection--file transfer

When connecting the Android phone to the computer with a data cable, if there is a USB connection method, there are generally three options: transfer photos, file transfer, and charging only.  Please select file transfer  and then open the CMD window on the computer, enter: adb devices -l View connected device.

 

view device

So far, both the emulator switch and the real device have been set up, and then use the cmd command to start installing the downloaded apk installation package.

Install the apk file

The installation method here is the same whether it is an emulator or a real machine. Enter the command in the cmd window to install the apk installation package, such as installing the downloaded snowball apk installation package: adb install D:\InstallationDirectory\apk\xinglicheng.apk As shown in the figure below, it shows that the installation has been successful, you can go to the emulator or Android real Go to the machine to check that the installation is successful.

install apks

At this point, the environment of the simulator and the real machine are ready, and the next step is to install Appium  Server.

 

Install Appium Server via npm

Appium is developed using Node.js, so you need to install Node.js 1. Download and install Node.js (LTM is recommended) and npm  https://nodejs.org/zh-cn/download/

Node.JS download

2. Install Appium Method 1. Download and install Appium from the official website: https://github.com/appium/appium-desktop/releases/tag/v1.15.1

Method 2: npm install Appium Official version installation: npm install -g appium (was blocked) (It is recommended to set the Taobao mirror warehouse address before installing) npm install -g cnpm --registry=https://registry.npm.taobao .org npm config set registry https://registry.npm.taobao.org Verify that the Taobao mirror is set successfully: npm config get registry Install Appium: cnpm install -g appium

Start Appium GUI mode

Without changing any configuration, select "Start Server "

Appium interface

As shown in the figure below, you can see that the connection has been successful. Click the magnifying glass icon in the figure below to start the inspector session

App Server

And set the new pop-up session window, and then start the session

  • platformName---device platform: fill in Android or IOS
  • deviceName----device name: Just fill in the device name found by adb above, and you can fill in any one for Android.
  • appPackage----The package name of the app to be started: WeChat is "com.tencent.mm"
  • appActivity----interface to be launched: WeChat startup interface is ".ui.LauncherUI"
{
  "platformName": "android",
  "deviceName": "ruancexiaosheng",
  "automationName": "uiautomator2",
  "appPackage": "com.xueqiu.android",
  "appActivity": ".view.WelcomeActivityAlias"
}

 

Appium connect session

Then go to the Appium interface, enter the relevant configuration parameters, select the Customer Server interface, and click "Start Session" in the figure below to invoke the inspector.

 

Appium connect session

After that, the inspector connection interface shown in the figure below will appear. If the interface has not been updated, click the refresh button in the middle to see the latest interface.

inspector connection interface

Error: An unknown server-side error occurred while processing the command. Original error: Could not sign with default certificate. Original error Command 'C:\Program Files\Java\jdk1.8.0_77\bin\bin\java.exe' not found. Is it installed? For some reason, I felt that the suggested path was wrong. After upgrading to Appium1.15.1, no error was reported.

Error: appium Could not connect to server; are you sure it's running? When running Appium, select Customer Server and start it again, as shown in the figure below

 

Custom Server

Possible reasons for Appium Server installation difficulties:

  • Some dependencies are not accessible overseas.
  • Node.js installation Do not install with root privileges.
  • Node.js version should not be too low or too high, LTS version is recommended, or get the recommended version from Appium source code.
  • Requires python2 to be present.
  • node_module does not have write permissions.
  • Windows needs to rely on compilation tools.
  • The PATH variable needs to set paths such as adb java, which can be verified with appium-doctor.
  • iOS also needs to solve the compilation and dependency download of WebDriverAgent.

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

These materials 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, and I hope it can help you! Partners can click the small card below to receive

Guess you like

Origin blog.csdn.net/okcross0/article/details/132278170