2023 The best Python automation test in the whole network

1 Overview

1.1 python automation

What is python automation? The Python automated testing I understand is a process of converting previous human tests into machine tests. Automated testing is a way to get feedback on failures faster than manual testing.
Automated testing is a way of quality assurance, and the most important thing is to make a high-quality product. Most of the testing work is constantly balancing the proportion and depth of quality, efficiency, and driving business. According to different business stages, different goals, and current key event drivers, constantly adjust strategies and tactics in terms of quality, efficiency, and business drivers.

At the same time, I have also prepared a software testing video tutorial for everyone, just below, you can watch it directly if you need it, or you can directly click on the small card at the end of the article to get the information document for free

Watch free video tutorials at:

A very perverted but allows you to quickly master automated testing (Web/interface automation/APP/Selenium/performance testing, etc.) Automation/APP/Selenium/Performance testing, etc.) magical methods totaling 100 videos, including: [Automated testing] How to design interface test cases? 、【Automated Testing】Automated testing framework design ideas, a full set of software testing materials and learning routes, etc., for more exciting videos from the UP master, please pay attention to the UP account. https://www.bilibili.com/video/BV1hj411z71j/?spm_id_from=333.999.0.0&vd_source=74d0257ec7066cc4f9013524f0bb7013

1.2 Email push

After the python automated testers complete the automated testing work of the project, they need to send the automated test report results to the corresponding person in charge for review. If the tester needs to manually forward the test report to the person in charge after each automated test is executed, if some unexpected event occurs during the transfer process, the tester forgets to forward the test report to the person in charge, and the person in charge will delay The efficiency of not being able to receive the work content you want is very low for people engaged in the software industry. Therefore, the function of python automated mail push was born.

Mail transmission is generally through the SMTP protocol, and the SMTP protocol is a set of rules for transmitting mail from source addresses to destination addresses. In python, the SMTP protocol is simply encapsulated through the smtplib module, which realizes a convenient way to send emails, and sends emails through the sendmail method of SMTP. This is a relatively common mail transmission method, but this time I will introduce to you a mail push method encapsulated in the unittestreport package. Compared with the traditional method, this email push method is more concise and easy to understand, and is suitable for scripts using the unittest testing framework. By using the python automated email push function, after the automated test results are generated, an email can be automatically sent to the mailbox of the corresponding person in charge, which improves work efficiency.

1.3 Enterprise WeChat push

What is Enterprise WeChat Push? Enterprise WeChat push means that automated testers push the test result information to the enterprise WeChat test group where they work after completing the automated testing work, so that relevant personnel can see the execution status of project automated testing. This is also a timely automated testing. A method of result sharing.

1.4 Jenkins automated deployment

What is Jenkins? Jenkins is an open source software project. It is a continuous integration tool developed based on Java. It is used to monitor continuous and repetitive work. It aims to provide an open and easy-to-use software platform to make continuous integration of software possible.

So what is Jenkins automated deployment? Since the feature of the automated testing work is to automate the testing of the system functions in each version iteration, so as to find out the problems that may occur in the system during the version iteration process, this kind of work has a strong repeatability. If each version iteration requires testers to manually execute automation scripts, it is not a cool thing for us working in the software industry, and it is also cumbersome. Since the role of Jenkins is to monitor continuous and repetitive work, we deploy the completed automated test script to Jenkins and set the corresponding timer, so that Jenkins can automatically execute our test according to the prescribed procedures and time. Automate test scripts to increase tester productivity.

2. Project realization

2.1 python scripts

This time we introduce the automated test script based on the addition, deletion, modification and query function of the SaaS background management platform account. The python framework used by the script is the unittest framework, and the ui element positioning uses the XPath method. Then use the mail push and corporate WeChat push methods in the unittestreport package to conveniently push the test report to the mailbox of the person in charge and the corresponding corporate WeChat group. The script implementation method will be introduced in detail below:

Create a .py file in the Pycharm compiler, and then import the file packages that our script needs to use at the very beginning of the py file. Since our automated tests are based on the selenium framework and use the UI element positioning method, we need to import the selenium package. The automation framework used is unittest, so import the unittest package. When the automation script is running, we need to make the script pause during the running process for easy observation, so we need to import the time package.

