Public class

class atx.drivers.Pattern(name, image=None, offset=None, anchor=0, rsl=None, resolution=None, th=None, threshold=None)[source]
save(path)[source]

save image to path

Common methods

class atx.drivers.mixin.DeviceMixin[source]
add_listener(fn, event_flags)[source]

Listen event Args:

  • fn: function call when event happends
  • event_flags: for example
    EVENT_UIAUTO_CLICK | EVENT_UIAUTO_SWIPE
Returns:
None
click(x, y)[source]
Args:
x, y (float): position to tap
Example:

if x, y both less than 1.0. then x, y means percentage position

d.click(0.5, 0.5) # click center of screen d.click(20, 10) # click position(20, 10)
click_exists(*args, **kwargs)[source]

Click when target exists Example usage:

  • click_exists(“button.png”)
  • click_exists(text=”Update”)
click_image(**kwargs)[source]

Simulate click according image position

Args:
  • pattern (str or Pattern): filename or an opencv image object.
  • timeout (float): if image not found during this time, ImageNotFoundError will raise.
  • action (str): click or long_click
  • safe (bool): if safe is True, Exception will not raise and return None instead.
  • method (str): image match method, choice of <template|sift>
  • delay (float): wait for a moment then perform click
Returns:
None
Raises:
ImageNotFoundError: An error occured when img not found in current screen.
click_nowait(**kwargs)[source]

Return immediately if no image found

Args:
  • pattern (str or Pattern): filename or an opencv image object.
  • action (str): click or long_click
Returns:
Click point or None
delay(secs)[source]

Delay some seconds Args:

secs: float seconds
Returns:
self
exists(pattern, **match_kwargs)[source]

Check if image exists in screen

Returns:
If exists, return FindPoint, or return None if result.confidence < self.image_match_threshold
free_screen()[source]

Unlock keep_screen()

keep_screen()[source]

Freese screenshot, so all image functions will not take images, until call free_screen()

match(pattern, screen=None, rect=None, offset=None, threshold=None, method=None)[source]

Check if image position in screen

Args:
  • pattern: Image file name or opencv image object
  • screen (PIL.Image): optional, if not None, screenshot method will be called
  • threshold (float): it depends on the image match method
  • method (string): choices on <template | sift>
Returns:

None or FindPoint, For example:

FindPoint(pos=(20, 30), method=’tmpl’, confidence=0.801, matched=True)

Only when confidence > self.image_match_threshold, matched will be True

Raises:
TypeError: when image_match_method is invalid
match_all(pattern)[source]

Test method, not suggested to use

region(bounds)[source]

Set region of the screen area Args:

bounds: Bounds object
Returns:
A new AndroidDevice object
Raises:
TypeError
region_screenshot(filename=None)[source]

Deprecated Take part of the screenshot

screenshot(**kwargs)[source]

Take screen snapshot

Args:
  • filename: filename where save to, optional
Returns:
PIL.Image object
Raises:
TypeError, IOError
touch(x, y)[source]

Alias for click

touch_image(*args, **kwargs)[source]

ALias for click_image

wait(pattern, timeout=10.0, safe=False, **match_kwargs)[source]

Wait till pattern is found or time is out (default: 10s).

Method only for android

class atx.drivers.android.AndroidDevice(serial=None, **kwargs)[source]
serial

Android device serial number. Optional

adb_cmd(command, **kwargs)[source]

Run adb command, for example: adb([‘pull’, ‘/data/local/tmp/a.png’])

Args:
command: string or list of string
Returns:
command output
adb_shell(*args)[source]

Run adb shell command

Args:
args: string or list of string
Returns:
command output
clear_text(count=100)[source]

Clear text Args:

  • count (int): send KEY_DEL count
current_app()[source]

Get current app (package, activity) Returns:

Return: dict(package, activity, pid?)
Raises:
RuntimeError
current_ime()[source]

Get current input method

display

Virtual keyborad may get small d.info[‘displayHeight’]

do_tap(x, y)[source]

Touch specify position

Args:
x, y: int
Returns:
None
dump_nodes()[source]

Dump current screen UI to list Returns:

List of UINode object, For example:

[UINode(
bounds=Bounds(left=0, top=0, right=480, bottom=168), checkable=False, class_name=’android.view.View’, text=’‘, resource_id=’‘, package=’com.sonyericsson.advancedwidget.clock’)]
dump_view()[source]

Current Page XML

forward(device_port, local_port=None)[source]

Forward device port to local Args:

device_port: port inside device local_port: port on PC, if this value is None, a port will random pick one.
Returns:
tuple, (host, local_port)
input_methods()[source]

Get all input methods

Return example: [‘com.sohu.inputmethod.sogou/.SogouIME’, ‘android.unicode.ime/.Utf7ImeService’]

is_app_alive(package_name)[source]

Deprecated: use current_package_name instaed. Check if app in running in foreground

keyevent(keycode)[source]

call adb shell input keyevent ${keycode}

Args:
  • keycode(string): for example, KEYCODE_ENTER

keycode need reference: http://developer.android.com/reference/android/view/KeyEvent.html

properties

Android Properties, extracted from adb shell getprop

Returns:

dict of props, for example:

{‘ro.bluetooth.dun’: ‘true’}
raw_cmd(*args, **kwargs)[source]

Return subprocess.Process instance

rotation

Rotaion of the phone

0: normal 1: home key on the right 2: home key on the top 3: home key on the left

serial

Android Device Serial Number

source(*args, **kwargs)[source]

Dump page xml

start_app(package_name, activity=None, stop=False)[source]

Start application

Args:
  • package_name (string): like com.example.app1
  • activity (string): optional, activity name

Returns time used (unit second), if activity is not None

Document: usage: adb shell am start

-D: enable debugging -W: wait for launch to complete –start-profiler <FILE>: start profiler and send results to <FILE> –sampling INTERVAL: use sample profiling with INTERVAL microseconds

between samples (use with –start-profiler)

-P <FILE>: like above, but profiling stops when app goes idle -R: repeat the activity launch <COUNT> times. Prior to each repeat,

the top activity will be finished.

-S: force stop the target app before starting the activity –opengl-trace: enable tracing of OpenGL functions –user <USER_ID> | current: Specify which user to run as; if not

specified then run as the current user.
stop_app(package_name, clear=False)[source]

Stop application

Args:
package_name: string like com.example.app1 clear: bool, remove user data
Returns:
None
type(s, enter=False, clear=False)[source]

Input some text, this method has been tested not very stable on some device. “Hi world” maybe spell into “H iworld”

Args:
  • s: string (text to input), better to be unicode
  • enter(bool): input enter at last
  • next(bool): perform editor action Next
  • clear(bool): clear text before type
  • ui_select_kwargs(**): tap then type

The android source code show that space need to change to %s insteresting thing is that if want to input %s, it is really unconvinent. android source code can be found here. https://android.googlesource.com/platform/frameworks/base/+/android-4.4.2_r1/cmds/input/src/com/android/commands/input/Input.java#159 app source see here: https://github.com/openatx/android-unicode

uiautomator
Returns:
uiautomator: Device object describes in https://github.com/openatx/atx-uiautomator
wlan_ip

Wlan IP

Method only for windows