Efficiency-oriented: Using ChatGPT and HttpRunner to implement agile automated testing (2) | JD Cloud Technology Team

1 Introduction

In the previous article: Using ChatGPT to Improve Test Work Efficiency - A New Tool for Test Engineers (1) , we mentioned how to generate single interface test cases through chatGPT, and then let chatGPT generate interface automation scripts based on the test cases. This article will explain in detail how our team uses the Httprunner framework to conduct automated interface testing when encountering business pain points. When I recently encountered chatGPT, how did I combine the two to achieve "agile" automated testing?

First of all, the pain point faced by business testing is that during the delivery process of commercial Devops products, there are various environments at different customer sites and within the company, as well as various domestic systems. Multiple customers are delivered in parallel, and multiple versions need to be carried out . Regression Testing. If the regression is manually performed by testers with limited human resources, the delivery may not be completed on time. How to quickly realize interface automation and assisted regression? After internal selection of the team, the HttpRunner framework was finally selected based on its speed, flexibility and ease of use. In the end, it was realized that in different customer site environments, when operation and maintenance personnel complete the environment deployment, they can quickly implement basic function regression testing, which greatly reduces the return time of testers.

Next, let’s talk in detail about how we use Httprunner to conduct automated interface testing through the three tools of “click”, “modify” and “check”. The point is to record the corresponding interface by performing business operations on the web front-end, and then output the automation script with a command. The change means that all repeated content that needs to be replaced needs to be changed in batches using scripts. Of course, variable extraction and assertions still require manual changes for each interface. Checking means running debugging to find errors and correct them. Compared with some interface testing tools or platforms that require manual input of a single interface, Httprunner is so easy, and there is no trouble! The following is an example of how to generate automated scripts through Httprunner in detail.

2. Move 1: Click a little

Now I will illustrate with a simple business scenario, where I want to automate the entire process of creating a team space, creating iterations, and creating cards in the team space module. First, you need to perform the corresponding operations on the Web side.

At the same time, you can also use packet capture tools such as Fiddler or the F12 function of the browser itself to capture the business process interface. Delete the secondary reserved core interfaces and export all interfaces into the har file createSpaceCardDemo.har. (Both packet capture tools and browsers can export)

Next, convert the har file into a py script through the tool command line of the Httprunner framework: h ar2case.exe createSpaceCardDemo.har . (Of course, it can also be in yml format. In comparison, py format is more concise and easy to read)



3. Move 2: Change it

The first round of running the command generates something like this: Through observation, it is found that the url, headers, cookies, request body and other information in the script will change according to different users in different environments, so parameterization is required.

After the second round of replacement of the "secret" script, it becomes like this: after extracting the url, headers, and cookies, the script is now very concise and clear.



Manual third-round replacement: Parameterize the input parameters to ensure that it can run every time. The return value field is extracted and spit out to the next result or other dependent scripts. Assertions make targeted judgments based on the business characteristics of each interface.



4. Move 3: Check it out

After the modification is completed, run the command hrun .\testcases\space\space\createSpaceCardDemo_test.py --html=reports\index.html to check the correctness of the script.

Doesn't it feel very simple? Easier than packing an elephant into a refrigerator.



Note: The early framework needs to be planned well, and the variable extraction function encapsulation needs to be done well. It is also necessary to consider business characteristics such as different environments, different deployment methods, interface prefix changes, etc. This will make the later automation scripts simpler.

5. ChatGPT generates use cases

The above is the basic process for Httprunner to implement interface automation. But if you want to test the abnormal scenario of the core interface, the front end cannot be clicked and the script will be automatically generated after recording. If you write it manually, it will greatly increase the tester's workload. Now chatGPT is on the scene. The initial idea is to enter parameters and constraints for the chatGPT interface. Then let chatGPT generate test cases for abnormal scenarios of the interface. Let chatGPT convert our test cases into the automation scripts we need. It’s so simple, so easy! If something is wrong, just ask chatGPT to correct it.

After several rounds of modifications, the final use case generated by chatGPT is as follows:



6. ChatGPT generates Httprunner script

Next, feed the generated test cases to chatGPT and let it automatically generate interface automation scripts. First train to generate an interface automation script that meets the expectations based on a use case.

Next, "feed" all the generated test cases to chatGPT, and let it generate all test cases into the Httprunner interface automation script. After running the command hrun .\testcases\space\exceptions\createSpaceException_P01_test.py, it was found to be successful directly. Of course, the current assertions are only status code assertions, and assertions need to be made for message bodies in different scenarios.



7. Summary

The above is the spark when chatGPT collides with Httprunner ( official website link ). Httprunner is already very simple for writing interface use cases, and its functionality has been greatly enhanced after encountering chatGPT. For interfaces that can be recorded, we can write a use case for a scenario with just three steps, a few clicks, a few changes, and a few searches. For single interfaces that cannot be recorded, you can use chatGPT to generate use cases, and then let chatGPT automatically generate automation scripts. Of course, the current application is still a relatively simple interface. In the early stage, it may be like a child learning to walk, but I believe that with continuous exploration and learning, chatGPT will become more and more proficient as it develops. Because a single spark can start a prairie fire.

 

Author: Zhang Xinglei of JD Technology

Source: JD Cloud Developer Community Please indicate the source when reprinting

The author of the open source framework NanUI switched to selling steel, and the project was suspended. The first free list in the Apple App Store is the pornographic software TypeScript. It has just become popular, why do the big guys start to abandon it? TIOBE October list: Java has the biggest decline, C# is approaching Java Rust 1.73.0 Released A man was encouraged by his AI girlfriend to assassinate the Queen of England and was sentenced to nine years in prison Qt 6.6 officially released Reuters: RISC-V technology becomes the key to the Sino-US technology war New battlefield RISC-V: Not controlled by any single company or country, Lenovo plans to launch Android PC
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4090830/blog/10117347