airtest.core.win.win module

require_app(func)[source]
class Windows(handle=None, dpifactor=1, **kwargs)[source]

Bases: airtest.core.device.Device

Windows client.

uuid
connect(handle=None, **kwargs)[source]

Connect to window and set it foreground

Parameters:**kwargs – optional arguments
Returns:None
shell(cmd)[source]

Run shell command in subprocess

Parameters:cmd – command to be run
Raises:subprocess.CalledProcessError – when command returns non-zero exit status
Returns:command output as a byte string
snapshot(filename=None, quality=10, max_size=None)[source]

Take a screenshot and save it in ST.LOG_DIR folder

Parameters:
  • filename – name of the file to give to the screenshot, {time}.jpg by default
  • quality – The image quality, integer in range [1, 99]
  • max_size – the maximum size of the picture, e.g 1200
Returns:

display the screenshot

keyevent(keyname, **kwargs)[source]

Perform a key event

References

https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html

Parameters:
  • keyname – key event
  • **kwargs – optional arguments
Returns:

None

text(text, **kwargs)[source]

Input text

Parameters:
  • text – text to input
  • **kwargs – optional arguments
Returns:

None

key_press(key)[source]

Simulates a key press event.

Sends a scancode to the computer to report which key has been pressed. Some games use DirectInput devices, and respond only to scancodes, not virtual key codes. You can simulate DirectInput key presses using this method, instead of the keyevent() method, which uses virtual key codes.

Parameters:key – A string indicating which key to be pressed. Available key options are: {‘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)[source]

Simulates a key release event.

Sends a scancode to the computer to report which key has been released. Some games use DirectInput devices, and respond only to scancodes, not virtual key codes. You can simulate DirectInput key releases using this method. A call to the key_release() method usually follows a call to the key_press() method of the same key.

Parameters:key – A string indicating which key to be released.
touch(pos, **kwargs)[source]

Perform mouse click action

References

https://pywinauto.readthedocs.io/en/latest/code/pywinauto.mouse.html

Parameters:
  • pos – coordinates where to click
  • **kwargs – optional arguments
Returns:

None

double_click(pos)[source]
swipe(p1, p2, duration=0.8, steps=5, button='left')[source]

Perform swipe (mouse press and mouse release)

Parameters:
  • p1 – start point
  • p2 – end point
  • duration – time interval to perform the swipe action
  • steps – size of the swipe step
  • button – mouse button to press, ‘left’, ‘right’ or ‘middle’, default is ‘left’
Returns:

None

mouse_move(pos)[source]

Simulates a mousemove event.

Known bug:
Due to a bug in the pywinauto module, users might experience off-by-one errors when it comes to the exact coordinates of the position on screen.
Parameters:pos – A tuple (x, y), where x and y are x and y coordinates of the screen to move the mouse to, respectively.
mouse_down(button='left')[source]

Simulates a mousedown event.

Parameters:button – A string indicating which mouse button to be pressed. Available mouse button options are: {‘left’, ‘middle’, ‘right’}.
mouse_up(button='left')[source]

Simulates a mouseup event.

A call to the mouse_up() method usually follows a call to the mouse_down() method of the same mouse button.

Parameters:button – A string indicating which mouse button to be released.
start_app(path, *args, **kwargs)[source]

Start the application

Parameters:
Returns:

None

stop_app(pid)[source]

Stop the application

Parameters:pid – process ID of the application to be stopped
Returns:None
set_foreground()[source]

Bring the window foreground

Returns:None
set_focus()

Bring the window foreground

Returns:None
get_rect()[source]

Get rectangle

Returns:win32structures.RECT
get_title()[source]

Get the window title

Returns:window title
get_pos()[source]

Get the window position coordinates

Returns:coordinates of topleft corner of the window (left, top)
move(pos)[source]

Move window to given coordinates

Parameters:pos – coordinates (x, y) where to move the window
Returns:None
kill()[source]

Kill the application

Returns:None
focus_rect
get_current_resolution()[source]
get_ip_address()[source]

Return default external ip address of the windows os.

Returns:ip address
Return type:str
start_recording(max_time=1800, output=None, fps=10, snapshot_sleep=0.001, orientation=0, max_size=None, *args, **kwargs)[source]

Start recording the device display

Parameters:
  • 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.
Returns:

path of video file

Return type:

save_path

Examples

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)

Note

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.

stop_recording()[source]

Stop recording the device display. Recoding file will be kept in the device.