airtest.core.win.win module¶
-
class
Windows
(handle=None, dpifactor=1, **kwargs)[源代码]¶ -
Windows 客户端。
-
uuid
¶
-
shell
(cmd)[源代码]¶ 在subprocess里运行命令行
参数: cmd – 需要运行的命令行 Raises: subprocess.CalledProcessError
– when command returns non-zero exit status返回: 命令行的输出内容作为bytes string返回
-
snapshot
(filename=None, quality=10, max_size=None)[源代码]¶ 截取一张图片并且保存到ST.LOG_DIR文件夹中
参数: - filename – 截图的文件名,默认为{time}.jpg
- quality – The image quality, integer in range [1, 99]
- max_size – the maximum size of the picture, e.g 1200
返回: 截图的内容
-
keyevent
(keyname, **kwargs)[源代码]¶ 执行一个按键响应
References
https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html
参数: - keyname – key event
- **kwargs – optional arguments
返回: None
-
key_press
(key)[源代码]¶ 模拟一个按下按键的事件。
发送键盘扫描码至计算机来告知哪个按键被按下。一些游戏使用DirectInput设备,只响应键盘扫描码,而不是虚拟键码。可以用key_press()方法来模拟发送键盘扫描码,而不是上述发送虚拟键码的keyevent()方法。
参数: key – 一个字符串来表示哪个按键将被按下。可用的选择有:{‘ESCAPE’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘0’, ‘-’, ‘=’, ‘BACKSPACE’, ‘TAB’, ‘Q’, ‘W’, ‘E’, ‘R’, ‘T’, ‘Y’, ‘U’, ‘I’, ‘O’, ‘P’, ‘[’, ‘]’, ‘ENTER’, ‘LCTRL’, ‘A’, ‘S’, ‘D’, ‘F’, ‘G’, ‘H’, ‘J’, ‘K’, ‘L’, ‘;’, “’”, ‘`’, ‘LSHIFT’, ‘BACKSLASH’, ‘Z’, ‘X’, ‘C’, ‘V’, ‘B’, ‘N’, ‘M’, ‘,’, ‘.’, ‘/’, ‘RSHIFT’, ‘*’, ‘LALT’, ‘SPACE’, ‘CAPS_LOCK’, ‘F1’, ‘F2’, ‘F3’, ‘F4’, ‘F5’, ‘F6’, ‘F7’, ‘F8’, ‘F9’, ‘F10’, ‘NUM_LOCK’, ‘SCROLL_LOCK’, ‘NUMPAD_7’, ‘NUMPAD_8’, ‘NUMPAD_9’, ‘NUMPAD_-’, ‘NUMPAD_4’, ‘NUMPAD_5’, ‘NUMPAD_6’, ‘NUMPAD_+’, ‘NUMPAD_1’, ‘NUMPAD_2’, ‘NUMPAD_3’, ‘NUMPAD_0’, ‘NUMPAD_.’, ‘F11’, ‘F12’, ‘PRINT_SCREEN’, ‘PAUSE’, ‘NUMPAD_ENTER’, ‘RCTRL’, ‘NUMPAD_/’, ‘RALT’, ‘HOME’, ‘UP’, ‘PAGE_UP’, ‘LEFT’, ‘RIGHT’, ‘END’, ‘DOWN’, ‘PAGE_DOWN’, ‘INSERT’, ‘DELETE’, ‘LWINDOWS’, ‘RWINDOWS’, ‘MENU’}.
-
key_release
(key)[源代码]¶ 模拟一个释放按键的事件。
发送键盘扫描码至计算机来告知哪个按键被释放。一些游戏使用DirectInput设备,只响应键盘扫描码,而不是虚拟键码。可以用key_release()方法来模拟发送键盘扫描码。一般情况下key_release()方法与所释放按键的key_press()方法搭配使用。
参数: key – 一个字符串来表示哪个按键将被释放。
-
touch
(pos, **kwargs)[源代码]¶ 执行鼠标点击操作
References
https://pywinauto.readthedocs.io/en/latest/code/pywinauto.mouse.html
参数: - pos – 点击位置的坐标
- **kwargs – optional arguments
返回: None
-
swipe
(p1, p2, duration=0.8, steps=5, button='left')[源代码]¶ 执行拖动操作(鼠标按下并且释放)
参数: - p1 – 起始点坐标
- p2 – 终点坐标
- duration – 执行滑动操作的时间间隔
- steps – 滑动操作的步数
- button – mouse button to press, ‘left’, ‘right’ or ‘middle’, default is ‘left’
返回: None
-
mouse_move
(pos)[源代码]¶ 模拟一个移动鼠标的事件。
- 已知的bug:
- 因为pywinauto库存在的bug,用户可能在使用此方法时遇到移动后位置与目标位置的x和y坐标有1个像素点偏差的情况。
参数: pos – 一个(x, y)的tuple, 其中x和y分别表示目标位置在屏幕上的x和y坐标。
-
mouse_down
(button='left')[源代码]¶ 模拟一个按下鼠标按键的事件。
参数: button – 一个字符串来表示将按下哪个鼠标按键。有以下的鼠标按键选项:{‘left’, ‘middle’, ‘right’}。
-
mouse_up
(button='left')[源代码]¶ 模拟一个释放鼠标按键的事件。
一般情况下mouse_up()方法与所释放鼠标按键的mouse_down()方法搭配使用。
参数: button – 一个字符串来表示将释放哪个鼠标按键。
-
start_app
(path, *args, **kwargs)[源代码]¶ 启动应用
参数: - path – 应用的完整路径
- kwargs – reference: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html#pywinauto.application.Application.start
返回: None
-
set_focus
()¶ 将窗口切换到最前
返回: None
-
focus_rect
¶
-
start_recording
(max_time=1800, output=None, fps=10, snapshot_sleep=0.001, orientation=0, max_size=None, *args, **kwargs)[源代码]¶ Start recording the device display
参数: - max_time – maximum screen recording time, default is 1800
- output – ouput file path
- mode – the backend write video, choose in [“ffmpeg”] ffmpeg: ffmpeg-python backend, higher compression rate.
- fps – frames per second will record
- snapshot_sleep – sleep time for each snapshot.
- orientation – 1: portrait, 2: landscape, 0: rotation.
- max_size – max size of the video frame, e.g.800, default is None. Smaller sizes lead to lower system load.
返回: path of video file
返回类型: save_path
实际案例
Record 30 seconds of video and export to the current directory test.mp4:
>>> from airtest.core.api import connect_device, sleep >>> dev = connect_device("Windows:///") >>> save_path = dev.start_recording(output="test.mp4") >>> sleep(30) >>> dev.stop_recording() >>> print(save_path)
You can specify max_size to limit the video’s maximum width/length. Smaller video sizes result in lower CPU load.
>>> dev.start_recording(output="test.mp4", max_size=800)
注解
1 Don’t resize the app window duraing recording, the recording region will be limited by first frame. 2 If recording still working after app crash, it will continuing write last frame before the crash.
-