How to build an App automation testing framework?

Preface

Appium is an open source automated testing framework that supports cross-platform and multiple programming languages. It can be used for native, hybrid and mobile web applications. It uses webdriver to drive ios and android applications. So in order to learn app automation testing, the first task must be to build Test the development environment, so here is the complete process of setting up the Appium automated testing environment. The article is long and takes a certain amount of time. Please read it patiently. Please correct me if there are any errors in the article.

Install Java JDK

In the JDK environment, you can see that I installed Jenkins before. 

Install Node.js

Before installing nodejs, we need to know, why should we install nodejs? Because appium is implemented by nodejs, node is equivalent to the interpreter of appium.

Node.js download address: Download | Node.js

Since my computer is a Windows 64-bit system, here I directly download the Windows 64-bit msi program file.

After downloading, just double-click to install (fool-style installation), so I won’t go into the specific steps. After installation, check whether the installation is successful.

Enter the first command node -version in the cmd terminal and output the following information

 

Then enter the npm command and output the following information

ok, this means that node.js has been installed successfully. 

Install Appium server

I don’t know if you have done or studied selenium. The appium server here is equivalent to the browser driver in selenium. When the browser driver is started, a server will be initialized and bound to the local address and port. The same is true for the Appium server. , when appium is started, a server will also be initialized to bind the local address and port.

There are two ways to install the server

The first way: use npm tool

Use the command npm install -g appium to install, but this installation method is relatively slow (I did not install successfully in this method, maybe the network speed was not good, and some errors were reported, which was embarrassing)

Second: Install the desktop version

This installation method is relatively fast, but downloading the installation package is also relatively slow. At least there were no problems with the installation.

download link

https://bitbucket.org/appium/appium.app/downloads/ (modify at: 2019.08.12-Do not use this address. I later discovered that the version inside is not the latest, but a very old version. For later use Locating the toast in the app will fail)

https://github.com/appium/appium-desktop/releases  (This is the address of the official website, just click the picture below to download the latest installation)

After the download is complete, double-click to install

I won’t describe the installation process here. It’s the same fool-proof installation. The default installation directory is: C:\Users\v-xug\AppData\Local\Programs\Appium

 

Configure environment variables

Add node_modules\.bin in the appium installation directory to the system environment variables (see the addition later)

Note: The old version has this directory, but I haven’t found this directory in the new version, so there is no need to configure environment variables -modify at: 2019.08.12

After the installation is completed, the appium program on the desktop can be successfully opened, indicating that there is no problem with the installation process for the time being.

 

Install Android SDK

Download SDK and install

Download address:  AndroidDevTools - Android development tools Android SDK download Android Studio download Gradle download SDK Tools download

After the download is complete, just double-click to install it.

After the installation is complete, find your installation directory and find the SDK-manager tool and double-click to open it.

 

Choose the corresponding sdk build-tools, Android SDK Platform-tools and api according to your needs. The api I chose is API 22 (5.1.1) version.

Android SDK Platform-tools, SDK build-tools I download and install the latest versions directly here. If the version you download is relatively low, you may not be able to connect to the emulator or real machine later.

Click [Install packages] in the picture above, the following page will pop up, click Accept License to install, and wait for all packages to be installed (it takes a long time, please be patient)

Configure environment variables

Create new system variables

 

ANDROID_HOME=D:\Program Files\Android\android-sdk variables and values ​​(SDK installation directory)

Add system variables

Add platform-tools and tools to the system environment variables. Use semicolons to separate the variable values ​​(paths). The two variable values ​​​​are: %ANDROID_HOME%\platform-tools; %ANDROID_HOME%\tools; or directly add absolute path

 

After configuring the environment variables, we can use the adb command

Install Appium Client

We use python to develop appium's automated test scripts, which must be inseparable from some of appium's api libraries, so the appium client here is the library used by python code to connect to the appium server and operate the app

Installing appium client is very simple. As long as you have configured the python environment, you can directly use pip to install it. cmd execute pipi install Appium-Python-Client to complete the installation. Enter the following command without an error, which means the installation has been successful.

 

environmental inspection

Note: Here I only found the appium-doctor tool in the old version of appium, but not in the new version. What should I do?

Open CMD and execute the command npm install -g appium-doctor to install appium-doctor

 

