App automation test introduction and environment construction

1. Introduction to App Automation Tools

As a type of testing that has emerged in recent years, App automation testing is becoming more and more popular. The current mainstream App automation tools are: Appium, Robotium, Espresso, Calabash, etc.

 

Here we mainly talk about the most mainstream tool: Appium.

 

 

Comparison of mainstream App testing tools:

 

 

Appium supports automated testing of Android and IOS. Appium supports all languages ​​supported by Selenium WebDriver, such as java, Object-C, JavaScript, Php, Python, Ruby, C#, Clojure, or Perl. You can also use Selenium WebDriver's Api. Novices are easy to get started, but at least they must be familiar with a language such as java.

 

Appium's architecture:

 

 

In fact, Appium mainly controls the phone by obtaining the root debugging permission of the phone through the bootstrap.jar package in the Android operating system.

 

From Appium's point of view, the mobile phone can be regarded as a website web, and the Appium server and the mobile phone communicate mainly through session dialogue.

 

Automation always revolves around a Session (session). The client initializes a Session to interact with the server. Different languages ​​have different implementations, but they all eventually send a POST request to the server. The request contains a JSON object called "Desired Capabilities".

 

At this point, the server will start an automated Session, and then return a Session ID, which will be sent by the user to subsequent commands.

 

Desired Capabilities is a collection of key-value pairs (such as a map or hash). The client sends these key-value pairs to the server, telling the server how we want to test.

 

For example, we can set the platformName capability to android and tell the Appium server that we want an android session instead of an IOS session.

 

Client/ServerArchitecture Appium server is written in node.js, you can use npm command or dmg directly to install node.js, server-side functions: monitor a port, receive the command sent by the client, translate these commands, and convert these commands into mobile The device can send it to the mobile device in a form that the device can understand, and then the mobile device returns the execution result to the appium server after executing the command, and appium returns the execution result to the client.

 

Client is actually the device that initiates the command. Generally speaking, it is the machine that executes the code. The machine that executes the appium test code can understand the client as code. These codes can be java, python, ruby, js, as long as the webdriver standard protocol is implemented. can.

 

 Two, environment construction

1. Install Python

 

It is recommended to install Python 3.6 and above, download link: 

https://www.python.org/downloads/windows/

 

Note that in the installation interface, select the following custom installation, and check the following to add the installation path to the path environment variable.

 

 

Note that in the second interface afterwards, check the first one: Install for all users.

 

 

The installation path below will become under c:\program files(x86)\pythonxx.

 

After the installation is complete, enter: python in cmd mode. If you can enter the python programming environment, the installation and configuration of environment variables are successful.

 

 

2. Install JDK

 

Refer to my previous java blog: 1. Java overview, installation and environment construction 2.3 Java development environment construction, and configure the corresponding path environment variables:

https://www.cnblogs.com/jeknight/p/6872114.html

 

3. Install Android SDK

 

download link:

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

Note that there should be no Chinese or special characters in the installation path.

 

After the installation is complete, use the installation path to add an environment variable: ANDROID_HOME value is the decompression location of the android sdk.

 

Modify the path environment variable: add three:

%ANDROID_HOME%\tools;

%ANDROID_HOME%\platformtools;

%ANDROID_HOME%\build-tools\29.0.2

 

After completion, run SDK manager.exe in the installation directory, install the following checked packages, and click install/update to install.

 

Other installation packages, especially the Android system image do not need to be installed, for automated testing.

 

 

4. Install node.js

 

Node.js must be installed before appium is installed.

Download address: https://nodejs.org/en/download/

 

Note: 32-bit and 64-bit are different versions

After installation, you can use the node -v command to check whether the installation is successful.

 

5. Install Appium

 

Download link: https://github.com/appium/appium-desktop/releases/tag/v1.15.1

 

Download your own version of the corresponding operating system, after all the way to next installation, you can see the running interface of appium-destop.

 

 

Here we put appium aside first, first prepare the equipment we want to connect.

 

6. Install the simulator

 

In some cases, it may be inconvenient for us to test with a real machine, we can first install the simulator on the computer for testing.

 

