This article is from the official account of the project: “AirtestProject” Copyright notice: It is allowed to be reproduced, but the original link must be retained. Do not use it for commercial or illegal purposes

1. Introduction

Recently, I found that many students still have some doubts in the generation of Airtest report, such as:

Why is it possible to generate a report using the AirtestIDE running script, but not using another editor?

Why can’t I find the path of the report generating script written according to the official example or there is another error?

Why did I generate a blank Airtest report (some English reports were translated into Chinese and even turned into air reports……) after a whole operation? ?

This can be considered a great reward for confusing behavior. So today, we are going to discuss why there are so many problems with a small Airtest report.

2. Why can the AirtestIDE running script directly generate a report?

1) The report can be generated directly after the official running of the AIR script

If you can generate a report by using the AirtestIDE running script, you can click the view Report button to generate and view the local Airtest report after running the. Air script.

After a local report is generated, you can right-click the script name and choose Export report to export the Airtest report that can be viewed non-locally:

When running the AirtestIDE. Air script, the system automatically saves the log content, and when clicking the button to view the report, the system generates an Airtest report based on the saved log content.

This can be seen from clicking on the command line to run the script and clicking on the command line to generate the report:

"D:\demo\ airtestide-win-1.2.13 (2)\AirtestIDE\AirtestIDE" runner "D: \ demo \ multi, multi - device - runner - master \ test02 air" - device android: / / 127.0.0.1:5037 / HT7C51A04625? cap_method=MINICAP&&ori_method=MINICAPORI&&touch_method=MAXTOUCH --log "D:/test/test01\dc1584de62ad6aff26d33afe5ce0bc54" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = # generate a report of the command line ============================================================ Generating HTML log: D: \ demo \ AirtestIDE - win - 1.2.13 (2) \ AirtestIDE \ AirtestIDE reporter D: \ demo \ multi \ multi - device - runner - master \ test02 air --log_root D:/test/test01\dc1584de62ad6aff26d33afe5ce0bc54 --outfile D: \ test \ test01 \ dc1584de62ad6aff26d33afe5ce0bc54 \ log HTML - static_root D: \ demo \ AirtestIDE - win - 1.2.13 (2)\AirtestIDE\airtest\report --lang zh --plugin airtest_selenium.report poco.utils.airtest.reportCopy the code

Even though we haven’t written any statement to save the log content in the.air script, the AirtestIDE will automatically save the log to the default directory:

We can see that, when run the script, save the parameters of the log – log “D: / test/test01 \ dc1584de62ad6aff26d33afe5ce0bc54, And generate a report when the specified log_root parameters – log_root D: / test/test01 \ dc1584de62ad6aff26d33afe5ce0bc54 is consistent, showed that after running the script to save the log content, can use when generating reports.

The AirtestIDE automatically does this for us, making it very easy to run a script and generate a test report with one click.

2) The test report cannot be generated after all selected scripts are right-clicked

When running the script of AirtestIDE, some students can select all the codes and right click to run only the selected codes. When the script is running, and then click to view the report, you will find that the popup window prompts “There’s no log. TXT file in log-directory” :

This is because right clicking on the selected code does not automatically save the log content, and report generation relies on the log content to prompt that the log.txt file cannot be found.

So if you debug the script in this way, you will not be able to generate the Airtest test report with one click. Please click the Run script button to generate the test report with one click after running the script.

3) Running the pure. Py script in AirtestIDE cannot generate a test report with one click

In the AirtestIDE, the difference between running a pure PY script and an.air script is very big, as can be seen from the command line running:

D:\demo\AirtestIDE-win-1.2.13 (2)\AirtestIDE\AirtestIDE" pyrunner "D:\demo\test_log.py"Copy the code

As you can see, the AirtestIDE will not help us to add any operation parameters, including device parameters, log save path parameters, etc.

If you want to generate a report by running a pure PY script in the AirtestIDE, you need to add a statement to save the log content when you write the script. For example:

# -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core.api import * from airtest.cli.parser import cli_setup if not cli_setup(): Auto_setup (__file__, devices = [" android: / / 127.0.0.1:5037 / HT7C51A04625 "], logdir = r "D: \ demo \ test_log")Copy the code

After this operation, it will help us to save the log content to the specified log saving path. Then when clicking the view report button, manually select the set log saving path:

3. How to generate a test report without AirtestIDE?

1) Use the simple_report interface

