gwda

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: MIT Imports: 21 Imported by: 14

README

Golang-WDA

go doc go report license

appium/WebDriverAgent Client Library in Golang

Android can use electricbubble/guia2

English | 🇨🇳中文

Installation

First, install WebDriverAgent for iOS devices

go get github.com/electricbubble/gwda

QuickStart

Connection Device
package main

import (
	"github.com/electricbubble/gwda"
	"log"
)

func main() {
	// var urlPrefix = "http://localhost:8100"
	// The function may also require 'iproxy 8100 8100' to forward the device port first
	// driver, _ := gwda.NewDriver(nil, urlPrefix)

	// Connect devices via USB
	driver, _ := gwda.NewUSBDriver(nil)

	log.Println(driver.IsWdaHealthy())
}

Touch
package main

import (
	"github.com/electricbubble/gwda"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	x, y := 50, 256

	driver.Tap(x, y)

	driver.DoubleTap(x, y)

	driver.TouchAndHold(x, y)

	fromX, fromY, toX, toY := 50, 256, 100, 256

	driver.Drag(fromX, fromY, toX, toY)

	driver.Swipe(fromX, fromY, toX, toY)

	// requires hardware support: 3D Touch 
	// driver.ForceTouch(x, y, 0.8)
}

AssistiveTouch driver.PerformW3CActions driver.PerformAppiumTouchActions

App Actions
package main

import (
	"github.com/electricbubble/gwda"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	var bundleId = "com.apple.Preferences"

	driver.AppLaunchUnattached(bundleId)

	driver.AppDeactivate(2)

	driver.AppTerminate(bundleId)

	driver.AppActivate(bundleId)

	// Resets the 📷 camera authorization status of the current application
	// driver.AppAuthReset(gwda.ProtectedResourceCamera)
}

Keyboard
package main

import (
	"github.com/electricbubble/gwda"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	driver.SendKeys("hello")
}

specified element element.SendKeys

Siri
package main

import (
	"github.com/electricbubble/gwda"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	driver.SiriActivate("What's the weather like today")
}

Alert
package main

import (
	"github.com/electricbubble/gwda"
	"log"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	text, _ := driver.AlertText()
	log.Println(text)

	alertButtons, _ := driver.AlertButtons()
	log.Println(alertButtons)

	driver.AlertAccept()
	// driver.AlertDismiss()

	// driver.SendKeys("ah")
}

Device information
package main

import (
	"github.com/electricbubble/gwda"
	"log"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	deviceInfo, _ := driver.DeviceInfo()
	log.Println(deviceInfo.Name)

	batteryInfo, _ := driver.BatteryInfo()
	log.Println(batteryInfo.State)

	windowSize, _ := driver.WindowSize()
	log.Println(windowSize)

	location, err := driver.Location()
	if err != nil {
		log.Fatalln(err)
	}
	log.Println(location)

	// screen, _ := driver.Screen()
	// log.Println(screen)
}

Hardware button
package main

import (
	"github.com/electricbubble/gwda"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	// driver.Homescreen()

	driver.PressButton(gwda.DeviceButtonHome)
	driver.PressButton(gwda.DeviceButtonVolumeUp)
	driver.PressButton(gwda.DeviceButtonVolumeDown)
}

Screenshot
package main

import (
	"github.com/electricbubble/gwda"
	"image"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	screenshot, _ := driver.Screenshot()

	img, format, _ := image.Decode(screenshot)
	_, _ = img, format
}

Debug
package main

import (
	"fmt"
	"github.com/electricbubble/gwda"
)

func main() {
	driver, _ := gwda.NewUSBDriver(nil)

	source, _ := driver.Source()
	fmt.Println(source)

	// fmt.Println(driver.AccessibleSource())

	// gwda.SetDebug(true)
}

Extensions

About
electricbubble/gwda-ext-opencv Operate with pictures

Alternatives

About
openatx/facebook-wda Facebook WebDriverAgent Python Client Library (not official)

Thanks

Thank you JetBrains for providing free open source licenses

Documentation

Index

Constants

View Source
const (
	TextBackspace string = "\u0008"
	TextDelete    string = "\u007F"
)

Variables

View Source
var (
	DefaultWaitTimeout  = 60 * time.Second
	DefaultWaitInterval = 400 * time.Millisecond

	DefaultKeepAliveInterval = 30 * time.Second
)
View Source
var HTTPClient = http.DefaultClient

HTTPClient The default client to use to communicate with the WebDriver server.

Functions

func SetDebug added in v0.1.0

func SetDebug(debug bool)

SetDebug sets debug mode

Types

type AlertAction added in v0.1.0

type AlertAction string
const (
	AlertActionAccept  AlertAction = "accept"
	AlertActionDismiss AlertAction = "dismiss"
)

type AppBaseInfo added in v0.1.0

type AppBaseInfo struct {
	Pid      int    `json:"pid"`
	BundleId string `json:"bundleId"`
}

type AppInfo added in v0.1.0

type AppInfo struct {
	ProcessArguments struct {
		Env  interface{}   `json:"env"`
		Args []interface{} `json:"args"`
	} `json:"processArguments"`
	Name string `json:"name"`
	AppBaseInfo
}

type AppLaunchOption added in v0.1.0

type AppLaunchOption map[string]interface{}

AppLaunchOption Configure app launch parameters

func NewAppLaunchOption added in v0.1.0

func NewAppLaunchOption() AppLaunchOption

func (AppLaunchOption) WithArguments added in v0.1.0

func (opt AppLaunchOption) WithArguments(args []string) AppLaunchOption

WithArguments The optional array of application command line arguments. The arguments are going to be applied if the application was not running before.

func (AppLaunchOption) WithBundleId added in v0.1.0

