Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate Allure Test report on Jenkins by Python+Pytest Framework

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

It is believed that many inexperienced people don't know what to do about how to generate the Allure test report on Jenkins. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

After the automated test execution, generating a beautiful and generous test report is also the most important part of the testing process. The test report directly reflects the problems found in the testing process, and the analysis of the test report is the most important means to solve the problem. So what should a professional test report look like? Don't talk too much nonsense, go straight to the picture:

In the above test report, the overall display in Chinese, easy to read; the left navigation bar contains an overview, classification, test case list, charts and other modules; the overview page on the right contains the number of use cases, success rate, historical trend chart, use case classification and other tables; the page layout is simple and generous.

So how do you generate such a test report?

The first step is to install Python dependent libraries. Choose one of two ways. The first is in the dos window, enter the following three commands:

Pip3 install pytest

Pip3 install allure-python

Pip3 install allure-python-commons

The second method is to open Pycharm, click File, click Settings, select project interpreter, click the upper right corner + plus button, search and select pytest, click install package; search allure, select allure-python and allure-python-commons, respectively, and click install package. As shown in the following picture.

In the second step, after installing the dependent library, download and extract the allure command line tool for the following steps to execute the allure command, download address 1: https://pan.baidu.com/s/1YkgYpvfmH_I26ZPAJ1OF0A; download address 2: https://github.com/allure-framework/allure-pytest. Set the extracted allure folder to the environment variable. Add allure to the environment variable PATH (\ installation path\ allure-commandline\ bin).

The third step is to confirm that allure is installed successfully, type: allure-- version on the command line, and you can display allure installation version 2.12.1. If you report an error, it may be due to the fact that jdk1.8 is not installed on your computer, so just install a jdk1.8 at this time.

The fourth step is to write automated test scripts through pytest, as shown in the following figure. Writing pytest test cases is very simple, just follow the following rules:

The test file begins with test_

The test class begins with Test

The test function begins with test_

Step 5, execute the test case. Click Terminal; at the bottom of Pycharm or open the dos window, switch to the current project folder, and execute the command pytest-s-Q. Terminal should display the print results as follows.

Step 6, in order to enrich the content of the test report, you can use the method of step 5 to create more test cases. As shown in the figure below, you can also put use cases in multiple packages.

Step 7, after creating the test case, execute the command in Terminal: pytest-s-Q-- alluredir allure-xml. The test case will be run at this point. -s means to allow the terminal to output results when the test is running,-Q means to simplify the output results, and-alluredir means to save the generated intermediate results to the allure-xml folder.

Step 8, wait for the test case to be executed. Continue to execute the command in Terminal: allure generate allure-xml-o allure-report-- clean. This generates a test report in the allure-report folder based on the intermediate results in the allure-xml folder.

Step 9, right-click the index.html file in the allure-report folder, select open in browser, and click on a browser, such as chrome.

Step 10, when a beautiful test report will be displayed as follows, give it a try.

Advanced article-customized report

At this point, click "function" in the left navigation bar, and after expansion, the test results are displayed as follows:

Here, we can see that all test cases are displayed directly as method names, which is not readable. We can rename these test cases in Chinese and classify them through the decorator that comes with allure. As shown below:

To implement the style shown above: allure provides the following decorators. @ allure.feature ('foreground subsystem') represents the first layer grouping, which is generally used to indicate which module the test case belongs to. @ allure.story ('register functionality') indicates the second layer grouping, which is generally used to indicate which function the test case belongs to. @ allure.title ('normal registration test') is used to represent the title of the test case. Allure.description ('enter the correct user information and sign up for an account') is used to display the description information in the test case. The specific code is shown below:

In addition to the above decorators, almost all elements of manual test cases are supported in the allure test report, such as operating procedures, pre-conditions, post-actions, attachment screenshots, and so on. You can try it yourself, and we'll talk about other elements later.

Advanced article-continuous integration

In enterprise applications, automated tests often need to be performed frequently, such as every other hour. After the execution is complete, you should send an email to remind tester,tester that you only need to open the email to see the generated test report. How do you do this?

The first step, prepare the environment, you should have installed jdk, we download the latest tomcat9,Jenkins official website from the Tomcat official website download the latest war package; you can also download from the URL I shared to you: https://pan.baidu.com/s/1YkgYpvfmH_I26ZPAJ1OF0A.

1. Install jdk

two。 Decompress tomcat

3. Copy jenkins.war to the webapps directory of tomcat

4. Double-click to open startup.bat under the bin directory, which will open a dos window. Be careful never to close this window, or you will not be able to visit the jenkins website.

5. Wait 1 minute or so, open the browser, enter the URL http://localhost:8088/jenkins/, and refresh it a few more times until you see the following picture

6. According to the prompts on the web page, use notepad to open the file initialAdminpassword in the prompt C:\ Users\. Jenkins\ secrets folder.

7. Copy the contents of the file to the Administrator password input box

8. Click the next step

9. Select suggested jenkins plugin (install the recommended plug-in) on the custom jenkins page.

10. After all the plug-ins have been downloaded, set the user name and password.

11. Log in to the main interface.

Second, after entering the jenkins main interface, let's create the first jenkins task.

1. Click "New" on the home page

two。 Choose a free-style software project

3. Click "Advanced" in the general configuration, select "Custom Workspace" and set it to your project path, for example, my project is in this path C:\ Users\ 51Testing\ PycharmProjects\ changcheng.

4. In the build trigger, select the window batch program, and in the jmeter input box, enter pytest-s-Q.

5. Check timing build and enter 0 18 15 6 1, indicating that the test case will be executed at 18:00 on Monday, June 15, where you can write five numbers, each separated by a space. They are minutes, hours, date, month and day of the week. In addition to numbers, time can also be represented by special symbols: asterisks * for all valid values, horizontal lines-from what to what, division / interval, and comma for enumeration. For example, to execute it at 18:00 every night, you could write 0 18 *. You can try it by yourself and set various time intervals.

The third step is the Jenkins integration allure test report.

1. Install the Allure plug-in first. Open Jenkins and click "system Management" on the home page.

two。 Select plug-in Management.

3. Select 'optional plug-in', enter Allure in the search input box, and the name will be called Allure. When installed, the name will become Allure Jenkins Plugin.

On the 4.jenkins configuration page, select Global tool configuration.

5. Drop down to the last item on the global tool configuration page, and you will see the 'Allure Commandline'' item. Click the figure below and save it.

6. In the build trigger, select the window batch program, and in the jmeter input box, change the previously entered pytest-s-Q to call pytest-s-Q-- alluredir. / allure-xml.

7. Select allure report in the 'post-build action' (Post-build Actions) and enter the Path name allure-xml, where the path name means that this folder is generated under the project root, and the folder is used to hold the intermediate test results before the html report is generated.

8. Click 'Save' and click 'build now'.

9. After running, click 'Allure Report', to show the figure as follows:

This completes the integrated configuration of pytest + allure + jenkins.

After reading the above, have you mastered how the Python+Pytest framework generates Allure test reports on Jenkins? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report