[python+appium] automated testing

The python+appium automated testing series is coming to an end, let's make a summary of this blog.

First of all, I want to explain that APP automation testing may not be used by many companies, but it is also required by most automation test engineers and senior test engineer job recruitment information. Therefore, in order to get better treatment, we still need to spend time to master it. After all, who Nor will it be hard for money.

Next, let’s summarize the ideas of APP UI automation testing.

1. Development language selection

Programming languages ​​commonly used for automated testing include: Python, Java, Javascript, Ruby, C#, PHP, etc. Generally, we will choose a programming language we are familiar with to write automated scripts, but for children's shoes with basically zero programming foundation (or children's shoes that focus on automated testing), it is recommended to learn to use Python.

Compared with other languages, Python has the following advantages for automated testing:

  • For beginners, Python syntax is concise, highly readable, and easy to learn

  • There are powerful third-party libraries, making scripting more efficient

  • The Pytest automated testing framework in Python is currently one of the most popular testing frameworks

2. Selection of UI testing framework

After choosing the programming language, we need to choose the UI testing framework. At present, the more mainstream or widely used APP UI automation testing frameworks include Appium, Airtest, etc.

1, Appius

  • open source

  • Appium server supports running on Windows, macOS, Linux

  • Support multiple mainstream programming languages, such as Python, Java, Javascript, Ruby, etc.

  • Support Android, ios, H5 automated testing (integrated UiAutomator, UiAutomation framework)

  • The environment is more complex

2、Air test

  • Developed by Netease ( official document ), only supports python language

  • Provides a powerful IDE that integrates the two testing frameworks of Airtest and Poco, which is friendly to novices

  • Integrate image recognition-based UI automation testing framework airtest, even if you don't know code, you can write automation scripts

  • Cross-platform, automated testing of Windows, Android and iOS application software

  • Friendly to game testing

  • Airtest and Poco are essentially two third-party libraries of python, and the test environment is not as complicated as Appium

3. Select the frame

Choose the appropriate frame according to the actual situation.

The following situations can give priority to NetEase's Airtest ( Airtest official website ):

  • No programming basis

  • game testing

  • The test scenario is relatively simple (Appium is relatively cumbersome)

  • Alipay applet automation (bloggers currently use Airtest integrated Poco framework for Alipay applet automation testing)

It is recommended to choose Appium in the following situations:

  • The test scenario is more complicated (for example, batch testing of multiple mobile phones is required)

  • The test scripting language is not Python (Airtest currently only supports Python)

3. Selection of unit testing framework

Different from the UI test framework mentioned above, the unit test framework is used to load test cases, execute test cases, assert, output test results, etc.

Different development languages ​​have their own corresponding unit testing frameworks, such as Java has JUnit, TestNG, Robot, etc., and Python has unittest, pytest, etc. Bloggers mainly use Python for automated testing, so here we only explain the Python unit testing framework.

Python's mainstream unit testing framework:

  • unittest, the unit testing framework that comes with Python

  • pytest, based on unittest development, easy to use, more detailed information, many plug-ins

  • robot framework, a keyword-driven test framework based on Python, has an interface, comes with reports and logs, complete functions, clear and beautiful

It is strongly recommended to use pytest here, which is powerful and easy to use. The official documentation is in English. For Chinese, please refer to the Pytest manual .

Fourth, test environment construction

1. Test computer selection

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

2. Test mobile phone selection

At the beginning of the test script debugging, you can choose the emulator, and the Android emulator can choose Gernymotion, Ye Shen emulator

After the development of the entire test project is completed, it is recommended to replace it with a real machine to run the automation script, which is closer to the real user usage scenario.

3. Development language environment

It is recommended to install a version above python 3, and the official has stopped updating and maintaining the python2 version.

4. Build the UI automation test framework environment

Building Appium in the windows environment, and building Appium in the Mac environment is a bit more complicated, and I will write a blog to share it later.

If you choose the Airtest framework, please refer to the official website.

Five, script writing

1. Write a test demo

In order to verify whether the entire test environment is successfully built and whether it can run common cases, generally we need to write a simple test script and execute it. If it passes, it means that the entire environment is successfully built.

2. Determine the directory structure

It is recommended to use the Page Object design pattern to develop APP UI automation test projects.

3. Select Test Report

Different development languages ​​and different unit test frameworks can choose different test reports. In python, the unittest framework uses HTMLTestRunner or BSTestrunner to generate test reports. The Pytest framework uses pytest-html to generate reports or customize test reports through allure.

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

Six, Jenkins integration

After writing the entire app UI automation test project according to the above steps and running it stably for a period of time, you can consider integrating Jenkins

Seven, summary

Summary APP UI automation can use the following implementation methods:

1, python + app + 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: The complete software testing video learning tutorial below has been sorted out and uploaded. If you need it, you can get it for free [guaranteed 100% free]

 These materials should be relatively complete for friends who do [software testing]. This kind of learning materials also accompanied me through the most difficult journey, and I hope it can help you too! Everything should be done as early as possible, especially in the technology industry, we must improve our technical skills.

Guess you like

Origin blog.csdn.net/xiao1542/article/details/130140143