uiautomator

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 15 Imported by: 0

README

This is a simple golang wrapper for working uiautomator.

Setup

To install this library, simple:

go get -u github.com/trazyn/uiautomator-go

Import the package:

import ug "github.com/trazyn/uiautomator-go"

Quick start

First, let yours mobile and PC join the same network.

ua := ug.New(&ug.Config{
    Host: "10.10.20.78",
    Port: 7912,
})

ua.Unlock()

// Show toast
toast := ua.NewToast()
toast.Show("hallo world", 10)

https://github.com/openatx/uiautomator2#basic-api-usages

Documentation

Overview

* https://github.com/openatx/uiautomator2#app-management

* Device api related https://github.com/openatx/uiautomator2#retrieve-the-device-info

* Gesture interaction with the device https://github.com/openatx/uiautomator2#gesture-interaction-with-the-device

* https://github.com/openatx/uiautomator2#input-method

* Screen api related https://github.com/openatx/uiautomator2#screen-related

* Selector is a handy mechanism to identify a specific UI object in the current window. https://github.com/openatx/uiautomator2#selector

* https://github.com/openatx/uiautomator2#toast

* https://github.com/openatx/uiautomator2#watcher

Index

Constants

View Source
const (
	ORIENTATION_RIGHT      = "right"
	ORIENTATION_LEFT       = "left"
	ORIENTATION_NATURAL    = "natural"
	ORIENTATION_UPSIDEDOWN = "upsidedown"
)
View Source
const (
	VERSION  = "0.0.1"
	BASE_URL = "/jsonrpc/0"

	TIMEOUT                      = 30  // Default timeout(second)
	AUTO_RETRY                   = 5   // Default retry times
	RETRY_DURATION               = 3   // Default retry duration
	WAIT_FOR_EXISTS_MAX_RETRY    = 3   // Default WaitForExistsMaxRetry
	WAIT_FOR_EXISTS_DURATION     = 0.3 // Default WaitForExistsDuration
	WAIT_FOR_DISAPPEAR_MAX_RETRY = 3   // Default WaitForDisappearMaxRetry
	WAIT_FOR_DISAPPEAR_DURATION  = 0.3 // Default WaitForDisappearDuration
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppInfo

type AppInfo struct {
	Activity string `json:"activity"`
	Package  string `json:"package"`
}

type Config

type Config struct {
	Host                     string  // Server host
	Port                     int     // Server port
	Timeout                  int     // Timeout(second)
	AutoRetry                int     // Auto retry times, 0 is without retry
	RetryDuration            int     // Retry duration(second)
	WaitForExistsDuration    float32 // Unit second
	WaitForExistsMaxRetry    int     // Max retry times
	WaitForDisappearDuration float32 // Unit second
	WaitForDisappearMaxRetry int     // Max retry times
}

type DeviceInfo

type DeviceInfo struct {
	CurrentPackageName string `json:"currentPackageName"`
	DisplayHeight      int    `json:"displayHeight"`
	DisplayWidth       int    `json:"displayWidth"`
	DisplayRotation    int    `json:"displayRotation"`
	DisplaySizeDpX     int    `json:"displaySizeDpX"`
	DisplaySizeDpY     int    `json:"displaySizeDpY"`
	ProductName        string `json:"productName"`
	ScreenOn           bool   `json:"screenOn"`
	SdkInt             int    `json:"sdkInt"`
	NaturalOrientation bool   `json:"naturalOrientation"`
}

type Element

type Element struct {
	// contains filtered or unexported fields
}

func (Element) Center

func (ele Element) Center(offset *Position) (*Position, error)

Get Widget center point

func (Element) Child

func (ele Element) Child(selector Selector) *Element

Get the children or grandchildren

func (*Element) ChildByDescription

func (ele *Element) ChildByDescription(keywords string, selector Selector) (*Element, error)

func (*Element) ChildByText

func (ele *Element) ChildByText(keywords string, selector Selector) (*Element, error)

func (Element) ClearText

func (ele Element) ClearText() error

Clear the widget text

func (*Element) Click

func (ele *Element) Click(offset *Position) error

Click on the screen

func (*Element) ClickNoWait added in v1.0.3

func (ele *Element) ClickNoWait(offset *Position) error

func (Element) Clone added in v0.0.4

func (ele Element) Clone() *Element

Clone the element

func (Element) Count

func (ele Element) Count() (int, error)

Get the count

func (Element) Eq

func (ele Element) Eq(index int) *Element

Get the instance via index

func (Element) GetInfo

func (ele Element) GetInfo() (*ElementInfo, error)

Get element info

func (Element) GetRect

func (ele Element) GetRect() (rect *ElementRect, err error)

Get Widget rect bounds

func (Element) GetText

func (ele Element) GetText() (string, error)

Get widget text

func (Element) GetTextNoWait added in v1.0.3

func (ele Element) GetTextNoWait() (string, error)

func (*Element) LongClick

func (ele *Element) LongClick() error

Long click on the element

func (*Element) ScrollDown added in v0.0.1

func (ele *Element) ScrollDown(step int) error

Screen scroll down

func (*Element) ScrollTo added in v0.0.1

func (ele *Element) ScrollTo(selector Selector) error

Screen scroll to selector

func (*Element) ScrollToBeginning added in v0.0.2

func (ele *Element) ScrollToBeginning() error

Screen scroll to beginning

func (*Element) ScrollToEnd added in v0.0.1

func (ele *Element) ScrollToEnd() error

Screen scroll to end

func (*Element) ScrollUp added in v0.0.1

func (ele *Element) ScrollUp(step int) error

Screen scroll up

func (Element) SetText

func (ele Element) SetText(text string) error

Set widget text

func (*Element) Sibling

func (ele *Element) Sibling(selector Selector) (*Element, error)

Get the sibling

func (*Element) SwipeDown

func (ele *Element) SwipeDown() error

Swipe to down

func (*Element) SwipeLeft

func (ele *Element) SwipeLeft() error

Swipe to left

func (*Element) SwipeRight

func (ele *Element) SwipeRight() error

Swipe to right

func (*Element) SwipeUp

func (ele *Element) SwipeUp() error

Swipe to up

func (Element) WaitForExists

func (ele Element) WaitForExists(duration float32, maxRetry int) error

Check if the specific UI object exists

func (Element) WaitUntilGone added in v1.0.0

func (ele Element) WaitUntilGone(duration float32, maxRetry int) error

Wait the specific UI object disappear

type ElementInfo

type ElementInfo struct {
	ContentDescription string       `json:"contentDescription"`
	Checked            bool         `json:"checked"`
	Scrollable         bool         `json:"scrollable"`
	Text               string       `json:"text"`
	PackageName        string       `json:"packageName"`
	Selected           bool         `json:"selected"`
	Enabled            bool         `json:"enabled"`
	ClassName          string       `json:"className"`
	Focused            bool         `json:"focused"`
	Focusable          bool         `json:"focusable"`
	Clickable          bool         `json:"clickable"`
	ChileCount         int          `json:"chileCount"`
	LongClickable      bool         `json:"longClickable"`
	Checkable          bool         `json:"checkable"`
	Bounds             *ElementRect `json:"bounds"`
	VisibleBounds      *ElementRect `json:"visibleBounds"`
}

type ElementRect

type ElementRect struct {
	Bottom int `json:"bottom"`
	Left   int `json:"left"`
	Right  int `json:"right"`
	Top    int `json:"top"`
}

type GatewayError

type GatewayError struct {
	Message string
}

func (*GatewayError) Error

func (err *GatewayError) Error() string

type ORIENTATION

type ORIENTATION string

type Position

type Position struct {
	X float32
	Y float32
}

func (*Position) String

func (pos *Position) String() string

type RPCOptions

type RPCOptions struct {
	URL    string
	Method string
	Params []interface{}
}

type Screenshot

type Screenshot struct {
	Type   string
	Base64 string
}

type Selector

type Selector map[string]interface{}

type SessionError

type SessionError struct {
	Message string
}

func (*SessionError) Error

func (err *SessionError) Error() string

type Toast

type Toast struct {
	// contains filtered or unexported fields
}

func (*Toast) GetMessage

func (t *Toast) GetMessage(timeout float32, cachedTime float32, fallback string) (string, error)

Get the toast message TODO: method "getLastToast" not work

func (*Toast) Reset

func (t *Toast) Reset(message string, duration float32) error

Reset the toast cache TODO: method "getLastToast" not work

func (*Toast) Show

func (t *Toast) Show(message string, duration float32) error

Show toast

type UIAutomator

type UIAutomator struct {
	// contains filtered or unexported fields
}

func New

func New(config *Config) *UIAutomator

func (*UIAutomator) AppInstall

func (ua *UIAutomator) AppInstall(url string) error

Install an app TODO: api "/install" not work

func (*UIAutomator) AppStart

func (ua *UIAutomator) AppStart(packageName string) error

Launch app

func (*UIAutomator) AppStop

func (ua *UIAutomator) AppStop(packageName string) error

Stop app

func (*UIAutomator) Click

func (ua *UIAutomator) Click(position *Position) error

Click on the screen

func (*UIAutomator) DbClick

func (ua *UIAutomator) DbClick(position *Position, duration float32) error

Double click on the screen

func (*UIAutomator) Drag

func (ua *UIAutomator) Drag(start *Position, end *Position, duration float32) error

Swipe the screen

func (*UIAutomator) DumpWindowHierarchy

func (ua *UIAutomator) DumpWindowHierarchy() (string, error)

* Get the UI hierarchy dump content (unicoded).

func (*UIAutomator) FreezeRotation

func (ua *UIAutomator) FreezeRotation(freeze bool) error

Freeze rotation

func (UIAutomator) GetConfig added in v0.0.1

func (ua UIAutomator) GetConfig() *Config

func (*UIAutomator) GetCurrentApp

func (ua *UIAutomator) GetCurrentApp() (info *AppInfo, err error)

Get current app info

func (*UIAutomator) GetDeviceInfo

func (ua *UIAutomator) GetDeviceInfo() (*DeviceInfo, error)

Get basic information

func (*UIAutomator) GetElementBySelector

func (ua *UIAutomator) GetElementBySelector(selector Selector) (ele *Element)

Query the UI element by selector

func (*UIAutomator) GetScreenshot

func (ua *UIAutomator) GetScreenshot() (*Screenshot, error)

func (*UIAutomator) GetSerialNumber

func (ua *UIAutomator) GetSerialNumber() (string, error)

Get device serial number

func (*UIAutomator) GetWindowSize

func (ua *UIAutomator) GetWindowSize() (*WindowSize, error)

Get window size

func (*UIAutomator) IsSleep

func (ua *UIAutomator) IsSleep() (res bool, err error)

Check device is sleep

func (*UIAutomator) IsWakeUp

func (ua *UIAutomator) IsWakeUp() (res bool, err error)

Check device is wakeup

func (*UIAutomator) LongClick

func (ua *UIAutomator) LongClick(position *Position, duration float32) error

Long click on the screen

func (*UIAutomator) NewToast

func (ua *UIAutomator) NewToast() *Toast

Create toast

func (*UIAutomator) OpenNotification

func (ua *UIAutomator) OpenNotification() error

* Open notification

func (*UIAutomator) OpenQuickSettings

func (ua *UIAutomator) OpenQuickSettings() error

* Open quick settings

func (*UIAutomator) Ping

func (ua *UIAutomator) Ping() (status string, err error)

func (*UIAutomator) Press

func (ua *UIAutomator) Press(key string) error

Press key

func (*UIAutomator) PressKeyCode

func (ua *UIAutomator) PressKeyCode(key int, meta interface{}) error

Press key code

func (*UIAutomator) SendAction

func (ua *UIAutomator) SendAction(code interface{}) error

func (*UIAutomator) SetFastinputIME

func (ua *UIAutomator) SetFastinputIME(enable bool) error

func (*UIAutomator) SetOrientationLeft

func (ua *UIAutomator) SetOrientationLeft() error

Set orientation left

func (*UIAutomator) SetOrientationNatural

func (ua *UIAutomator) SetOrientationNatural() error

Set orientation natural

func (*UIAutomator) SetOrientationRight

func (ua *UIAutomator) SetOrientationRight() error

Set orientation right

func (*UIAutomator) SetOrientationUpsidedown

func (ua *UIAutomator) SetOrientationUpsidedown() error

Set orientation upsidedown(not worked)

func (*UIAutomator) Shell

func (ua *UIAutomator) Shell(command []string, timeout int) (output string, err error)

func (*UIAutomator) Sleep

func (ua *UIAutomator) Sleep() error

Trun off the screen

func (*UIAutomator) Swipe

func (ua *UIAutomator) Swipe(from *Position, to *Position, step int) error

Swipe the screen

func (*UIAutomator) SwipePoints added in v0.0.3

func (ua *UIAutomator) SwipePoints(points ...*Position) error

Swipe by points, unlock the gesture login

func (*UIAutomator) Unlock

func (ua *UIAutomator) Unlock() error

Unblock the device

func (*UIAutomator) WakeUp

func (ua *UIAutomator) WakeUp() error

Trun on the screen

func (*UIAutomator) Watchman added in v1.0.5

func (ua *UIAutomator) Watchman() *Watcher

Create a watcher

type UiaError

type UiaError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*UiaError) Error

func (err *UiaError) Error() string

type Watcher added in v1.0.5

type Watcher struct {
	// contains filtered or unexported fields
}

func (*Watcher) Click added in v1.0.5

func (watcher *Watcher) Click(selector Selector) error

Listener has triggered and click the target

func (*Watcher) Register added in v1.0.5

func (watcher *Watcher) Register(name string, selector Selector) *Watcher

Add trigger condition

func (*Watcher) Remove added in v1.0.5

func (watcher *Watcher) Remove(name string) *Watcher

Remove watcher

type WindowSize

type WindowSize struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL