airtest.core.helper module¶
-
class
G
[source]¶ Bases:
object
Represent the globals variables
-
BASEDIR
= []¶
-
LOGGER
= <airtest.utils.logwraper.AirtestLogger object>¶
-
LOGGING
= <Logger airtest.core.api (DEBUG)>¶
-
SCREEN
= None¶
-
DEVICE_LIST
= []¶
-
RECENT_CAPTURE
= None¶
-
RECENT_CAPTURE_PATH
= None¶
-
CUSTOM_DEVICES
= {}¶
-
-
set_logdir
(dirpath)[source]¶ set log dir for logfile and screenshots.
Parameters: dirpath – directory to save logfile and screenshots Returns:
-
log
(arg, timestamp=None, desc='', snapshot=False)[source]¶ Insert user log, will be displayed in Html report.
Parameters: - arg – log message or Exception object
- timestamp – the timestamp of the log, default is time.time()
- desc – description of log, default is arg.class.__name__
- snapshot – whether to take a screenshot, default is False
Returns: None
Examples
>>> log("hello world", snapshot=True) >>> log({"key": "value"}, timestamp=time.time(), desc="log dict") >>> try: 1/0 except Exception as e: log(e)
-
logwrap
(f)[source]¶ A decorator used to add the current function to the airtest log, which can be seen on the report html page
Parameters: f – The function being decorated Returns: The decorated function Examples
Add foo() to the airtest report html page:
@logwrap def foo(): pass
-
using
(path)[source]¶ Import a function from another .air script, the
using
interface will find the image path from the imported function.Parameters: path – relative or absolute. This function transforms a given relative path, searching in the project root, current working directory, or the current script’s directory, into an absolute path and adds it to the sys.path and G.BASEDIR. Returns:
Examples
Suppose our project structure is as follows:
demo/ foo/ bar.air baz.air main.py
If we want to reference foo/bar.air and baz.air in main.py, we can write:
# main.py from airtest.core.api import * ST.PROJECT_ROOT = r"D:\demo" # This line can be ignored if it is the current working directory using("foo/bar.air") using("baz.air")
If we want to reference baz.air in foo/bar.air, we can write:
# foo/bar.air from airtest.core.api import * using("../baz.air")