Of course, this has great limitations. The performance of the simulator and the real machine and the operating system version may vary greatly, so the simulator cannot replace the real machine for automated testing.

 

It is recommended to use the night god simulator, the latest version 6.5.0.0 is based on the android5.1.1 version.

 

The avd emulator that comes with android sdk is not very recommended, the performance is slower and the freeze is more serious.

 

 

7. Connect to the emulator or real machine

 

Connect to the real machine

 

Connecting to the real machine is relatively simple. Open the developer option, then check the usb debugging mode in the developer option, and then connect the data cable to the computer, the phone will pop up whether to allow usb debugging, click OK.

 

The developer options of many mobile phones are hidden, so you need to open the corresponding model of Baidu first. For some mobile phones, you can open it in Settings -> System -> About the mobile phone interface.

 

If the mobile phone is connected to the computer via the data cable, it may not be recognized or the adb connection is not possible. At this time, you need to download the usb driver corresponding to your mobile phone model.

 

 

If the above connections and drivers are normal, open the cmd window and enter: adb devices

 

If the connection is normal, as shown below:

 

 

If this happens, the device displays as unauthorized, indicating that the phone does not allow the computer's usb debugging, recheck the corresponding settings of the developer options.

 

 

Sometimes the inconsistent adb version will also cause the adb connection failure, so you may need to upgrade or downgrade the platform-tools in the android sdk.

 

Connect to the simulator

 

Connecting to the emulator is a bit more troublesome, first run the emulator: Night God

 

Check the process PID through task manager -> detailed information, as shown below:

 

 

Then enter in cmd mode: netstat -ano|findstr "Night God's PID" to view the port occupied by the simulator.

 

The communication port found here is: 62001, of course, if you only use the Night God simulator, it is also possible to remember this port.

 

 

Then use the adb tool to connect to the simulator: adb connect 127.0.0.1:62001

 

 

After connecting, you can also use: adb devices to view the currently connected devices.

 

8. Start Appium

 

Appium has two startup modes: simple and advanced.

 

9. Simple mode start

 

After ensuring that adb is connected, start appium, fill in the local address in host: 127.0.0.1, and click start server.

 

 

Then if everything is normal, you can see this interface.

 

 

10.advanced advanced mode

 

Generally only need to fill in Server Address: 127.0.0.1

Check the local timezone, allow session override, log timestamps three items below.

 

Among them, allow session override is more important. When the use case fails to execute, the session will not be closed automatically. Failure to check this will cause the subsequent use cases to fail to continue.

 

 

After setting, you can click Save As Presets on the right to save the settings, and next time you can click Presets to choose to use the saved settings.

 

At this point, we have initially completed the establishment of the appium automated test environment.

 

Next, we will talk about Python environment setup and installation of appium-python-client.

 

11.Pycharm installation

 

For the installation and settings of pycharm, please refer to my other blog: https://www.cnblogs.com/jeknight/p/

11453901.html

 

There are two ways to crack, offline and online. The online javaagent.jar package cracking method is recommended here, which can be cracked permanently. Refer to the following blog:

 

https://www.cnblogs.com/teamemory/p/8473727.html

 

Or use pycharm community version without cracking, there is no difference in writing python.

 

New Project

 

 

12.pycharm settings

Install appium-python-client

 

There are two installation methods:

01. pip installation

Enter in the cmd command line: pip install appium-python-client

 

Note: pip is an online installation tool similar to yum in linux. It will visit the official website of python to install the library, so Internet access is required to use it.

 

If the pip command is not recognized, check whether the python installation directory and python\scripts directory are added to the path environment variable.

 

The pip version does not need to be the latest, but if it is too far from the current version, it may not work properly. You can enter python -m pip install --upgrade pip on the command line to upgrade pip.

 

02. Install in pycahrm

 

 

1> First click File->Settings->project interpreter

2>Click the + sign on the right

3> In the pop-up search box, enter: appium

4> Select appium-python-client

5> Click the install button below and wait for the installation to complete.

 

Guess you like

Origin blog.csdn.net/weixin_43802541/article/details/110197985