airtest.core.win.win module¶
-
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 statusReturns: 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
-
swipe
(p1, p2, duration=0.8, steps=5)[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
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, **kwargs)[source]¶ Start the application
Parameters: - path – full path to the application
- kwargs – reference: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html#pywinauto.application.Application.start
Returns: None
-
stop_app
(pid)[source]¶ Stop the application
Parameters: pid – process ID of the application to be stopped Returns: None
-
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
-
focus_rect
¶
-