func (opt AppLaunchOption) WithBundleId(bundleId string) AppLaunchOption

func (AppLaunchOption) WithEnvironment added in v0.1.0

func (opt AppLaunchOption) WithEnvironment(env map[string]string) AppLaunchOption

WithEnvironment The optional dictionary of environment variables for the application, which is going to be executed. The environment variables are going to be applied if the application was not running before.

func (AppLaunchOption) WithShouldWaitForQuiescence added in v0.1.0

func (opt AppLaunchOption) WithShouldWaitForQuiescence(b bool) AppLaunchOption

WithShouldWaitForQuiescence whether to wait for quiescence on application startup

Defaults to `true`

type AppState added in v0.1.0

type AppState int
const (
	AppStateNotRunning AppState = 1 << iota
	AppStateRunningBack
	AppStateRunningFront
)

func (AppState) String added in v0.1.0

func (v AppState) String() string

type BatteryInfo added in v0.1.0

type BatteryInfo struct {
	// Battery level in range [0.0, 1.0], where 1.0 means 100% charge.
	Level float64 `json:"level"`

	// Battery state ( 1: on battery, discharging; 2: plugged in, less than 100%, 3: plugged in, at 100% )
	State BatteryState `json:"state"`
}

type BatteryState added in v0.1.0

type BatteryState int
const (
	BatteryStateUnplugged BatteryState = iota // on battery, discharging
	BatteryStateCharging                      // plugged in, less than 100%
	BatteryStateFull                          // plugged in, at 100%
)

func (BatteryState) String added in v0.1.0

func (v BatteryState) String() string

type BySelector added in v0.1.0

type BySelector struct {
	ClassName ElementType `json:"class name"`

	// isSearchByIdentifier
	Name            string `json:"name"`
	Id              string `json:"id"`
	AccessibilityId string `json:"accessibility id"`

	// partialSearch
	LinkText        ElementAttribute `json:"link text"`
	PartialLinkText ElementAttribute `json:"partial link text"`

	Predicate string `json:"predicate string"`

	ClassChain string `json:"class chain"`

	XPath string `json:"xpath"`
}

type Capabilities added in v0.1.0

type Capabilities map[string]interface{}

func NewCapabilities added in v0.1.0

func NewCapabilities() Capabilities

func (Capabilities) WithAppLaunchOption added in v0.1.0

func (caps Capabilities) WithAppLaunchOption(launchOpt AppLaunchOption) Capabilities

func (Capabilities) WithDefaultAlertAction added in v0.1.0

func (caps Capabilities) WithDefaultAlertAction(alertAction AlertAction) Capabilities

WithDefaultAlertAction

func (Capabilities) WithDisableAutomaticScreenshots added in v0.1.6

func (caps Capabilities) WithDisableAutomaticScreenshots(b bool) Capabilities

WithDisableAutomaticScreenshots

Defaults to `true`

func (Capabilities) WithElementResponseAttributes added in v0.1.0

func (caps Capabilities) WithElementResponseAttributes(s string) Capabilities

WithElementResponseAttributes If shouldUseCompactResponses == NO, is the comma-separated list of fields to return with each element.

Defaults to `type,label`.

func (Capabilities) WithEventloopIdleDelaySec added in v0.1.0

func (caps Capabilities) WithEventloopIdleDelaySec(second float64) Capabilities

WithEventloopIdleDelaySec Delays the invocation of '-[XCUIApplicationProcess setEventLoopHasIdled:]' by the timer interval passed. which is skipped on setting it to zero.

func (Capabilities) WithMaxTypingFrequency added in v0.1.0

func (caps Capabilities) WithMaxTypingFrequency(n int) Capabilities

WithMaxTypingFrequency

Defaults to `60`.

func (Capabilities) WithShouldTerminateApp added in v0.1.6

func (caps Capabilities) WithShouldTerminateApp(b bool) Capabilities

WithShouldTerminateApp

Defaults to `true`

func (Capabilities) WithShouldUseCompactResponses added in v0.1.0

func (caps Capabilities) WithShouldUseCompactResponses(b bool) Capabilities

WithShouldUseCompactResponses If set to YES will use compact (standards-compliant) & faster responses

Defaults to `true`

func (Capabilities) WithShouldUseSingletonTestManager added in v0.1.0

func (caps Capabilities) WithShouldUseSingletonTestManager(b bool) Capabilities

WithShouldUseSingletonTestManager

Defaults to `true`

func (Capabilities) WithShouldUseTestManagerForVisibilityDetection added in v0.1.0

func (caps Capabilities) WithShouldUseTestManagerForVisibilityDetection(b bool) Capabilities

WithShouldUseTestManagerForVisibilityDetection If set to YES will ask TestManagerDaemon for element visibility

Defaults to  `false`

func (Capabilities) WithWaitForIdleTimeout added in v0.1.0

func (caps Capabilities) WithWaitForIdleTimeout(second float64) Capabilities

WithWaitForIdleTimeout

Defaults to `10`

type Condition added in v0.1.0

type Condition func(wd WebDriver) (bool, error)

type Device

type Device struct {
	Port      int
	MjpegPort int
	// contains filtered or unexported fields
}

func DeviceList

func DeviceList() (devices []Device, err error)

func (Device) DeviceID

func (d Device) DeviceID() int

func (Device) GIDevice added in v0.4.0

func (d Device) GIDevice() giDevice.Device

func (Device) SerialNumber

func (d Device) SerialNumber() string

type DeviceButton added in v0.1.0

type DeviceButton string

DeviceButton A physical button on an iOS device.

const (
	DeviceButtonHome       DeviceButton = "home"
	DeviceButtonVolumeUp   DeviceButton = "volumeUp"
	DeviceButtonVolumeDown DeviceButton = "volumeDown"
)

