III. Airtest Report Guide¶
1.Preface¶
This section of the tutorial contains the following content: Report interface introduction Customize report info (This article is based on IDE1.2.12 and Airtest1.2.3)
2.Report interface introduction¶
1) Airtest report heading¶
The Airtest report heading includes information such as: execution results, execution time, execution steps, log.txt, script author, script name, script description, etc.
2) Airtest report steps details¶
Following the heading, there's the details of all testing steps and their results.
We can click the step info on the left to view the details of each step; or click the shortcut on the right to get to error steps; or filter out failed, successful, or assertion steps; or we can also click a picture on the quick glance to get to the details of that step.
3.Display and customize report info¶
1) Customize script author info¶
Use __author__
at the beginning to edit the author info of the script.
The display of Airtest report is as follow:
`__author__` = "AirtestProject"
The display of Airtest report is as follow:
2) Customize report title¶
Use __title__
at the beginning to edit the title of the report.
The display of Airtest report is as follow:
__title__ = "big fish script"
The display of Airtest report is as follow:
3) Customize script description¶
Use __desc__
at the beginning to edit scrpit description. The description will be folded if it is too long.
The display of Airtest report is as follow:
__desc__ = """
Big fish is here 5 minutes script
Test point 1
Test point 2
Test point 3
"""
The display of Airtest report is as follow:
4) Steps for customizing name¶
Right now we only support customizing the names for assertion steps and adding a customized name using log API
① Customize assertion step name¶
assert_equal("1", "1", "this is an assertion")
The display of Airtest report is as follow:
② Customize step name using log¶
log("this is a log")
The display of Airtest report is as follow:
Additionally, the following 4 parameters are supported when recording log()
API ofr log in the script.
args
, which can be the object of strings ortracebck
, now also supports passing in non-strings and is compatible with py2. If atraceback
object is passed in, it will be automatically marked as an error step in the report, otherwise it will be displayed as normal log content.timestamp
, which can be used to customize the timestamp of the current log, is default to the current time (when recording the logs obtained in long-term callbacks, the time when this log was passed is used by default, but it may need to be modified to the time when the log was generated).desc
, which is used to customize the title of a log for a better display effect in the report.snapshot
, used to get a screenshot of the current screen and put it into a report. (At the same time, because of the addition of this parameter, if the airtest script terminates due to the failure to execute the Poco statement and reports an error, you can get an additional shot of the current screen to facilitate troubleshooting.)
Example:
data = {"test": 123, "time": 123456}
# The first log. Set display step name as title, and take a screenshot
log(data, timestamp=time.time(), desc="title", snapshot=True)
# The second log. Mark as error step and take a screenshot
try:
1/0
except Exception as e:
log(e, snapshot=True)
# The third log, showing the passed in string
log("Chinese")
5) Customize compression quality for single or global screenshot(s)¶
We can customize compression quality according to the following format:
① Use command line: airtest run ... --compress quality
. quality
takes the value 1-99, the higher the value, the clearer the screenshot.
② Customizing in script. The priority is higer than command line. The value range is a positive integer between 1-99 (default to 10). If you want a clearer picture, you can set the value to 75, 90, etc.
import airtest.core.api import *
ST.SNAPSHOT_QUALITY = xxx # [1, 99]
# In this touch step of the report, the global compression quality of the screenshots is xxx
touch(xx)
# The global compression quality of the screenshots saved by snapshot is also xxx
snapshot()
③ Define the compression quality of a single screenshot
snapshot(quality=my_quality)
6) Customize the maximum size of report screenshots¶
We can use ST.IMAGE_MAXSIZE
to define the maximum size of the designated screenshot. For example, if the value is set to 1200, the saved screenshots will not exceed 1200 in length and width, which further reduce the size of screenshots.
# Define the size of the screenshots to not exceed 600*600. If it's not defined, then the image will be in it's original size.
ST.IMAGE_MAXSIZE = 600
# In this touch step of the report, the saved screenshots will not exceed the size of 600*600
touch(xx)
# Define compression quality as 90, maximum size as 1200*1200
snapshot(filename="test2.png", msg="test02", quality=90, max_size=1200)
# If not set, it will default to the value of the global variable in ST, which is 600*600
snapshot(msg="test12")
7) Disable screenshot¶
If you want to set whether to take screenshots in the script, we can use the ST.SAVE_IMAGE
in the settings. Its default value is True
, if changed to False
, screenshots will not be saved until the value is changed to True
again. Example:
from airtest.core.api import *
# Disable screenshot temporarily
ST.SAVE_IMAGE = False
touch((100, 100)) # This statement will not save the image on the current screen
# Continue to take screenshot
ST.SAVE_IMAGE = True
touch((100, 100))
(touch that has not saved screenshots)
(touch that has saved screenshots)
4.Expansion: Get the script details separately¶
If you want to get script info like name, save path, author, title, description, etc., you can use the command line: airtest info + scriptpath
to get the script info phrased by airtest. The return value will be like this:
>airtest info untitled.air
{"name": "untitled.air", "path": "untitled.air", "author": "user", "title": "script title", "desc": "use case description"}