First of all, I want to explain that APP automated testing may not be used by many companies, but it is also required by the recruitment information of most automation test engineers and senior test engineers, so in order to better treatment, we still need to spend time to master, after all, no one will not go with money.

Next, let’s summarize the idea of APP UI automated testing.

First, development language selection

Programming languages commonly used for automated testing are: Python, Java, Javascript, Ruby, C#, PHP, etc. We usually choose a programming language we are familiar with to write automated scripts, but Python is recommended for those with minimal programming background (or those who specialize in automated testing).

Python has the following advantages over other languages for automated testing:

For starters, Python syntax is concise, readable, and easy to learn

Powerful third-party libraries make scripting more efficient

The Pytest automation framework in Python is one of the most popular testing frameworks out there

Second, test framework selection

After selecting the programming language, we need to select the UI testing framework. At present, the more mainstream or widely used APP UI automation test frameworks include Appium, Airtest and so on.

1, Appium

Open source

Appium Server runs on Windows, macOS, and Linux

Support for many major programming languages, such as Python, Java, Javascript, Ruby, etc

Support Android, ios, H5 automation testing (integrated with UiAutomator, UiAutomation framework)

Setting up the environment is complicated

2, Airtest

It is developed by netease (official document) and supports only Python

A powerful IDE that integrates both Airtest and Poco testing frameworks and is very novice friendly

Integration of image recognition based UI automation test framework AirTest, even if you do not know the code can write automated scripts

Cross-platform, automated testing of Windows, Android and iOS applications

Playtest friendly

Airtest and Poco are essentially python third party libraries, and the test environment setup is not as complex as Appium

3. Choose the frame

Choose the appropriate frame according to the actual situation.

Netease Airtest (the official website of Airtest) is preferred in the following cases:

No programming background

Video game testing

Single test scenario (Appium is relatively bulky)

Alipay applet automation (Bloggers currently use Poco framework integrated with Airtest to automate alipay applet testing)

Appium is recommended for the following situations:

Complex test scenarios (such as batch test of multiple mobile phones)

Test scripting language not Python (Airtest currently only supports Python)

Third, unit test framework selection

Unlike the UI testing framework mentioned above, the unit testing framework is used to load test cases, execute test cases, assert, output test results, and so on.

Different development languages have their own unittest frameworks, such as Java JUnit, TestNG, Robot, Python unittest, pytest, etc. Bloggers mainly use Python for automated testing, so this is only for the Python unit testing framework.

The main python unit testing frameworks:

Unittest, Python’s built-in unit testing framework

Pytest, developed based on UnitTest, easy to use, more detailed information, many plug-ins

Robot Framework, based on Python keyword driven test framework, has an interface, built-in report and log, complete functionality, clear and beautiful

Pytest is highly recommended because it is powerful and easy to use. The official documentation is in English. For Chinese, please refer to the PyTest user manual.

Fourth, test environment construction

1. Test computer selection

If possible, it is recommended to use a Mac machine specifically for UI automation testing, as ios app UI automation can only be done on a Mac machine.

2. Test your phone choice

At the beginning of the test script debugging, you can choose emulators. Android emulators can choose Gernymotion and Nighthorse emulators. For details, refer to the blog Android emulators

After the development of the whole test project is completed, it is suggested to switch to the automatic script of the real machine, which is closer to the real user use scenario.

3. Develop the language environment

Python 3 or later is recommended. Official maintenance for Python 2 has been stopped.

4. UI automatic test framework environment construction

Please refer to the blog to build Appium in Windows environment. It is slightly more complicated to build Appium in Mac environment. I will write a blog to share in the future.

For Airtest framework, please refer to the official website.

Fifth, scripting

1. Write test demo

In order to verify whether the whole test environment is set up successfully and whether it can run the general example, we generally need to write a simple test script and execute it first. If it passes, the whole environment is set up successfully.

2. Determine the directory structure

Page Object design pattern is recommended for developing APP UI automation test projects. Please refer to Page Object design Pattern on the blog.

3. Select the test report

Different development languages and unit test frameworks can choose different test reports. In python, the unittest framework uses HTMLTestRunner or BSTestrunner to generate test reports. See the unittest unittest framework blog. The Pytest framework uses Pytest-HTML to generate reports or custom test reports through Allure.

After the above steps are complete, continue to add new test cases to the test project.

Six, Jenkins integration

After the completion of the entire APP UI automated test project according to the above steps and stable operation for a period of time, Jenkins integration can be considered. Please refer to Jenkins Integration Appium Automated Test (Windows) or remote Jenkins to add Mac nodes.

Seven,

To sum up, APP UI automation can be implemented in the following ways:

Python + appium + unittest + HTMLTestRunner

2, python + appium + pytest + pytest-html/allure

3, Python + Airtest (AirtestIDE)

4, Python + Poco + pytest + pytest-html/allure

You can choose according to the actual situation.

Finally: [May give you some help]

These materials, for [software testing] friends should be the most comprehensive and complete preparation warehouse, this warehouse also accompany tens of thousands of test engineers through the most difficult journey, I hope to help you! Follow my wechat public number [software test small DAO] free access ~

My learning exchange group: 644956177 group of technical cattle to exchange and share ~

If my blog is helpful to you, if you like my blog content, please “like” “comment” “favorites” one key three even oh!