type DeviceInfo added in v0.1.0

type DeviceInfo struct {
	TimeZone           string `json:"timeZone"`
	CurrentLocale      string `json:"currentLocale"`
	Model              string `json:"model"`
	UUID               string `json:"uuid"`
	UserInterfaceIdiom int    `json:"userInterfaceIdiom"`
	UserInterfaceStyle string `json:"userInterfaceStyle"`
	Name               string `json:"name"`
	IsSimulator        bool   `json:"isSimulator"`
	ThermalState       int    `json:"thermalState"`
}

type DeviceStatus added in v0.1.0

type DeviceStatus struct {
	Message string `json:"message"`
	State   string `json:"state"`
	OS      struct {
		TestmanagerdVersion int    `json:"testmanagerdVersion"`
		Name                string `json:"name"`
		SdkVersion          string `json:"sdkVersion"`
		Version             string `json:"version"`
	} `json:"os"`
	IOS struct {
		IP               string `json:"ip"`
		SimulatorVersion string `json:"simulatorVersion"`
	} `json:"ios"`
	Ready bool `json:"ready"`
	Build struct {
		Time                    string `json:"time"`
		ProductBundleIdentifier string `json:"productBundleIdentifier"`
	} `json:"build"`
}

type Direction added in v0.1.0

type Direction string
const (
	DirectionUp    Direction = "up"
	DirectionDown  Direction = "down"
	DirectionLeft  Direction = "left"
	DirectionRight Direction = "right"
)

type ElementAttribute added in v0.1.0

type ElementAttribute map[string]interface{}

func NewElementAttribute added in v0.1.0

func NewElementAttribute() ElementAttribute

func (ElementAttribute) String added in v0.1.0

func (ea ElementAttribute) String() string

func (ElementAttribute) WithAccessibilityContainer added in v0.1.0

func (ea ElementAttribute) WithAccessibilityContainer(b bool) ElementAttribute

WithAccessibilityContainer Whether element is an accessibility container (contains children of any depth that are accessible)

func (ElementAttribute) WithAccessible added in v0.1.0

func (ea ElementAttribute) WithAccessible(b bool) ElementAttribute

WithAccessible Whether element is accessible

func (ElementAttribute) WithEnabled added in v0.1.0

func (ea ElementAttribute) WithEnabled(b bool) ElementAttribute

WithEnabled Whether element is enabled

func (ElementAttribute) WithLabel added in v0.1.0

func (ea ElementAttribute) WithLabel(s string) ElementAttribute

WithLabel Element's label

func (ElementAttribute) WithName added in v0.1.0

func (ea ElementAttribute) WithName(s string) ElementAttribute

WithName Element's name

func (ElementAttribute) WithSelected added in v0.1.0

func (ea ElementAttribute) WithSelected(b bool) ElementAttribute

WithSelected Element's selected state

func (ElementAttribute) WithType added in v0.1.0

func (ea ElementAttribute) WithType(elemType ElementType) ElementAttribute

WithType Element's type

func (ElementAttribute) WithUID added in v0.1.0

func (ea ElementAttribute) WithUID(uid string) ElementAttribute

WithUID Element's unique identifier

func (ElementAttribute) WithValue added in v0.1.0

func (ea ElementAttribute) WithValue(s string) ElementAttribute

WithValue Element's value

func (ElementAttribute) WithVisible added in v0.1.0

func (ea ElementAttribute) WithVisible(b bool) ElementAttribute

WithVisible

Whether element is visible

type ElementType added in v0.1.0