Simple_report interface, which is actually a simplified version of the report generation interface, can reduce the cost of students to understand and use the cost:

  • filepath: Specifies the path to the script
  • logpath: Specifies the path of the log contents
  • logfile: Specifies the path to the log. TXT file
  • output: Specifies the HTML report generation path.htmlAt the end

If students do not specify any parameters, the interface will use the default parameters to generate an HTML report, output=’log.html’ to generate an airtest report named log.html in the current script path:

from airtest.report.report import simple_report
simple_report(__file__)
Copy the code

If output is specified, the report will be generated at the specified path:

from airtest.core.api import *
from airtest.report.report import simple_report

auto_setup(__file__,logdir=True)
simple_report(__file__,logpath=True,output=r"D:\test\report02\log.html")
Copy the code

logdirwithlogpath

To generate an Airtest report, you need to save the log saved during the script running. The logdir parameter of the auto_setup interface can set the path for saving the log. When using simple_report to generate a report, you can set logpath and go to the log storage path specified by logdir to find the log content of the script.

2) useLogToHtml()

Another way to use scripts to generate Airtest reports is to use the LogToHtml() class:

The class’s arguments are much more complex than simple_report() and contain:

  • script_rootTo specify the script path
  • log_rootTo specify the path to the log file
  • static_rootTo specify the server path where static resources will be deployed
  • export_dirTo set the path for storing the exported report
  • script_name, script name
  • logfileTo specify the path to the log file log.txt
  • lang, specify the reporting language (英 文 : zh; English: EN)
  • plugins, specify the reporting plug-in that uses POCO or airtest-Selenium

As an example, we exported the D:\test\report01. Air runtime report in the specified path D:\test\report02 in English:

from airtest.report.report import LogToHtml

h1 = LogToHtml(script_root=r'D:\test\report01.air', log_root=r"D:\test\report01.air\log", export_dir=r"D:\test\report02" ,logfile=r'D:\test\report01.air\log\log.txt', lang='en', plugins=None)
h1.report()
Copy the code

From the example, we can see that using the LogToHtml class to generate the report, we need to instantiate a LogToHtml class and then call the class method report() to generate the Airtest report.

logdirwithlog_root

As mentioned above, generating Airtest report depends on the log content of script running, so we need to save the log content of script running before generating the report, and then specify parameters for it to find the corresponding log content when generating the report.

In the example above, we specify logdir=True in auto_setup, which means that the log contents are saved under the path of the current script; When generating the report, we use the log_root parameter of LogToHtml to specify the search path of the log.

In fact, we change log_root=r”D:\test\report01.air\log” to log_root=True to have the same effect, that is, log save path logdir and log find path log_root must be the same.

More details see our website tutorial document: airtest.doc.io.netease.com/IDEdocs/air… .

4. What can I do if I get an error report when I leave the AirtestIDE?

1) An error is reported that a path cannot be found

Generally, there are two cases that the path cannot be found. One is that an incorrect path is given when parameters such as the log content and log file path are specified. In this case, you only need to observe which path is given the wrong error, and then modify the correct path. Especially if you fill in the relative path, if you really don’t know the relative path, just fill in the absolute path.

The second is that when the report generation path or report export path is specified, a new path is specified, that is, the students expect to generate/export the report under the new path, but in fact, the new path does not exist at present. In this case, pay special attention to that whether the report path is generated or exported, it must be a real path that has been established. Airtest will not help us create the path if the path does not exist. So please build the target path in advance, and then fill in!!

2) Why is the empty/air report generated?

The air report, the English version of Airtest empty, is translated into an air report by the browser. So why do we generate empty test reports?

The code to generate the report is placed at the beginning of the script, usually for beginners. The following is a series of practical operations:

# -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core.api import * from airtest.report.report import simple_report,LogToHtml auto_setup(__file__,logdir=True) simple_report(__file__,log_path=True) Touch (Template (r "tpl1637219700366. PNG," record_pos = (0.103, 0.27), the resolution = (1920, 1080))) sleep(1.0) snapshot(MSG =" Please fill in the test point."Copy the code

The result is that even if we successfully run the entire script, when we finally open the generated report to view, it will be an empty report; This is because the test report was generated at the beginning of the script, and the log does not record the execution of any of the steps (the actual steps are run after the script that generated the report), so you will get an empty test report.


AirtestIDE download: airtest.netease.com/ Airtest tutorial website: airtest.doc.io.netease.com/ build enterprise private cloud service: airlab.163.com/b2b

Official Q group: 117973773

Ah ~ so seriously see here, help click on the left thumb, give me a thumbs-up support, ash often thank you!