Appium automated testing complete project

 foreword

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. Using webdriver to drive ios and android applications, the first task in order to learn app automation testing must be to build Test the development environment, so here is a complete process of building the Appium automated test environment. The article is long and takes a certain amount of time. Please read it patiently. Please correct me if there are any mistakes in the article

Install Java JDK

You can see the JDK environment. I installed Jenkins before. Here you need to pay attention to install jdk 1.8 as much as possible to prevent the failure of linking to the phone later.

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 appium's interpreter

Node.js download link: Download | Node.js

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

After the download is complete, just double-click to install (fool-style installation), so I won’t talk about the specific steps. After installation, check whether the installation is successful

The cmd terminal enters the first command node -version and outputs 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 address and port of the machine, so is 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 tools

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

The second: install the desktop version

This installation method is relatively fast, but downloading the installation package is also relatively slow. Anyway, there is no problem with the installation

download link

https://bitbucket.org/appium/appium.app/downloads/ (modify at: 2019.08.12- this address is not used anymore, I later found out that the version inside is not the latest, it is a very old version, for later Locating the toast in the app will fail)

https://github.com/appium/appium-desktop/releases  (this is the address of the official website, just download the latest installation as shown below)

After the download is complete, double-click to install

I will not describe the installation process here, the same fool-like installation, the default installation directory: C:\Users\v-xug\AppData\Local\Programs\Appium

Configure environment variables

Add node_modules\.bin in the appium installation directory to the system environment variable (add it 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 complete, the appium program on the desktop can be successfully opened, indicating that there is no problem with the installation process

Install the 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

After the installation is complete, find your installation directory, 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, and the api I choose is API 22 (5.1.1) version

Android SDK Platform-tools, SDK build-tools I am directly downloading and installing the latest version here. If the version you downloaded is relatively low, you may not be able to link to the emulator or real device later.

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

Configure environment variables

New system variable

ANDROID_HOME=D:\Program Files\Android\android-sdk variable and value (SDK installation directory)

Add system variables

Add platform-tools and tools to the system environment variable. The variable values ​​(paths) are separated by semicolons. 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 appium's api library, so the appium client here is the library used by python code to connect to appium server and operate app

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

environmental inspection

Note: Here I only found the appium-doctor tool in the old version of appium, but not in the new version, so 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 is a problem with the entire environment

Cmd executes the appium-doctor command. If your output information is the same as mine, then congratulations on successfully building your environment.

Install the emulator

All the environments have been installed, and the next step is to link to the mobile phone simulator or the real machine. I am using the Night God Simulator here. The download address: Night God Android Simulator -Android Simulator PC Download_Android Mobile Game Simulator _Mobile phone simulator_official website

 

After the download is complete, install it directly. After the installation is complete, two icons will be generated on the desktop, the Yeghen Simulator and the Yeghen Multi-Opener

connect emulator

Enable developer mode on the emulator

Click on the settings of the emulator - click on the tablet - click on the version number (there will be a prompt 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 installation directory of the Yeshen Simulator (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 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 displayed when executing the command, it means that your server (adb (nox_adb.exe) of the Yeshen simulator) and client (Android SDK The adb) version does not correspond to

check version

cmd input adb version to view the client version

Switch to the bin directory of the Yeshen installation directory with cmd, and execute nox_adb.exe version

My version is the same, yours may have two different version numbers, you need to copy the adb in the Android SDK to the bin directory under the installation directory of the Night God emulator, and rename it to nox_adb.exe and replace the original can

connect emulator

Next, we can test whether the connection is normal, enter the command nox_adb.exe connect 127.0.0.1:62001 (here, pay attention to the directory where the command is executed, it should be in the bin directory of the installation directory of the Yeshen Simulator)

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 the bin, if you still execute 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 emulator has been successfully connected. This can only mean that the Android development environment is fine, but it may not be possible to control the emulator normally when performing 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, the entire appnium automated test 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 now

output

The corresponding app is successfully opened, indicating that there is no problem in the whole environment, and then we can happily start our app automation test

Summarize

Finally, review the points that need to be paid attention to in the process of building the environment

1. If it prompts that .net framework 4.5 is missing when installing appium, then download and install it first, and then install appium. Download Microsoft .NET Framework 4.5 from Official Microsoft Download Center

2. Download the latest appium to prevent the toast of the app from being unable to be located

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 when connecting to an emulator or a real device (the adb command cannot be found, etc.)

Guess you like

Origin blog.csdn.net/m0_68405758/article/details/130189197