type ElementType struct {
	Any                bool `json:"XCUIElementTypeAny"`
	Other              bool `json:"XCUIElementTypeOther"`
	Application        bool `json:"XCUIElementTypeApplication"`
	Group              bool `json:"XCUIElementTypeGroup"`
	Window             bool `json:"XCUIElementTypeWindow"`
	Sheet              bool `json:"XCUIElementTypeSheet"`
	Drawer             bool `json:"XCUIElementTypeDrawer"`
	Alert              bool `json:"XCUIElementTypeAlert"`
	Dialog             bool `json:"XCUIElementTypeDialog"`
	Button             bool `json:"XCUIElementTypeButton"`
	RadioButton        bool `json:"XCUIElementTypeRadioButton"`
	RadioGroup         bool `json:"XCUIElementTypeRadioGroup"`
	CheckBox           bool `json:"XCUIElementTypeCheckBox"`
	DisclosureTriangle bool `json:"XCUIElementTypeDisclosureTriangle"`
	PopUpButton        bool `json:"XCUIElementTypePopUpButton"`
	ComboBox           bool `json:"XCUIElementTypeComboBox"`
	MenuButton         bool `json:"XCUIElementTypeMenuButton"`
	ToolbarButton      bool `json:"XCUIElementTypeToolbarButton"`
	Popover            bool `json:"XCUIElementTypePopover"`
	Keyboard           bool `json:"XCUIElementTypeKeyboard"`
	Key                bool `json:"XCUIElementTypeKey"`
	NavigationBar      bool `json:"XCUIElementTypeNavigationBar"`
	TabBar             bool `json:"XCUIElementTypeTabBar"`
	TabGroup           bool `json:"XCUIElementTypeTabGroup"`
	Toolbar            bool `json:"XCUIElementTypeToolbar"`
	StatusBar          bool `json:"XCUIElementTypeStatusBar"`
	Table              bool `json:"XCUIElementTypeTable"`
	TableRow           bool `json:"XCUIElementTypeTableRow"`
	TableColumn        bool `json:"XCUIElementTypeTableColumn"`
	Outline            bool `json:"XCUIElementTypeOutline"`
	OutlineRow         bool `json:"XCUIElementTypeOutlineRow"`
	Browser            bool `json:"XCUIElementTypeBrowser"`
	CollectionView     bool `json:"XCUIElementTypeCollectionView"`
	Slider             bool `json:"XCUIElementTypeSlider"`
	PageIndicator      bool `json:"XCUIElementTypePageIndicator"`
	ProgressIndicator  bool `json:"XCUIElementTypeProgressIndicator"`
	ActivityIndicator  bool `json:"XCUIElementTypeActivityIndicator"`
	SegmentedControl   bool `json:"XCUIElementTypeSegmentedControl"`
	Picker             bool `json:"XCUIElementTypePicker"`
	PickerWheel        bool `json:"XCUIElementTypePickerWheel"`
	Switch             bool `json:"XCUIElementTypeSwitch"`
	Toggle             bool `json:"XCUIElementTypeToggle"`
	Link               bool `json:"XCUIElementTypeLink"`
	Image              bool `json:"XCUIElementTypeImage"`
	Icon               bool `json:"XCUIElementTypeIcon"`
	SearchField        bool `json:"XCUIElementTypeSearchField"`
	ScrollView         bool `json:"XCUIElementTypeScrollView"`
	ScrollBar          bool `json:"XCUIElementTypeScrollBar"`
	StaticText         bool `json:"XCUIElementTypeStaticText"`
	TextField          bool `json:"XCUIElementTypeTextField"`
	SecureTextField    bool `json:"XCUIElementTypeSecureTextField"`
	DatePicker         bool `json:"XCUIElementTypeDatePicker"`
	TextView           bool `json:"XCUIElementTypeTextView"`
	Menu               bool `json:"XCUIElementTypeMenu"`
	MenuItem           bool `json:"XCUIElementTypeMenuItem"`
	MenuBar            bool `json:"XCUIElementTypeMenuBar"`
	MenuBarItem        bool `json:"XCUIElementTypeMenuBarItem"`
	Map                bool `json:"XCUIElementTypeMap"`
	WebView            bool `json:"XCUIElementTypeWebView"`
	IncrementArrow     bool `json:"XCUIElementTypeIncrementArrow"`
	DecrementArrow     bool `json:"XCUIElementTypeDecrementArrow"`
	Timeline           bool `json:"XCUIElementTypeTimeline"`
	RatingIndicator    bool `json:"XCUIElementTypeRatingIndicator"`
	ValueIndicator     bool `json:"XCUIElementTypeValueIndicator"`
	SplitGroup         bool `json:"XCUIElementTypeSplitGroup"`
	Splitter           bool `json:"XCUIElementTypeSplitter"`
	RelevanceIndicator bool `json:"XCUIElementTypeRelevanceIndicator"`
	ColorWell          bool `json:"XCUIElementTypeColorWell"`
	HelpTag            bool `json:"XCUIElementTypeHelpTag"`
	Matte              bool `json:"XCUIElementTypeMatte"`
	DockItem           bool `json:"XCUIElementTypeDockItem"`
	Ruler              bool `json:"XCUIElementTypeRuler"`
	RulerMarker        bool `json:"XCUIElementTypeRulerMarker"`
	Grid               bool `json:"XCUIElementTypeGrid"`
	LevelIndicator     bool `json:"XCUIElementTypeLevelIndicator"`
	Cell               bool `json:"XCUIElementTypeCell"`
	LayoutArea         bool `json:"XCUIElementTypeLayoutArea"`
	LayoutItem         bool `json:"XCUIElementTypeLayoutItem"`
	Handle             bool `json:"XCUIElementTypeHandle"`
	Stepper            bool `json:"XCUIElementTypeStepper"`
	Tab                bool `json:"XCUIElementTypeTab"`
	TouchBar           bool `json:"XCUIElementTypeTouchBar"`
	StatusItem         bool `json:"XCUIElementTypeStatusItem"`
}

ElementType !!! This mapping should be updated if there are changes after each new XCTest release"`

func (ElementType) String added in v0.1.0

func (et ElementType) String() string

type EventPageID added in v0.1.9

type EventPageID int

EventPageID The event page identifier

const EventPageIDConsumer EventPageID = 0x0C

type EventUsageID added in v0.1.9

type EventUsageID int

EventUsageID The event usage identifier (usages are defined per-page)

const (
	EventUsageIDCsmrVolumeUp   EventUsageID = 0xE9
	EventUsageIDCsmrVolumeDown EventUsageID = 0xEA
	EventUsageIDCsmrHome       EventUsageID = 0x40
	EventUsageIDCsmrPower      EventUsageID = 0x30
	EventUsageIDCsmrSnapshot   EventUsageID = 0x65 // Power + Home
)

type FingerAction added in v0.1.0

type FingerAction []map[string]interface{}

func NewFingerAction added in v0.1.0

func NewFingerAction(capacity ...int) *FingerAction

func (*FingerAction) Down added in v0.1.0

func (fa *FingerAction) Down() *FingerAction

func (*FingerAction) Move added in v0.1.0

func (fa *FingerAction) Move(fm FingerMove) *FingerAction

func (*FingerAction) Pause added in v0.1.0

func (fa *FingerAction) Pause(second ...float64) *FingerAction

func (*FingerAction) Up added in v0.1.0

func (fa *FingerAction) Up() *FingerAction

type FingerMove added in v0.1.0

type FingerMove map[string]interface{}

func NewFingerMove added in v0.1.0

func NewFingerMove() FingerMove

func (FingerMove) WithDuration added in v0.1.0

func (fm FingerMove) WithDuration(second float64) FingerMove

func (FingerMove) WithOrigin added in v0.1.0

func (fm FingerMove) WithOrigin(element WebElement) FingerMove

func (FingerMove) WithXY added in v0.1.0