Now we can use the appium-doctor command to check whether there are any problems with the entire environment.

cmd executes the appium-doctor command. If your output information is the same as mine, congratulations on successfully setting up the environment.

Install emulator

All environments have been installed. The next step is to connect to the mobile phone simulator or real machine. I am using the Yeshen simulator here. Download address: Yeshen Android simulator - Android simulator PC version download_Android mobile game simulator _Mobile phone simulator_Official website

 

Install directly after the download is completed. After the installation is completed, two icons will be generated on the desktop, Ye God Simulator and Ye God Multi-Opener.

Connect emulator

Turn on the developer mode of the emulator

Click on the settings of the emulator - click on About Tablet - click on the version number (you will be prompted to click several times to open the developer mode)

Open the CMD terminal, switch the working directory of cmd to the bin directory of the Yeshen Simulator installation directory (or you can add this directory to the environment variable, but it is best not to add it to the environment variable, because there is also a directory in the bin directory adb.exe will conflict with adb.exe in the Android SDK), execute the command nox_adb.exe connect 127.0.0.1:62001 (this port number is different for different emulators)

If a failure message similar to: abd server version(40) doesn't match this client (36) is prompted when executing the command, it means that your server (adb (nox_adb.exe) of the Night God simulator) and client (Android SDK adb) version in does not correspond

Check version

cmd enter adb version to view the client version

 

cmd to switch to the bin directory of the Yeshen installation directory and execute nox_adb.exe version

My version is the same, yours may be two different version numbers. You need to copy the adb in the Android SDK to the bin directory under the Nox emulator installation directory, and rename it to nox_adb.exe and replace the original one. That’s it

Connect emulator

Next we can test whether the connection is normal, enter the command nox_adb.exe connect 127.0.0.1:62001 (note here the directory where the command is executed, which should be the bin directory of the Yeshen simulator installation directory)

 

After seeing the above prompt, enter the command adb devices again (note: do not continue to enter the command in the above directory, because there is also an adb.exe under bin. If you are still executing the adb command in this directory, then use It is not adb in the Android SDK, so switch to any other directory to execute the command)

If you see the information in the picture above, it means that the simulator has been successfully connected. This only means that the Android development environment is OK, but it may not be able to control the simulator normally during automation.

Test environment verification

 

Next, we write a simple code program to verify whether the program can successfully drive the simulator to open the specified app. If no error is reported, then the entire appnium automated testing environment has been completed so far.

Open appium, start the server, and keep the emulator open

test code

Write the following test code

"""
------------------------------------
@Time : 2019/7/30 19:47
@Auth : linux超
@File : appium_test.py
@IDE  : PyCharm
@Motto: Real warriors,dare to face the bleak warning,dare to face the incisive error!
@QQ   : [email protected]
@GROUP: 878565760
------------------------------------
"""
from appium import webdriver
 
 
desired = {
    "platformName": "Android",
    "platformVersion": "5.1.1",
    "deviceName": "e9b768eb7d2a",
    "appPackage": "com.xxzb.fenwoo",
    "appActivity": "com.xxzb.fenwoo.activity.addition.WelcomeActivity"
}
 
driver = webdriver.Remote(
    command_executor="http://127.0.0.1:4723/wd/hub",
    desired_capabilities=desired)

 

The desired_capabilities parameter of the above code will not be introduced for the time being.

output

The corresponding app is successfully opened, which means that there are no problems in the entire environment. Then we can happily start our app automated testing.

Summarize

Finally, let’s review the points that need to be paid attention to when setting up the environment.

1. If you are prompted that .net framework 4.5 is missing when installing appium, then download and install it first, and then install appium https://www.microsoft.com/zh-cn/download/details.aspx?id=30653

2. Download the latest appium to prevent the app from being unable to locate its toast.

3. Note that the version of adb in the Android SDK and the version of nox_adb in the emulator need to be the same.

4. When downloading the Andorid SDK, be sure to install the latest platform-tools to prevent unexpected errors (cannot find the adb command, etc.) when connecting to the emulator or real device later.

Thank you to everyone who reads my article carefully. There is always a courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly:


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. I hope it can also help you! Anyone in need Partners can click on the small card below to receive it

Guess you like

Origin blog.csdn.net/chengxuyuznguoke/article/details/132699688