"""
@author: meili
@contact: meili02@corp.netease.com
@file: api.py
@date: 2023/2/20 19:50
@desc:
"""
import time
import GPUtil
import cpuinfo
import psutil
from airtest.core.api import Template as Image
from autoease.core.autoease_global import (
AutoEaseG,
Platform,
RunMode,
)
from autoease.core.stage import (
Stage,
StageManager,
auto_put_step
)
from autoease.core.error import TargetNotFoundError
from autoease.core.error import ModuleError
from autoease.utils.udata import PromeDataRequest
from autoease.driver_control.xbox_gamepad import GAMEPAD_BUTTONS
[docs]def init_autoease(exp_mode=RunMode.LOCAL,
platform=Platform.WIN64,
game_project_name=None,
record_id=None,
is_record=False,
is_upload_video=True,
case_name="default_case",
report_url="https://test-autoease.nie.netease.com/prod-server/reportRecord",
logs_saved="autoease_logs/",
case_info_log=None,
case_error_log=None,
**kwargs):
"""Initialize the AutoEase instance as a global parameter
----
Args:
exp_mode(Optional[str]): The mode of use scenario, defaults to "local"
**- local**: run locally, no report will be generated and upload to the web
**- deploy**: run in deployment mode. Parameters game_path, record_id must be given,
and is_record must be set to True. Otherwise exp_mode will be set to "local"
game_path(Optional[str]):
the path to the game excutable
game_project_name(Optional[string]):
The name of the game project. This will be used to locate
log files and keep the game process on top
record_id(Optional[int]):
the record_id of current test run, which will be used to assgin recorded videos
to test report
report_url(Optional[str]):
the url to the AutoEase report backend, defaults to
``https://test-autoease.nie.netease.com/prod-server/reportRecord``
Returns:
None
Examples:
>>> init_autoease(exp_mode=RunMode.LOCAL,
>>> game_path="D:/Projects/Dayly/LyraGame.exe",
>>> game_project_name="LyraStarterGame")
"""
from autoease.core.autoease_global import init_autoease_global
# initial autoease_global
init_autoease_global(exp_mode=exp_mode,
platform=platform,
game_project_name=game_project_name,
is_record=is_record,
is_upload_video=is_upload_video,
record_id=record_id,
case_name=case_name,
report_url=report_url,
logs_saved=logs_saved,
case_info_log=case_info_log,
case_error_log=case_error_log,
**kwargs)
"""
stage
"""
[docs]def put_stage(name=None, **kwargs):
"""A context manager which sets a new stage and put it to the test run,
----
c
Args:
name(string):
The name of the test stage
Return:
(Class object): A stage class instance with the given name
Example:
>>> with put_stage(name="new test stage"):
>>> key_press(key="W", duration=1)
>>> mouse_click()
"""
if name is None or name == "":
raise TypeError("The stage of name can not be None or blank str!")
stage = Stage(name=name)
StageManager.append_stage(stage)
return stage
[docs]@auto_put_step
def wait(duration, **kwargs):
"""pause for a period of time, a test step will be automatically added for this operation
----
Args:
duration(float):
The time to be paused in seconds
Returns:
None
Example:
>>> wait(duration=5)
"""
time.sleep(duration)
[docs]def get_resource(resource_name: str, **kwargs):
"""Get the path of the given resource name.
An error will be raised if the resource does not exist
----
Args:
resource_name(string):
The name of the resource file
Returns:
string:
relative path of the resource
Raises:
ResourceNotFoundError: If the resource does not exist
Example:
>>> get_resource("check_keybinding_screen/keybinding_screen.png")
>>> "testcase_resources/check_keybinding_screen/keybinding_screen.png"
"""
return AutoEaseG.CASE_RESOURCE_MANAGER.get_resource(resource_name)
"""
keyboard api
"""
[docs]@auto_put_step
def key_press(key, duration=0.05, **kwargs):
"""simulate the key down input for a duration of time then key up,
a test step will be automatically added for this operation
----
Args:
key(string):
The keyboard key that user would like to press.
Please see autoease/driver_control/keyboard.py for a detailed key mapping
duration(optional[non-negative float]):
the duration of the time the given key will be hold down, default to None,
the key will be down and up instantly
Returns:
None
Example:
>>> key_press("R", duration=1)
"""
AutoEaseG.DEVICE.key_press(key, duration)
[docs]@auto_put_step
def keys_press(keys: list, internal=0.05, duration=0.05, **kwargs):
AutoEaseG.DEVICE.keys_press(keys, internal, duration)
[docs]@auto_put_step
def key_down(key, **kwargs):
"""simulate the key down input,
a test step will be automatically added for this operation
----
Args:
key(string):
The keyboard key that user would like to hold down
Please see autoease/driver_control/keyboard.py for a detailed key mapping
**kwargs: optional keyword arguments.
Returns:
None
Example:
>>> key_down("R")
"""
AutoEaseG.DEVICE.key_down(key, **kwargs)
[docs]@auto_put_step
def key_up(key, **kwargs):
"""simulate the key up input,
a test step will be automatically added for this operation
----
Args:
key(string):
The keyboard key that user would like to release
Please see autoease/driver_control/keyboard.py for a detailed key mapping
**kwargs:
optional keyword arguments.
Returns:
None
Example:
>>> key_up("R")
"""
AutoEaseG.DEVICE.key_up(key, **kwargs)
[docs]@auto_put_step
def key_write(words, duration=0.05, **kwargs):
"""simulate keyboard input for a string,
a test step will be automatically added for this operation
----
Args:
words(string):
the string that user would like to enter
duration(optional[non-negative float]):
duration of pause between each character entry in seconds.
Defaults to None, the entire command will be entered instantly
Returns:
None
Example:
>>> key_write(words="type_this", duration=1)
"""
AutoEaseG.DEVICE.key_write(words, duration=duration)
"""
gamepad api
"""
[docs]@auto_put_step
def gamepad_left_joystick_set(x_value: float, y_value: float, duration=None, **kwargs):
"""simulate set the gamepad left joystick x and y axis value,
a test step will be automatically added for this operation
----
Args:
x_value(float):
The value of x axis.
Between -1.0 and 1.0.
y_value(float):
The value of y axis.
Between -1.0 and 1.0.
duration(optional[non-negative float]):
the duration of the time behind setting the x and y axis, default to None,
Returns:
None
Example:
>>> gamepad_left_joystick_set(0, 1.0, duration=3)
>>> gamepad_left_joystick_set(0, 0)
"""
AutoEaseG.DEVICE.gamepad_left_joystick_set(x_value, y_value, duration)
[docs]@auto_put_step
def gamepad_left_joystick_set_and_reset(x_value: float, y_value: float, duration=0.05, **kwargs):
"""simulate set the gamepad left joystick x and y axis value for a while and reset,
a test step will be automatically added for this operation
----
Args:
x_value(float):
The value of x axis.
Between -1.0 and 1.0.
y_value(float):
The value of y axis.
Between -1.0 and 1.0.
duration(optional[non-negative float]):
the duration of the time between set value and reset, default to 0.05,
Returns:
None
Example:
>>> gamepad_left_joystick_set_and_reset(0, 1.0, duration=2)
"""
AutoEaseG.DEVICE.gamepad_left_joystick_set_and_reset(x_value, y_value, duration)
[docs]@auto_put_step
def gamepad_right_joystick_set(x_value: float, y_value: float, duration=None, **kwargs):
"""simulate set the gamepad right joystick x and y axis value,
a test step will be automatically added for this operation
----
Args:
x_value(float):
The value of x axis.
Between -1.0 and 1.0.
y_value(float):
The value of y axis.
Between -1.0 and 1.0.
duration(optional[non-negative float]):
the duration of the time behind setting the x and y axis, default to None,
Returns:
None
Example:
>>> gamepad_right_joystick_set(0, 1.0, duration=3)
>>> gamepad_right_joystick_set(0, 0)
"""
AutoEaseG.DEVICE.gamepad_right_joystick_set(x_value, y_value, duration)
[docs]@auto_put_step
def gamepad_right_joystick_set_and_reset(x_value: float, y_value: float, duration=0.05, **kwargs):
"""simulate set the gamepad right joystick x and y axis value for a while and reset,
a test step will be automatically added for this operation
----
Args:
x_value(float):
The value of x axis.
Between -1.0 and 1.0.
y_value(float):
The value of y axis.
Between -1.0 and 1.0.
duration(optional[non-negative float]):
the duration of the time between set value and reset, default to 0.05,
Returns:
None
Example:
>>> gamepad_right_joystick_set_and_reset(0, 1.0, duration=2)
"""
AutoEaseG.DEVICE.gamepad_right_joystick_set_and_reset(x_value, y_value, duration)
[docs]@auto_put_step
def gamepad_left_trigger_set(value: float, duration=None, **kwargs):
"""simulate set the gamepad left trigger value,
a test step will be automatically added for this operation
----
Args:
value(float):
The value of trigger.
Between 0 and 1.0.
duration(optional[non-negative float]):
the duration of the time behind setting the trigger value, default to None,
Returns:
None
Example:
>>> gamepad_left_trigger_set(1.0, duration=3)
>>> gamepad_left_trigger_set(0)
"""
AutoEaseG.DEVICE.gamepad_left_trigger_set(value, duration)
[docs]@auto_put_step
def gamepad_left_trigger_set_and_reset(value: float, duration=0.05, **kwargs):
"""simulate set the gamepad left trigger value for a while and reset,
a test step will be automatically added for this operation
----
Args:
value(float):
The value of trigger.
Between 0 and 1.0.
duration(optional[non-negative float]):
the duration of the time between set value and reset, default to None,
Returns:
None
Example:
>>> gamepad_left_trigger_set_and_reset(1.0, duration=3)
>>> gamepad_left_trigger_set_and_reset(0)
"""
AutoEaseG.DEVICE.gamepad_left_trigger_set_and_reset(value, duration)
[docs]@auto_put_step
def gamepad_right_trigger_set(value: float, duration=None, **kwargs):
"""simulate set the gamepad right trigger value,
a test step will be automatically added for this operation
----
Args:
value(float):
The value of trigger.
Between 0 and 1.0.
duration(optional[non-negative float]):
the duration of the time behind setting the trigger value, default to None,
Returns:
None
Example:
>>> gamepad_right_trigger_set(1.0, duration=3)
>>> gamepad_right_trigger_set(0)
"""
AutoEaseG.DEVICE.gamepad_right_trigger_set(value, duration)
[docs]@auto_put_step
def gamepad_right_trigger_set_and_reset(value: float, duration=0.05, **kwargs):
"""simulate set the gamepad right trigger value for a while and reset,
a test step will be automatically added for this operation
----
Args:
value(float):
The value of trigger.
Between 0 and 1.0.
duration(optional[non-negative float]):
the duration of the time between set value and reset, default to None,
Returns:
None
Example:
>>> gamepad_right_trigger_set_and_reset(1.0, duration=3)
>>> gamepad_right_trigger_set_and_reset(0)
"""
AutoEaseG.DEVICE.gamepad_right_trigger_set_and_reset(value, duration)
"""
mouse api
"""
[docs]@auto_put_step
def mouse_move_and_click(pos, duration=1, repeat=1, **kwargs):
"""Move mouse to a position then simulate a click,
a test step will be automatically added for this operation
----
Args:
pos(tuple[float,float]):
the position on screen to move mouse to
duration(optional[non-negative float]):
the time takes to move mouse from the
current position to the given position in seconds. Defaults to 1
repeat(optional[positive int]):
number of time the given mouse button will be pressed and released
Returns:
None
Examples:
>>> mouse_move_and_click(pos=(460,889), button="LEFT", duration=1, repeat=2)
"""
AutoEaseG.DEVICE.mouse_move_and_click(pos, duration=duration, repeat=repeat, **kwargs)
[docs]@auto_put_step
def mouse_click(button='LEFT', duration=0.05, repeat=1, **kwargs):
"""simulate a mouse click,
a test step will be automatically added for this operation
----
Args:
button(optional[string]):
the mouse button the user would like to click, default to "LEFT"
Please see autoease/driver_control/mouse.py for a detailed key mapping
duration(optional[non-negative float]):
The duration of time the mouse button will be hold down until released in seconds.
Defaults to None, the button will be clicked then released instantly
repeat(optional[int]):
number of time the given mouse button will be pressed and released
Returns:
None
Examples:
>>> mouse_click(button="MIDDLE", duration=1, repeat=1)
"""
AutoEaseG.DEVICE.click(button, duration, repeat)
[docs]@auto_put_step
def mouse_double_click(button='LEFT', duration=0.05, repeat=1, **kwargs):
"""simulate double click on a mouse button
a test step will be automatically added for this operation
----
Args:
button(optional[string]):
the mouse button to click, default to "LEFT"
Please see autoease/driver_control/mouse.py for a detailed key mapping
duration(optional[non-negative float]):
The duration of time paused between each double-click.
Defaults to None, no pause between double clicks
repeat(optional[int]):
number of time the given mouse button will be double-clicked,
defaults to 1
Returns:
None
Examples:
>>> mouse_double_click(button="RIGHT", duration=1, repeat=1)
"""
AutoEaseG.DEVICE.double_click(button, duration, repeat)
[docs]@auto_put_step
def mouse_drag(pos1: tuple, pos2: tuple, button='LEFT', duration=1, **kwargs):
"""Move mouse to a position then simulate a button press down, then move to a position and release
the mouse button. A test step will be automatically added for this operation
----
Args:
pos1(tuple[float,float]):
the position on screen to move mouse to before press down the given mouse button
pos2(tuple[float,float]):
the position on screen to move mouse to after press down the given mouse button
button(optional[string]):
the mouse button to click, default to "LEFT"
Please see autoease/driver_control/mouse.py for a detailed key mapping
duration(optional[non-negative float]):
the time takes to move mouse from the pos1 to pos2 in seconds. Defaults to None
Returns:
None
Examples:
>>> mouse_drag(pos1=(0.0,0), pos2=(100,100.5), button="LEFT", duration=1)
"""
AutoEaseG.DEVICE.mouse_drag(pos1, pos2, button, duration, **kwargs)
[docs]@auto_put_step
def mouse_move(pos: tuple, **kwargs):
"""simulate a mouse move,
a test step will be automatically added for this operation
----
Args:
pos1(tuple[float,float]):
the position on screen to move mouse
Returns:
None
Examples:
>>> mouse_move((900, 900))
"""
AutoEaseG.DEVICE.mouse_move(pos)
[docs]@auto_put_step
def mouse_wheel(steps: int, direction='FORWARD', duration=0.05, **kwargs):
"""simulate mouse use wheel
a test step will be automatically added for this operation
----
Args:
steps(int):
the steps to use wheel movement.
direction(optional[non-negative str]):
'FORWARD' or 'BACK'.
The direction of wheel movement, defaults to 'FORWARD'.
duration(optional[non-negative float]):
the time among each wheel movement. Defaults to 0.05
Returns:
None
Examples:
>>> mouse_wheel(1, button="FORWARD")
>>> mouse_wheel(2, button="BACK", duration=1)
"""
return AutoEaseG.DEVICE.mouse_wheel(steps, direction, duration)
"""
identification api
"""
[docs]@auto_put_step
def img_exist(img, **kwargs):
"""Check whether the given target exists on device screen.
A test step will be automatically added for this operation
----
Args:
img(class object[Template]):
the image of the target to be checked
**kwargs: optional keyword arguments.
Returns:
Boolean or Tuple(float,float): False if target is not found,
otherwise returns the center coordinates (X,Y) of target's location
Examples:
>>> img_exist(Image("testcase_resources/ability_test/ability_slot.png"))
>>> (100, 200)
or
>>> img_exist(Image(get_resource("ability_test/ability_slot.png")))
>>> False
"""
return AutoEaseG.DEVICE.img_exist(img, **kwargs)
[docs]@auto_put_step
def assert_img_exists(img, **kwargs):
"""Check whether given target exists on device screen.
A test step will be automatically added for this operation
----
Args:
img(class object[Template]): the image of the target to be checked
**kwargs: optional keyword arguments.
Returns:
Tuple(float,float):
the center coordinates (X,Y) of the target's location if the target is found,
raise an error otherwise
Raises:
AssertionError: If the target is not found
Examples:
>>> assert_img_exists(Image("testcase_resources/ability_test/ability_slot.png"))
>>> (100, 200)
or
>>> assert_img_exists(Image(get_resource("ability_test/ability_slot.png")))
>>> Traceback (most recent call last):
>>> ...
>>> AssertionError: Template(...) does not exist in screen, message:
"""
return AutoEaseG.DEVICE.img_assert_exists(img, **kwargs)
[docs]@auto_put_step
def assert_img_not_exists(img, **kwargs):
"""Check whether given target not exist on device screen.
A test step will be automatically added for this operation
----
Args:
img(class object[Template]):
the image of the target to be checked
**kwargs: optional keyword arguments.
Returns:
None
Raises:
AssertionError: If the target is found
Examples:
>>> assert_img_not_exists(Image("testcase_resources/ability_test/ability_slot.png"))
or
>>> assert_img_not_exists(Image(get_resource("ability_test/ability_slot.png")))
"""
return AutoEaseG.DEVICE.assert_not_exists(img, **kwargs)
[docs]@auto_put_step
def img_click(img, **kwargs):
"""Move mouse to the position of the target and click the left mouse button.
A test step will be automatically added for this operation
----
Args:
img(class object[Template]):
the image of the target to be checked
**kwargs: optional keyword arguments, supports duration(float), times(int)
Returns:
Tuple(float,float): the center coordinates (X,Y) of the target's location if the target
is found, raise an error otherwise
Raises:
TargetNotFoundError: If the target is not found on screen
Examples:
>>> img_click(Image(get_resource("module/login_game/login_screen.png")))
>>> (100, 200)
"""
return AutoEaseG.DEVICE.img_click(img, **kwargs)
[docs]@auto_put_step
def img_double_click(img, **kwargs):
"""Move mouse to the position of the target and double-click the left mouse button.
A test step will be automatically added for this operation
----
Args:
img(class object[Template]):
the image of the target to be checked
**kwargs:
optional keyword arguments, supports duration(float), times(int)
Returns:
Tuple(float,float):
the center coordinates (X,Y) of the target's location if the target
is found, raise an error otherwise
Raises:
TargetNotFoundError: If the target is not found on screen
Examples:
>>> img_double_click(Image(get_resource("module/login_game/login_screen.png")))
>>> (100, 200)
"""
return AutoEaseG.DEVICE.double_click(img, **kwargs)
"""
ocr api
"""
[docs]@auto_put_step
def ocr_exist_sentence(word_list, **kwargs):
"""Check whether given word_list exists in a sentence on device screen.
A test step will be automatically added for this operation
----
Args:
word_list(list[string]):
list of strings to be checked
Returns:
list[(float, float), (float, float), (float, float), (float, float)]):
The four conner coordinates of the rectangle where the list of strings have been found
on screen. return False if not all strings have been found
Examples:
>>> ocr_exist_sentence(["Test", "word", "list"])
>>> [(100, 200), (300, 200), (300, 250), (100, 250)]
"""
return AutoEaseG.DEVICE.ocr_exist_sentence(word_list)
[docs]@auto_put_step
def ocr_assert_exist_sentence(word_list, **kwargs):
"""Check whether given word_list exists in a sentence on device screen.
A test step will be automatically added for this operation
----
Args:
word_list(list[string]):
list of strings to be asserted
Returns:
list[(float, float), (float, float), (float, float), (float, float)]):
The four conner coordinates of the rectangle where the list of strings have been
found on screen.
Raises:
TargetNotFoundError:
If not all strings in word_list are not found
Examples:
>>> ocr_assert_exist_sentence(["Test", "word", "list"])
>>> [(100, 200), (300, 200), (300, 250), (100, 250)]
>>> ocr_assert_exist_sentence(["Test", "word", "list"])
>>> Traceback (most recent call last):
>>> ...
>>> TargetNotFoundError: OCR can not find the sentence ... in screen:
"""
return AutoEaseG.DEVICE.ocr_assert_exist_sentence(word_list)
[docs]@auto_put_step
def ocr_exist_sentence_on_screen_rectangle(
x1: int, y1: int, x2: int, y2: int, word_list: list, **kwargs):
"""Check whether given word_list exists in a sentence in a rectangle on the device screenshot.
A test step will be automatically added for this operation
----
Args:
x1:
the x-axis of the bottom-left corner of the rectangle on device screen
y1:
the y-axis of the bottom-left corner of the rectangle on device screen
x2:
the x-axis of the top-right corner of the rectangle on device screen
y2:
the y-axis of the top-right corner of the rectangle on device screen
word_list(list[string]):
A list of strings to be checked
**kwargs:
optional keyword arguments, supports quality(int)
Returns:
list[(float, float), (float, float), (float, float), (float, float)]) or string:
The four conner coordinates of the rectangle where the list of strings have been
found on screen. Return string if recognize text don't match
Examples:
>>> ocr_exist_sentence_on_screen_rectangle(900, 771, 1020, 794, ["KILLS", ":", "1"])
>>> [(900, 771), (1020, 771), (1020, 794), (900, 794)]
>>> ocr_exist_sentence_on_screen_rectangle(900, 771, 1020, 794, ["KILLS", ":", "1"])
>>> "KILLS:2"
"""
return AutoEaseG.DEVICE.ocr_exist_sentence_on_screen_rectangle(x1, y1, x2, y2, word_list, **kwargs)
[docs]@auto_put_step
def ocr_click(sentence: str, **kwargs):
"""Find the given string in screen, then move mouse to the center of the position
and click the left mouse button.
A test step will be automatically added for this operation
----
Args:
sentence(string):
the sentence to be asserted
Returns:
list[(float, float), (float, float), (float, float), (float, float)]):
The four conner coordinates of the rectangle where the list of strings have been
found on screen. Raise an error otherwise
Raises:
TargetNotFoundError: If the given string is not found on screen
Examples:
>>> ocr_click("Play")
>>> ocr_click("Open")
>>> Traceback (most recent call last):
>>> ...
>>> TargetNotFoundError: Sentence Open not found in screen:
"""
return AutoEaseG.DEVICE.ocr_click(sentence)
"""
assert api
"""
[docs]@auto_put_step
def assert_is_not_false(a, msg="", **kwargs):
"""Assert whether a variable is NOT False(boolean).
A test step will be automatically added for this operation
----
Args:
a:
the variable to be asserted
msg(string):
The printout message if the given variable is False
Returns:
None
Raises:
AssertionError: if the given variable is False
Examples:
>>> assert_is_not_false(flag, msg="The flag is False!")
"""
assert a is not False, "%s is False, message: %s" % (a, msg)
[docs]@auto_put_step
def assert_is_false(a, msg="", **kwargs):
"""Assert whether a variable is False(boolean).
A test step will be automatically added for this operation
----
Args:
a:
the variable to be asserted
msg(string):
The printout message if the given variable is NOT False
Returns:
None
Raises:
AssertionError: if the given variable is anything other than False
Examples:
>>> assert_is_false(flag, msg="The flag is not False!")
"""
assert a is False, "%s is not False, message: %s" % (a, msg)
[docs]@auto_put_step
def assert_is_true(a, msg="", **kwargs):
"""Assert whether a variable is True(boolean).
A test step will be automatically added for this operation
----
Args:
a:
the variable to be asserted
msg(string):
The printout message if the given variable is NOT True
Returns:
None
Raises:
AssertionError: if the given variable is anything other than True
Examples:
>>> assert_is_true(flag, msg="The flag is not True!")
"""
assert a is True, "%s is not True, message: %s" % (a, msg)
[docs]@auto_put_step
def assert_is_not_true(a, msg="", **kwargs):
"""Assert whether a variable is NOT True(boolean).
A test step will be automatically added for this operation
----
Args:
a:
the variable to be asserted
msg(string):
The printout message if the given variable is True
Returns:
None
Raises:
AssertionError: if the given variable is True
Examples:
>>> assert_is_not_true(flag, msg="The flag is True!")
"""
assert a is not True, "%s is True, message: %s" % (a, msg)
[docs]@auto_put_step
def assert_equal(a, b, tolerance=0, msg: str = "", **kwargs):
"""Assert two variables whether equal or not with tolerance.
A test step will be automatically added for this operation
Args:
a:
the first variable
b:
the second variable
tolerance:
the tolerance of comparing a and b
msg(string):
if a and b not equal then will out put the msg
Returns:
None
Raises:
AssertionError: if variable a is not equal to variable b
Examples:
>>> assert_equal(1, 1, tolerance=1, msg="assert 1==1")
"""
assert a >= b - tolerance and a <= b + tolerance,\
"%s and %s are not equal, tolerance is %s, message: %s" \
% (a, b, tolerance, msg)
[docs]@auto_put_step
def assert_greater(a, b, msg="", **kwargs):
"""Assert whether a variabel is greater than another variable.
A test step will be automatically added for this operation
Args:
a:
the first variable
b:
the second variable
msg(string):
the printout message if a is not greater than b
Returns:
None
Raises:
AssertionError: if variable a is not greater than variable b
Examples:
>>> assert_greater(1, 1, msg="assert 1>1")
"""
assert a > b, "%s is not greater than %s, message: %s" % (a, b, msg)
[docs]@auto_put_step
def assert_greater_equal(a, b, msg="", **kwargs):
"""Assert whether a variabel is greater than or equal to another variable.
A test step will be automatically added for this operation
Args:
a:
the first variable
b:
the second variable
msg(string):
the printout message if a is not greater or equal than b
Returns:
None
Raises:
AssertionError: if variable a is not greater than or equal to variable b
Examples:
>>> assert_greater_equal(1, 1, msg="assert 1>=1")
"""
assert a >= b, "%s is not greater than or equal to %s, message: %s" % (a, b, msg)
[docs]@auto_put_step
def assert_less(a, b, msg="", **kwargs):
"""Assert whether a variabel is less than another variable.
A test step will be automatically added for this operation
Args:
a:
the first variable
b:
the second variable
msg(string):
the printout message if a is not less than b
Returns:
None
Raises:
AssertionError: if variable a is not less than variable b
Examples:
>>> assert_less(1, 1, msg="assert 1<1")
"""
assert a < b, "%s is not less than %s, message: %s" % (a, b, msg)
[docs]@auto_put_step
def assert_less_equal(a, b, msg="", **kwargs):
"""Assert whether a variabel is less than or equal to another variable.
A test step will be automatically added for this operation
Args:
a:
the first variable
b:
the second variable
msg(string):
the printout message if a is not less or equal than b
Returns:
None
Raises:
AssertionError: if variable a is not less than or equal to variable b
Examples:
>>> assert_less_equal(1, 1, msg="assert 1<=1")
"""
assert a <= b, "%s is not less than or equal to %s, message: %s" % (a, b, msg)
"""
others api
"""
[docs]@auto_put_step
def wait_for_keyword(keyword, log_file_path=None, timeout=20, is_rematch=False, opfunc=None, **kwargs):
"""Monitor new input to the log file and search for keywords.
A test step will be automatically added for this operation
----
Args:
keyword(string):
The keywords to look for
timeout(float):
maximum time of monitoring in seconds
is_rematch(Boolean):
If True, look for keywords by regular expression.
If False, look for the exact given keywords.
opfunc(function): The function to be excuted when keywords appear in the log file
Returns:
String or Boolean:
The entire line of the log where the keywords are found.
False if no log input contains the given keywords before timeout.
Examples:
>>> wait_for_keyword("LogWorld: Bringing World /Game/Provisional/QA/Maps/Smoke_01/Smoke_01.Smoke_01", timeout=20, is_rematch=False, opfunc=mouse_click)
>>> "[2023.04.03-03.49.18:825][816]LogWorld: Bringing World /Game/Provisional/QA/Maps/Smoke_01/Smoke_01.Smoke_01 up for play (max tick rate 0) at 2023.04.03-11.49.18"
or
>>> wait_for_keyword("LogWorld: Bringing World /Game/Provisional/QA/Maps/Smoke_01/Smoke_01.Smoke_01", timeout=20, is_rematch=False, opfunc=mouse_click)
>>> False
"""
return AutoEaseG.DEVICE.wait_for_keyword(keyword, log_file_path, timeout=timeout, is_rematch=is_rematch, opfunc=opfunc)
[docs]@auto_put_step
def assert_log_exist(keyword, log_file_path=None, timeout=20, is_rematch=False, opfunc=None, **kwargs):
"""Monitor new input to the log file and search for keywords.
A test step will be automatically added for this operation
----
Args:
keyword(string):
The keywords to look for
timeout(float):
maximum time of monitoring in seconds
is_rematch(Boolean):
If True, look for keywords by regular expression.
If False, look for the exact given keywords
opfunc(function):
The function to be excuted when keywords appear in the log file
Returns:
String:
The entire line of the log where the keywords are found.
Raises:
TargetNotFoundError:
if no log input contains the given keywords before timeout
Examples:
>>> assert_log_exist("LogWorld: Bringing World /Game/Provisional/QA/Maps/Smoke_01/Smoke_01.Smoke_01", timeout=20, is_rematch=False, opfunc=mouse_click)
>>> "[2023.04.03-03.49.18:825][816]LogWorld: Bringing World /Game/Provisional/QA/Maps/Smoke_01/Smoke_01.Smoke_01 up for play (max tick rate 0) at 2023.04.03-11.49.18"
or
>>> assert_log_exist("LogWorld: Bringing World /Game/Provisional/QA/Maps/Smoke_01/Smoke_01.Smoke_01", timeout=20, is_rematch=False, opfunc=mouse_click)
>>> Traceback (most recent call last):
>>> ...
>>> TargetNotFoundError: Log keyword ... not found in ...:
"""
res = AutoEaseG.DEVICE.wait_for_keyword(keyword, log_file_path, timeout=timeout, is_rematch=is_rematch, opfunc=opfunc)
if res is False:
raise TargetNotFoundError(f"Log keyword {keyword} not found in {AutoEaseG.LOG_PATH}")
return res
[docs]@auto_put_step
def fail(message: str = "This case has failed!", **kwargs):
"""Raise an error with the given message.
A test step will be automatically added for this operation
----
Args:
message(string): The error message to be raised with, defaults to "This case has failed!"
Returns:
None
Raises:
RuntimeError: when the function is called
Examples:
>>> fail("The armor is not reduced!")
>>> Traceback (most recent call last):
>>> ...
>>> RuntimeError: The armor is not reduced!:
"""
raise RuntimeError(message)
[docs]@auto_put_step
def success(message: str = "This case has succeed!", **kwargs):
"""This function can be used to add a "success" test step
Returns:
None
Examples:
>>> success("The armor is reduced!")
"""
pass
[docs]class AUTOEASE_PARAMS():
MODE = "mode"
RECORD_ID = "record_id"
GAME_PATH = "game_path"
PLATFORM = "platform"
[docs]def get_params(key: str, **kwargs):
t_d = {
AUTOEASE_PARAMS.RECORD_ID: AutoEaseG.RECORD_ID,
AUTOEASE_PARAMS.MODE: AutoEaseG.MODE,
AUTOEASE_PARAMS.GAME_PATH: AutoEaseG.DEVICE.get_game_path,
AUTOEASE_PARAMS.PLATFORM: AutoEaseG.PLATFORM
}
return t_d.get(key, None)
[docs]def get_device_info(**kwargs) -> dict:
cpu_info = cpuinfo.get_cpu_info()
mem = psutil.virtual_memory()
gpus = GPUtil.getGPUs()
cpu_name = cpu_info['brand_raw']
mem_total_gb = round(mem.total / (1024 ** 3))
gpu_name = gpus[0].name
gpu_mem_total = round(gpus[0].memoryTotal / 1024)
res_dict = {
"platform": 'Win64',
"memory_total": mem_total_gb,
"cpu_name": cpu_name,
"gpu_name": gpu_name,
"gpu_mem_total": gpu_mem_total,
}
return res_dict
if __name__ == '__main__':
pass