func (fm FingerMove) WithXY(x, y int) FingerMove

func (FingerMove) WithXYFloat added in v0.1.0

func (fm FingerMove) WithXYFloat(x, y float64) FingerMove

type Location added in v0.1.2

type Location struct {
	AuthorizationStatus int     `json:"authorizationStatus"`
	Longitude           float64 `json:"longitude"`
	Latitude            float64 `json:"latitude"`
	Altitude            float64 `json:"altitude"`
}

type NotificationType added in v0.1.5

type NotificationType string
const (
	NotificationTypePlain  NotificationType = "plain"
	NotificationTypeDarwin NotificationType = "darwin"
)

type Orientation added in v0.1.0

type Orientation string
const (
	// OrientationPortrait Device oriented vertically, home button on the bottom
	OrientationPortrait Orientation = "PORTRAIT"

	// OrientationPortraitUpsideDown Device oriented vertically, home button on the top
	OrientationPortraitUpsideDown Orientation = "UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN"

	// OrientationLandscapeLeft Device oriented horizontally, home button on the right
	OrientationLandscapeLeft Orientation = "LANDSCAPE"

	// OrientationLandscapeRight Device oriented horizontally, home button on the left
	OrientationLandscapeRight Orientation = "UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT"
)

type PasteboardType added in v0.1.0

type PasteboardType string

PasteboardType The type of the item on the pasteboard.

const (
	PasteboardTypePlaintext PasteboardType = "plaintext"
	PasteboardTypeImage     PasteboardType = "image"
	PasteboardTypeUrl       PasteboardType = "url"
)

type PickerWheelOrder added in v0.1.0

type PickerWheelOrder string
const (
	PickerWheelOrderNext     PickerWheelOrder = "next"
	PickerWheelOrderPrevious PickerWheelOrder = "previous"
)

type Point added in v0.1.0

type Point struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type ProtectedResource added in v0.1.0

type ProtectedResource int

ProtectedResource A system resource that requires user authorization to access.

const (
	ProtectedResourceContacts               ProtectedResource = 1
	ProtectedResourceCalendar               ProtectedResource = 2
	ProtectedResourceReminders              ProtectedResource = 3
	ProtectedResourcePhotos                 ProtectedResource = 4
	ProtectedResourceMicrophone             ProtectedResource = 5
	ProtectedResourceCamera                 ProtectedResource = 6
	ProtectedResourceMediaLibrary           ProtectedResource = 7
	ProtectedResourceHomeKit                ProtectedResource = 8
	ProtectedResourceSystemRootDirectory    ProtectedResource = 0x40000000
	ProtectedResourceUserDesktopDirectory   ProtectedResource = 0x40000001
	ProtectedResourceUserDownloadsDirectory ProtectedResource = 0x40000002
	ProtectedResourceUserDocumentsDirectory ProtectedResource = 0x40000003
	ProtectedResourceBluetooth              ProtectedResource = -0x40000000
	ProtectedResourceKeyboardNetwork        ProtectedResource = -0x40000001
	ProtectedResourceLocation               ProtectedResource = -0x40000002
	ProtectedResourceHealth                 ProtectedResource = -0x40000003
)

https://developer.apple.com/documentation/xctest/xcuiprotectedresource?language=objc

type Rect added in v0.1.0

type Rect struct {
	Point
	Size
}

type Rotation added in v0.1.0

type Rotation struct {
	X int `json:"x"`
	Y int `json:"y"`
	Z int `json:"z"`
}

type Screen added in v0.1.0

type Screen struct {
	StatusBarSize Size    `json:"statusBarSize"`
	Scale         float64 `json:"scale"`
}

type SessionInfo added in v0.1.0

type SessionInfo struct {
	SessionId    string `json:"sessionId"`
	Capabilities struct {
		Device             string `json:"device"`
		BrowserName        string `json:"browserName"`
		SdkVersion         string `json:"sdkVersion"`
		CFBundleIdentifier string `json:"CFBundleIdentifier"`
	} `json:"capabilities"`
}

type Size added in v0.1.0

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

type SourceOption added in v0.1.0

type SourceOption map[string]interface{}

SourceOption Configure the format or attribute of the Source

func NewSourceOption added in v0.1.0

func NewSourceOption() SourceOption

func (SourceOption) WithExcludedAttributes added in v0.1.0

func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption

WithExcludedAttributes Excludes the given attribute names. only `xml` is supported.

func (SourceOption) WithFormatAsDescription added in v0.1.0

func (opt SourceOption) WithFormatAsDescription() SourceOption

WithFormatAsDescription Application elements tree in form of internal XCTest debugDescription string

func (SourceOption) WithFormatAsJson added in v0.1.0

func (opt SourceOption) WithFormatAsJson() SourceOption

WithFormatAsJson Application elements tree in form of json string

func (SourceOption) WithFormatAsXml added in v0.1.0

func (opt SourceOption) WithFormatAsXml() SourceOption

WithFormatAsXml Application elements tree in form of xml string

func (SourceOption) WithScope added in v0.2.0

func (opt SourceOption) WithScope(scope string) SourceOption

WithScope Allows to provide XML scope.

only `xml` is supported.

type TouchActionLongPress added in v0.1.0

type TouchActionLongPress map[string]interface{}

func NewTouchActionLongPress added in v0.1.0

func NewTouchActionLongPress() TouchActionLongPress

func (TouchActionLongPress) WithElement added in v0.1.0

func (opt TouchActionLongPress) WithElement(element WebElement) TouchActionLongPress

func (TouchActionLongPress) WithXY added in v0.1.0

func (TouchActionLongPress) WithXYFloat added in v0.1.0

func (opt TouchActionLongPress) WithXYFloat(x, y float64) TouchActionLongPress

