II Use command line to generate report¶
Similar to running scripts, we don't necessarily have to generate Airtest reports within AirtestIDE. We can also use the command line to generate reports. In the following text, we will provide a detailed introduction of how to generate Airtest reports using the command line.
1.Generate using AirtestIDE command line.¶
In the section of using AirtestIDE to generate reports, we introduce the commands for generating and exporting reports respectively.
Generating HTML log:
D:\demo\AirtestIDE-win-1.2.12\AirtestIDE\AirtestIDE reporter D:\test\song.air --log_root D:/test/test01\0d86098ed0cd4a54c8c611578a3d71b7 --outfile D:\test\test01\0d86098ed0cd4a54c8c611578a3d71b7\log.html --static_root D:\demo\AirtestIDE-win-1.2.12\AirtestIDE\airtest\report --lang zh --plugin airtest_selenium.report poco.utils.airtest.report
Generating HTML log:
D:\demo\AirtestIDE-win-1.2.12\AirtestIDE\AirtestIDE reporter D:\test\song.air --log_root D:/test/test01\0d86098ed0cd4a54c8c611578a3d71b7 --outfile D:\export\report\song.log\log.html --static_root D:\demo\AirtestIDE-win-1.2.12\AirtestIDE\airtest\report --lang zh --plugin airtest_selenium.report poco.utils.airtest.report --export D:/export/report
Even if we don't have a Python environment or haven't installed airtest and poco locally, we can still copy the above command line to our terminal and run it by pressing enter, and finally generate an Airtest report. Moreover, if we fail to generate a report in the IDE, we can use the error message generated by running the command line in the terminal to troubleshoot the problem in detail.
2.Generate reports using command line in the local environment.¶
Apart from that, we can also deploy a local Python environment to run scripts and generate reports without relying on AirtestIDE.
1) Example of generating a report using a command line.¶
We can use the command "airtest report + script path" to generate Airtest report. Here is an example of generating a report on the command line:
airtest report D:\test\song.air --log_root D:\test\song.air\log --lang zh --outfile D:\test\test01\0d86098ed0cd4a54c8c611578a3d71b7\cloud_music.html
python -m airtest report D:\test\song.air --log_root D:\test\song.air\log --lang zh --outfile D:\test\test01\0d86098ed0cd4a54c8c611578a3d71b7\cloud_music.html
These two command lines have the same effect. We are generating a test report for song.air and specifying to look for the log content under the path D:\test\song.air\log
. We also specify the report language as Chinese and the complete report generation path as D:\test\test01\0d86098ed0cd4a54c8c611578a3d71b7\cloud_music.htm
l.
2)Introduction of parameters for the "airtest report" command.¶
The mandatory parameter for the "airtest report" command is the script path, while other optional parameters are also available.
--outfile
: Specify the path where the HTML report will be generated, ending with .html.
--static_root
: Refers to the path of the static resource files, typically the file server address.
--log_root
: Specifies the search path for log content.
--record
: Specifies the path of the screen recording file.
--export
: Specifies the export path for the report.
--lang
: Specifies the language of the report, which can be Chinese or English (ch or en).
--plugins
: specify the reporting plugin (required when generating reports for poco/airtest-selenium scripts).
We can also refer to the Airtest-running-air-from-cli documentation to learn more details about these parameters.
3.Notes on the airtest report command¶
1)Run the script first, then generate the report.¶
When we use the "airtest report" command to generate a report, we will look for the log content generated by the script in the default log path or the specified log path. If the script has not been run, the log content will be empty, and we cannot generate an airtest report or can only generate a blank test report.
So we need to always remember that we need to run the script first before generating the script's test report. If everything is implemented on the command line, we need to execute the "airtest run" command first before executing the "airtest report" command to generate the test report.
2) Correspondence between the parameters of "airtest run" and "airtest report".¶
These are the corresponding parameters in the two commands: One is the --log parameter of airtest run and the --log_root parameter of airtest report. These two parameters indicate the path where the log is saved when running the script and the location where the log content is found when generating the report. The two parameters are corresponding. Where the log content is generated when running the script, the corresponding location should be searched to generate the report.
The other one is the --recording parameter of airtest run and the --record parameter of airtest report. Similar to the log content just now, when we run the script, we specify where to save the screen recording file, and when generating the report, we need to look for the screen recording file in that path.
3) The difference between the outfile
parameter and the export
parameter.¶
Airtest report
has two parameters that are very easy to confuse: outfile and export.
- "outfile" means the path where the report is generated (the generated report can only be viewed locally).
- export: indicates the export path of the report (the exported report can be sent to others for viewing).
If our airtest report command only contains the outfile parameter and not the export parameter, it means that the generated report can only be viewed locally, and the paths for images or static resources in the report are absolute. If our airtest report command only includes the export parameter and does not include the outfile parameter, it means that the report generated this time is an exported report that can be sent to others or deployed to a server for viewing. The paths for the image resources or static resources in the report are relative. If our airtest report command contains both the outfile and export parameters, only the export parameter will take effect, and the outfile parameter will be invalid.
4) Explanation of the static_root
parameter¶
Every time the --export parameter is used to export a report, there will be a static resource file named "static" in the directory of the report file, which contains the css and js files in the report. Generally speaking, unless the format of the report has been updated, these static resource files remain unchanged.
So we can deploy these resource files to a static resource file server and access them using a path like https://host:port/static/css/. Then, when generating the report, pass the deployed server address as the --static_root parameter. This way, the report will automatically access this URL to read the static resource files, avoiding the disk space occupation caused by repeatedly copying these resource files during report export.
airtest report D:/test/report_test.air --log_root
C:/Users/xiaoming/log --lang zh --static_root https://host:port --export E:/log_test/
This report will default to visiting the server address passed in the --static_root
parameter and read static resource files from there.
This can effectively avoid the disk space occupation caused by duplicating these resource files when exporting reports.
However, if we pass a local path to --static_root
instead of a server address, when we export the report, a copy of the static files will still be copied to the report folder:
>airtest report D:\test\song.air --log_root D:/test/test01\0d86098ed0cd4a54c8c611578a3d71b7 --static_root D:\demo\AirtestIDE-win-1.2.12\AirtestIDE\airtest\report --lang zh --export D:\export
[14:30:44][INFO]<airtest.report.report> D:\export\song.log\log.html
5) Explanation of plugins parameters.¶
The default report is an exclusive report for Airtest. It does not fully support Poco statements and Airtest-Selenium statements. Therefore, we need to use plugins to supplement the support for Poco statements and Airtest-Selenium statements:
Add the command --plugin airtest_selenium.report poco.utils.airtest.report" at the end of the command line in your report
.