Skip to content

Report guidelines

Foreword

By reading this tutorial, you will learn about the following:

  • Page content of the new report
  • Feature introduction of the new report
  • How to generate a report

Page content of the new report

image

The report is mainly divided into two parts:
①In the top half of the report, you can see some information related to the report, such as the name of the report, the author, the report description (which can be customized, refer to the below content), the quick view, and so on.Click on any of the quick views and the corresponding test information will be displayed below.
②The second half of the report shows each test action and its execution in detail. Click the test action on the left side, and the details of the corresponding action execution result will be displayed on the right side. And we can also filter different execution results on the right side.

image

Feature introduction of the new report

Customize partial report information

If the following content is written in the script, it will be displayed in the report: - __author__ Corresponding to the author of the script - __title__ Corresponding to the title of the script - __desc__ You can write a long script description that will be displayed on the page. If it exceeds a certain number of lines, it will be automatically folded.

image

image

image

If you want to get the corresponding information in the script separately, you can use the command line: airtest info + script path. And you can get the script information parsed by airtest, similar to the following return value:

>airtest info untitled.air
{"name": "untitled.air", "path": "untitled.air", "author": "user", "title": "title of the script", "desc": "Description of the case"}

The assertion name in the step navigation shows the msg entered by the user

image

Add view context function in the step navigation

After filtering some test actions, if you want to view the context of a test action, you can click the "eye" icon to the right of the test action to locate the context of the test action in all test actions.

image

Add image thumbnail and thumbnail positioning function

Click on a different thumbnail to display the execution of the corresponding step.

image

Fix the case where the report content is empty after opening the report page in some browsers

At present, we have fixed the case where the report content is empty after opening the report page in some browsers. And we will continue to fix it later, so stay tuned.

How to generate a report

Click the Generate Report button in the IDE to generate a report.

After running the script, you can immediately see whether the current script succeeds or fails in the log window, but you cannot see more detailed and intuitive execution results.In AirtestIDE, you can click the "View Report" button on the upper icon menu, the shortcut key is Ctrl+L, and the report page will be opened automatically in the default browser later:

image

In addition, we can right-click on the script title on AirtestIDE and select "Open Report" to open the folder where the log is located.

image

Use the command line to generate a report

The process that our script runs is a separate step from the report generation process, so we can run the script first with the airtest run directive:

 # Run the script untitled.air with airtest
 # Following the airtest run is the path to the script file.
 >airtest run untitled.air

It is worth noting that if the airtest run directive does not specify --log log/, the generated log content will be placed in the execution directory of the current command line; if the --log parameter is specified, the log content and the screenshot will be placed in the specified directory.

Then we can run the airtest report command to generate a report in HTML format:

# The simplest command line, the log file is in the same folder as the script file
# Run the following command to generate a log.html in the current directory
>airtest report untitled.air
log.html

The parameter that must be passed in the airtest report command is our running script. There are many other optional parameters supported. For details, please refer to Airtest_generate-html-report .Here is the most common command line:

>airtest report untitled.air --log_root log/ --outfile log/log.html --lang zh

In the above code:
--log_root log/ indicates that an html report is generated using the log contents in the log/ directory;
--outfile log/log.html means to put the html report into the log directory, named log.html;
--lang zh indicates that the specified language is Chinese.

Sometimes we need to copy the report to another directory, or package it for others to view, but the directly generated report can not be viewed since it was copied to other directories.The reason is that all the pictures and static resource files in the report directly generated use absolute paths, so you can't directly copy them to other computers to view them, but you can copy them to other directories in your own computer. So we provide an export mode, which is to add a parameter --export to the directory path after the report command, and you can export the report to a folder to view it.

In addition, we can directly copy the instructions displayed in the log window to run the script after running the sanme script in AirtestIDE.So you can do the same when generating a report:First click on the Generate Report button in AirtestIDE. After the command line for generating the report appears in the log window, copy it to your command line window and you are free to run it.(Note that if the instruction copied into the command line window contains paths, all the paths in the instruction should be separately enclosed in double quotation marks in English mode, otherwise the command line will execute the error.)

Read static resource files and image files in reports

In the report generated by the command airtest report, absolute paths are used to access the image file inside, and the static css and js resource files accessed in the HTML report are also absolute paths on the hard disk (The default is in the report folder under the installation directory of Airtest ).Therefore, if you want to send a report to others to watch, you must add --export exported directory to the end of the command line to export the report to a specified directory, and then send the entire directory to others to watch.

Comparison of read paths of static files: - By default, the report page uses absolute paths to access images and resource files.
- The pages of reports exported using the parameter -export use relative paths to access images and resource files.

Therefore, if you want to deploy the report to the server for others to see, you also need to use the parameter --export to export the report so that the image path is a relative path.

At the same time, you can use the parameter --static_root static resource directory to specify the path to the static resource file (ie, css, js, etc. in the report).We can deploy the resource file to the static resource file server, and access it with a path such as https://host:port/static/css/. When generating the report, you can pass the deployed server address as the parameter of --static_root, so that the report will access the URL to read the static resource file by default, avoiding disk space usage caused by duplicate copying of these resource files when exporting reports.

airtest report untitled.air --log_root log/ --outfile log/log.html --lang zh --static_root https://host:port/static/css/ --export ./report
The report using poco statement

Since the default report is an exclusive report for airtest, the support for the poco statement is not perfect, so we use plugins to support the poco statement:Add the directive --plugin poco.utils.airtest.report at the end of your report command line.

The report using the selenium plugin

If our script uses selenium plugin, be sure to include --plugin airtest_selenium.report at the end of the command line that generated the report, which will allow the report to support the selenium element. Please refer to the Airtest-Selenium documentation for details.

Generate reports using Python code

Usually, we generate reports through the command line, but since Airtest is a Python third-party library, you can simply call the interface to generate reports.First we need to create a new script - select the pure .py file and check the option to generate the log:

image

Then click OK, a .py template will be automatically generated. After writing the script, we can use the following code to call the interface to generate the report:

# generate html report
from airtest.report.report import simple_report
simple_report(__file__)

In the above code, simple_report uses the default parameters, in which case you need to initialize logdir of auto_setup, such as auto_setup(__file__, logdir=True, devices=["Android:///",]), if you do not initialize it, you will not be able to generate log.txt, the error is as follows:

image

After the initialization, the script is executed, and the log.html and log folder (which stores log.txt ) are generated. But if we manually specify the logdir directory, log.txt will be generated in the specified directory.

In addition, more parameters of simple_report can also refer to documentation. You can simply pass logpath= to manually specify the script's log directory to simply generate log.html.

If you have more complex requirements, such as specifying the export directory export_dir or using --plugin poco.utils.airtest.report when using the poco statement in the script, please refer to the document LogToHtml.