type TouchActionMoveTo added in v0.1.0

type TouchActionMoveTo map[string]interface{}

func NewTouchActionMoveTo added in v0.1.0

func NewTouchActionMoveTo() TouchActionMoveTo

func (TouchActionMoveTo) WithElement added in v0.1.0

func (opt TouchActionMoveTo) WithElement(element WebElement) TouchActionMoveTo

func (TouchActionMoveTo) WithXY added in v0.1.0

func (opt TouchActionMoveTo) WithXY(x, y int) TouchActionMoveTo

func (TouchActionMoveTo) WithXYFloat added in v0.1.0

func (opt TouchActionMoveTo) WithXYFloat(x, y float64) TouchActionMoveTo

type TouchActionPress added in v0.1.0

type TouchActionPress map[string]interface{}

func NewTouchActionPress added in v0.1.0

func NewTouchActionPress() TouchActionPress

func (TouchActionPress) WithElement added in v0.1.0

func (opt TouchActionPress) WithElement(element WebElement) TouchActionPress

func (TouchActionPress) WithPressure added in v0.1.0

func (opt TouchActionPress) WithPressure(pressure float64) TouchActionPress

func (TouchActionPress) WithXY added in v0.1.0

func (opt TouchActionPress) WithXY(x, y int) TouchActionPress

func (TouchActionPress) WithXYFloat added in v0.1.0

func (opt TouchActionPress) WithXYFloat(x, y float64) TouchActionPress

type TouchActionTap added in v0.1.0

type TouchActionTap map[string]interface{}

func NewTouchActionTap added in v0.1.0

func NewTouchActionTap() TouchActionTap

func (TouchActionTap) WithCount added in v0.1.0

func (opt TouchActionTap) WithCount(count int) TouchActionTap

func (TouchActionTap) WithElement added in v0.1.0

func (opt TouchActionTap) WithElement(element WebElement) TouchActionTap

func (TouchActionTap) WithXY added in v0.1.0

func (opt TouchActionTap) WithXY(x, y int) TouchActionTap

func (TouchActionTap) WithXYFloat added in v0.1.0

func (opt TouchActionTap) WithXYFloat(x, y float64) TouchActionTap

type TouchActions added in v0.1.0

type TouchActions []map[string]interface{}

func NewTouchActions added in v0.1.0

func NewTouchActions(capacity ...int) *TouchActions

func (*TouchActions) Cancel added in v0.1.0

func (act *TouchActions) Cancel() *TouchActions

func (*TouchActions) LongPress added in v0.1.0

func (act *TouchActions) LongPress(opt TouchActionLongPress) *TouchActions

func (*TouchActions) MoveTo added in v0.1.0

func (act *TouchActions) MoveTo(opt TouchActionMoveTo) *TouchActions

func (*TouchActions) Press added in v0.1.0

func (act *TouchActions) Press(opt TouchActionPress) *TouchActions

func (*TouchActions) Release added in v0.1.0

func (act *TouchActions) Release() *TouchActions

func (*TouchActions) Tap added in v0.1.0

func (act *TouchActions) Tap(opt TouchActionTap) *TouchActions

func (*TouchActions) Wait added in v0.1.0

func (act *TouchActions) Wait(second ...float64) *TouchActions

type W3CActions added in v0.1.0

type W3CActions []map[string]interface{}

func NewW3CActions added in v0.1.0

func NewW3CActions(capacity ...int) *W3CActions

func (*W3CActions) DoubleTap added in v0.1.0

func (act *W3CActions) DoubleTap(x, y int, element ...WebElement) *W3CActions

func (*W3CActions) FingerAction added in v0.1.0

func (act *W3CActions) FingerAction(fingerAct *FingerAction, fActs ...*FingerAction) *W3CActions

func (*W3CActions) Press added in v0.1.0

func (act *W3CActions) Press(x, y int, second float64, element ...WebElement) *W3CActions

func (*W3CActions) SendKeys added in v0.1.0

func (act *W3CActions) SendKeys(text string) *W3CActions

func (*W3CActions) Swipe added in v0.1.0

func (act *W3CActions) Swipe(fromX, fromY, toX, toY int, element ...WebElement) *W3CActions

func (*W3CActions) SwipeFloat added in v0.1.0

func (act *W3CActions) SwipeFloat(fromX, fromY, toX, toY float64, element ...WebElement) *W3CActions

func (*W3CActions) Tap added in v0.1.0

func (act *W3CActions) Tap(x, y int, element ...WebElement) *W3CActions

type WebDriver added in v0.1.0