Put the browser driver, maximize the browser, implicitly wait, and open the test URL in the setup function, because the function of the setup function is executed once when calling each new function, if this function is used, it will cause the script There is a problem with the logic of element positioning, which causes the script to fail to run. So what we need is to call the setup function once before the automation script runs, so we use the setUpClass function, which will only run once during the entire automation script running process, which meets our expectations. But because the setUpClass function is a class function, if we write it in a class, it will also cause the script to run incorrectly, so we need to add a @classmethod in front of the function to declare that this is a class function. Similarly, after the script finishes running, we need to close the automatically opened webpage. We write the function of closing the webpage in the tearDownClass class function.

insert image description here

Then we code the SaaS login page, because we use the unittest framework, so the created scene function must start with test, and the function of the login interface is test_01_login. Then, the login automation is realized through the positioning of UI elements, and the same is true for the subsequent addition, deletion, modification, and query environment code writing, so I won’t go into details here.

insert image description here

2.2 Running the script

After the automation script of SaaS background management is written, we need to write a running file to execute this script, which we call a runner file. Because we are based on the automation script written by the unittest framework, in order to facilitate and generate an automated test report with a beautiful interface, we choose the unittestreport data package here, which encapsulates a number of beautiful test report templates for testers to choose.

insert image description here

In order to identify the version of the generated test report, we use the time.strftime() method to add a timestamp to the test report. Then define a suite for temporary storage of all our test scenario scripts. So how do we get the scene scripts we wrote before? One method is to import the py file of the previously written scene script into the current file through import, but this method is cumbersome. If there are many py files, our work efficiency will become very low. So here we introduce another method, which is
to read the location of our file through the unittest.defaultTestLoader.discover() method. If the script is running locally, we can import the absolute path of the script, but if we require the script to run in other environments, we cannot read the absolute path of the script, but change it to a relative path. Because we need to deploy the script to gitlab later, what we write here is to read the relative path of the script.

How to generate a good-looking automated test report? Next we will use the TestRunner() method in unittestreport. unittestreport rewrites and encapsulates the TestRunner() method in python, we only need to call its TestRunner() to use it. The explanation of each parameter in TestRunner() is commented in the code, so I won't go into details here.

After the template parameters are filled in, the automated test report we need can be generated by calling the run method to execute the current script using runner.run().

About automated testing technology reserves

To learn Python automated testing, you still need a learning plan. Finally, I will share a piece of information with you, and give some help to those who want to learn Python automated testing!

☑ 215 episodes - zero basics to proficient in a full set of automated testing video courses
☑ [courseware + source code] - complete supporting tutorials
☑ 18 sets - source code of actual test projects
☑ 37 sets - test tool software package
☑ 268 - real interview questions
☑ 200 Templates-interview resume template, test plan template, software test report template, test analysis template, test plan template, performance test report, performance test report, performance test script use case template (complete information)

1. Fundamentals of software testing

Understand the basic skills of testing, master the use of mainstream defect management tools, and be proficient in the operation and maintenance of test environments

insert image description here

2. Necessary knowledge of Linux

As the most popular software environment system, Linux must be mastered. The current recruitment requirements require Linux capabilities.

insert image description here

3. Shell script

Master Shell script: including Shell basics and application, Shell logic control, Shell logic function

insert image description here

4. Principles of Internet Programs

The only way to automate: the basic knowledge of front-end development and the necessary knowledge of the Internet network 4. Principles of Internet programs

insert image description here

5. MySQL database

Software test engineers must have MySQL database knowledge, not just the basic "addition, deletion, modification and query".

insert image description here

6. Packet capture tool

Fiddler, Wireshark, Sniffer, Tcpdump and various packet capture tools are suitable for various projects, there is always one that suits you

insert image description here

7. Interface testing tools

Interface testing artifact, a powerful tool you can't avoid: Jmeter. Small and flexible: Postman

insert image description here

8. Web automation test Java&Python

Understand the purpose of automation, master TestNG&unittest automation framework, and assertion and log processing

insert image description here

9. Interface and mobile terminal automation

Professional interface calling and testing solutions. Build a complete web and interface automation framework, and use Appium as a whole

insert image description here

10. Agile testing & TestOps construction

Unveiling the mystery of TestOps, continuous integration of the Jenkins framework is familiar

insert image description here

11. Performance Test & Security Test

The other side of software testing: performance testing and security testing, choose a direction and work hard to climb the pit!

insert image description here

Reasonably use every minute and every second of time to learn to improve yourself, and don't use the reason of "no time" to cover up your ideological laziness! While you are young, work hard and give an explanation to your future self!

 

Guess you like

Origin blog.csdn.net/HUA1211/article/details/132299629