type WebDriver interface {
	// NewSession starts a new session and returns the SessionInfo.
	NewSession(capabilities Capabilities) (SessionInfo, error)

	ActiveSession() (SessionInfo, error)
	// DeleteSession Kills application associated with that session and removes session
	//  1) alertsMonitor disable
	//  2) testedApplicationBundleId terminate
	DeleteSession() error

	Status() (DeviceStatus, error)

	DeviceInfo() (DeviceInfo, error)

	// Location Returns device location data.
	//
	// It requires to configure location access permission by manual.
	// The response of 'latitude', 'longitude' and 'altitude' are always zero (0) without authorization.
	// 'authorizationStatus' indicates current authorization status. '3' is 'Always'.
	// https://developer.apple.com/documentation/corelocation/clauthorizationstatus
	//
	//  Settings -> Privacy -> Location Service -> WebDriverAgent-Runner -> Always
	//
	// The return value could be zero even if the permission is set to 'Always'
	// since the location service needs some time to update the location data.
	Location() (Location, error)
	BatteryInfo() (BatteryInfo, error)
	WindowSize() (Size, error)
	Screen() (Screen, error)
	Scale() (float64, error)
	ActiveAppInfo() (AppInfo, error)
	// ActiveAppsList Retrieves the information about the currently active apps
	ActiveAppsList() ([]AppBaseInfo, error)
	// AppState Get the state of the particular application in scope of the current session.
	// !This method is only returning reliable results since Xcode9 SDK
	AppState(bundleId string) (AppState, error)

	// IsLocked Checks if the screen is locked or not.
	IsLocked() (bool, error)
	// Unlock Forces the device under test to unlock.
	// An immediate return will happen if the device is already unlocked
	// and an error is going to be thrown if the screen has not been unlocked after the timeout.
	Unlock() error
	// Lock Forces the device under test to switch to the lock screen.
	// An immediate return will happen if the device is already locked
	// and an error is going to be thrown if the screen has not been locked after the timeout.
	Lock() error

	// Homescreen Forces the device under test to switch to the home screen
	Homescreen() error

	// AlertText Returns alert's title and description separated by new lines
	AlertText() (string, error)
	// AlertButtons Gets the labels of the buttons visible in the alert
	AlertButtons() ([]string, error)
	// AlertAccept Accepts alert, if present
	AlertAccept(label ...string) error
	// AlertDismiss Dismisses alert, if present
	AlertDismiss(label ...string) error
	// AlertSendKeys Types a text into an input inside the alert container, if it is present
	AlertSendKeys(text string) error

	// AppLaunch Launch an application with given bundle identifier in scope of current session.
	// !This method is only available since Xcode9 SDK
	AppLaunch(bundleId string, launchOpt ...AppLaunchOption) error
	// AppLaunchUnattached Launch the app with the specified bundle ID.
	AppLaunchUnattached(bundleId string) error
	// AppTerminate Terminate an application with the given bundle id.
	// Either `true` if the app has been successfully terminated or `false` if it was not running
	AppTerminate(bundleId string) (bool, error)
	// AppActivate Activate an application with given bundle identifier in scope of current session.
	// !This method is only available since Xcode9 SDK
	AppActivate(bundleId string) error
	// AppDeactivate Deactivates application for given time and then activate it again
	//  The minimum application switch wait is 3 seconds
	AppDeactivate(second float64) error

	// AppAuthReset Resets the authorization status for a protected resource. Available since Xcode 11.4
	AppAuthReset(ProtectedResource) error

	// Tap Sends a tap event at the coordinate.
	Tap(x, y int) error
	TapFloat(x, y float64) error

	// DoubleTap Sends a double tap event at the coordinate.
	DoubleTap(x, y int) error
	DoubleTapFloat(x, y float64) error

	// TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration.
	//  second: The default value is 1
	TouchAndHold(x, y int, second ...float64) error
	TouchAndHoldFloat(x, y float64, second ...float64) error

	// Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.
	//  pressForDuration: The default value is 1 second.
	Drag(fromX, fromY, toX, toY int, pressForDuration ...float64) error
	DragFloat(fromX, fromY, toX, toY float64, pressForDuration ...float64) error

	// Swipe works like Drag, but `pressForDuration` value is 0
	Swipe(fromX, fromY, toX, toY int) error
	SwipeFloat(fromX, fromY, toX, toY float64) error

	ForceTouch(x, y int, pressure float64, second ...float64) error
	ForceTouchFloat(x, y, pressure float64, second ...float64) error

	// PerformW3CActions Perform complex touch action in scope of the current application.
	PerformW3CActions(actions *W3CActions) error
	PerformAppiumTouchActions(touchActs *TouchActions) error

	// SetPasteboard Sets data to the general pasteboard
	SetPasteboard(contentType PasteboardType, content string) error
	// GetPasteboard Gets the data contained in the general pasteboard.
	//  It worked when `WDA` was foreground. https://github.com/appium/WebDriverAgent/issues/330
	GetPasteboard(contentType PasteboardType) (raw *bytes.Buffer, err error)

	// SendKeys Types a string into active element. There must be element with keyboard focus,
	// otherwise an error is raised.
	//  frequency: Frequency of typing (letters per sec). The default value is 60
	SendKeys(text string, frequency ...int) error

	// KeyboardDismiss Tries to dismiss the on-screen keyboard
	KeyboardDismiss(keyNames ...string) error

	// PressButton Presses the corresponding hardware button on the device
	PressButton(devBtn DeviceButton) error

	// IOHIDEvent Emulated triggering of the given low-level IOHID device event.
	//  duration: The event duration in float seconds (XCTest uses 0.005 for a single press event)
	IOHIDEvent(pageID EventPageID, usageID EventUsageID, duration ...float64) error

	// ExpectNotification Creates an expectation that is fulfilled when an expected Notification is received
	ExpectNotification(notifyName string, notifyType NotificationType, second ...int) error

	// SiriActivate Activates Siri service voice recognition with the given text to parse
	SiriActivate(text string) error
	// SiriOpenUrl Opens the particular url scheme using Siri voice recognition helpers.
	// !This will only work since XCode 8.3/iOS 10.3
	//  It doesn't actually work, right?
	SiriOpenUrl(url string) error

	Orientation() (Orientation, error)
	// SetOrientation Sets requested device interface orientation.
	SetOrientation(Orientation) error

	Rotation() (Rotation, error)
	// SetRotation Sets the devices orientation to the rotation passed.
	SetRotation(Rotation) error

	// MatchTouchID Matches or mismatches TouchID request
	MatchTouchID(isMatch bool) error

	// ActiveElement Returns the element, which currently holds the keyboard input focus or nil if there are no such elements.
	ActiveElement() (WebElement, error)
	FindElement(by BySelector) (WebElement, error)
	FindElements(by BySelector) ([]WebElement, error)

	Screenshot() (*bytes.Buffer, error)

	// Source Return application elements tree
	Source(srcOpt ...SourceOption) (string, error)
	// AccessibleSource Return application elements accessibility tree
	AccessibleSource() (string, error)

	// HealthCheck Health check might modify simulator state so it should only be called in-between testing sessions
	//  Checks health of XCTest by:
	//  1) Querying application for some elements,
	//  2) Triggering some device events.
	HealthCheck() error
	GetAppiumSettings() (map[string]interface{}, error)
	SetAppiumSettings(settings map[string]interface{}) (map[string]interface{}, error)

	IsWdaHealthy() (bool, error)
	WdaShutdown() error

	// WaitWithTimeoutAndInterval waits for the condition to evaluate to true.
	WaitWithTimeoutAndInterval(condition Condition, timeout, interval time.Duration) error
	// WaitWithTimeout works like WaitWithTimeoutAndInterval, but with default polling interval.
	WaitWithTimeout(condition Condition, timeout time.Duration) error
	// Wait works like WaitWithTimeoutAndInterval, but using the default timeout and polling interval.
	Wait(condition Condition) error

	GetMjpegHTTPClient() *http.Client

	// Close inner connections properly
	Close() error
}

WebDriver defines methods supported by WebDriver drivers.

func NewDriver added in v0.1.0

func NewDriver(capabilities Capabilities, urlPrefix string, mjpegPort ...int) (driver WebDriver, err error)

NewDriver creates new remote client, this will also start a new session.

func NewUSBDriver added in v0.1.0

func NewUSBDriver(capabilities Capabilities, device ...Device) (driver WebDriver, err error)

NewUSBDriver creates new client via USB connected device, this will also start a new session.

type WebElement added in v0.1.0

type WebElement interface {
	// Click Waits for element to become stable (not move) and performs sync tap on element.
	Click() error
	// SendKeys Types a text into element. It will try to activate keyboard on element,
	// if element has no keyboard focus.
	//  frequency: Frequency of typing (letters per sec). The default value is 60
	SendKeys(text string, frequency ...int) error
	// Clear Clears text on element. It will try to activate keyboard on element,
	// if element has no keyboard focus.
	Clear() error

	// Tap Waits for element to become stable (not move) and performs sync tap on element,
	// relative to the current element position
	Tap(x, y int) error
	TapFloat(x, y float64) error

	// DoubleTap Sends a double tap event to a hittable point computed for the element.
	DoubleTap() error

	// TouchAndHold Sends a long-press gesture to a hittable point computed for the element,
	// holding for the specified duration.
	//  second: The default value is 1
	TouchAndHold(second ...float64) error
	// TwoFingerTap Sends a two finger tap event to a hittable point computed for the element.
	TwoFingerTap() error
	// TapWithNumberOfTaps Sends one or more taps with one or more touch points.
	TapWithNumberOfTaps(numberOfTaps, numberOfTouches int) error
	// ForceTouch Waits for element to become stable (not move) and performs sync force touch on element.
	//  second: The default value is 1
	ForceTouch(pressure float64, second ...float64) error
	// ForceTouchFloat works like ForceTouch, but relative to the current element position
	ForceTouchFloat(x, y, pressure float64, second ...float64) error

	// Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.
	// relative to the current element position
	//  pressForDuration: The default value is 1 second.
	Drag(fromX, fromY, toX, toY int, pressForDuration ...float64) error
	DragFloat(fromX, fromY, toX, toY float64, pressForDuration ...float64) error

	// Swipe works like Drag, but `pressForDuration` value is 0.
	// relative to the current element position
	Swipe(fromX, fromY, toX, toY int) error
	SwipeFloat(fromX, fromY, toX, toY float64) error
	// SwipeDirection Performs swipe gesture on the element.
	//  velocity: swipe speed in pixels per second. Custom velocity values are only supported since Xcode SDK 11.4.
	SwipeDirection(direction Direction, velocity ...float64) error

	// Pinch Sends a pinching gesture with two touches.
	//  scale: The scale of the pinch gesture. Use a scale between 0 and 1 to "pinch close" or zoom out
	//  and a scale greater than 1 to "pinch open" or zoom in.
	//  velocity: The velocity of the pinch in scale factor per second.
	Pinch(scale, velocity float64) error
	PinchToZoomOutByW3CAction(scale ...float64) error

	// Rotate Sends a rotation gesture with two touches.
	//  rotation: The rotation of the gesture in radians.
	//  velocity: The velocity of the rotation gesture in radians per second.
	Rotate(rotation float64, velocity ...float64) error

	// PickerWheelSelect
	//  offset: The default value is 2
	PickerWheelSelect(order PickerWheelOrder, offset ...int) error

	ScrollElementByName(name string) error
	ScrollElementByPredicate(predicate string) error
	ScrollToVisible() error
	// ScrollDirection
	//  distance: The default value is 0.5
	ScrollDirection(direction Direction, distance ...float64) error

	FindElement(by BySelector) (element WebElement, err error)
	FindElements(by BySelector) (elements []WebElement, err error)
	FindVisibleCells() (elements []WebElement, err error)

	Rect() (rect Rect, err error)
	Location() (Point, error)
	Size() (Size, error)
	Text() (text string, err error)
	Type() (elemType string, err error)
	IsEnabled() (enabled bool, err error)
	IsDisplayed() (displayed bool, err error)
	IsSelected() (selected bool, err error)
	IsAccessible() (accessible bool, err error)
	IsAccessibilityContainer() (isAccessibilityContainer bool, err error)
	GetAttribute(attr ElementAttribute) (value string, err error)
	UID() (uid string)

	Screenshot() (raw *bytes.Buffer, err error)
}

WebElement defines method supported by web elements.

Directories

Path Synopsis
examples
app

Jump to

Keyboard shortcuts

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