gwda

package module
v0.0.0-...-c1d24a1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 21 Imported by: 0

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

func SetDebug(debug bool)

SetDebug sets debug mode

Types

type AlertAction

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

type AppBaseInfo

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

type AppInfo

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

type AppLaunchOption

type AppLaunchOption map[string]interface{}

AppLaunchOption Configure app launch parameters

func NewAppLaunchOption

func NewAppLaunchOption() AppLaunchOption

func (AppLaunchOption) WithArguments

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

func (opt AppLaunchOption) WithBundleId(bundleId string) AppLaunchOption

func (AppLaunchOption) WithEnvironment

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

func (opt AppLaunchOption) WithShouldWaitForQuiescence(b bool) AppLaunchOption

WithShouldWaitForQuiescence whether to wait for quiescence on application startup

Defaults to `true`

type AppState

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

func (AppState) String

func (v AppState) String() string

type BatteryInfo

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

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

func (BatteryState) String

func (v BatteryState) String() string

type BySelector

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

type Capabilities map[string]interface{}

func NewCapabilities

func NewCapabilities() Capabilities

func (Capabilities) WithAppLaunchOption

func (caps Capabilities) WithAppLaunchOption(launchOpt AppLaunchOption) Capabilities

func (Capabilities) WithDefaultAlertAction

func (caps Capabilities) WithDefaultAlertAction(alertAction AlertAction) Capabilities

WithDefaultAlertAction

func (Capabilities) WithDisableAutomaticScreenshots

func (caps Capabilities) WithDisableAutomaticScreenshots(b bool) Capabilities

WithDisableAutomaticScreenshots

Defaults to `true`

func (Capabilities) WithElementResponseAttributes

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

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

func (caps Capabilities) WithMaxTypingFrequency(n int) Capabilities

WithMaxTypingFrequency

Defaults to `60`.

func (Capabilities) WithShouldTerminateApp

func (caps Capabilities) WithShouldTerminateApp(b bool) Capabilities

WithShouldTerminateApp

Defaults to `true`

func (Capabilities) WithShouldUseCompactResponses

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

func (caps Capabilities) WithShouldUseSingletonTestManager(b bool) Capabilities

WithShouldUseSingletonTestManager

Defaults to `true`

func (Capabilities) WithShouldUseTestManagerForVisibilityDetection

func (caps Capabilities) WithShouldUseTestManagerForVisibilityDetection(b bool) Capabilities

WithShouldUseTestManagerForVisibilityDetection If set to YES will ask TestManagerDaemon for element visibility

Defaults to  `false`

func (Capabilities) WithWaitForIdleTimeout

func (caps Capabilities) WithWaitForIdleTimeout(second float64) Capabilities

WithWaitForIdleTimeout

Defaults to `10`

type Condition

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 NewDevice

func NewDevice(options ...DeviceOption) (device *Device, err error)

func (Device) DeviceID

func (d Device) DeviceID() int

func (Device) GIDevice

func (d Device) GIDevice() giDevice.Device

func (Device) SerialNumber

func (d Device) SerialNumber() string

type DeviceButton

type DeviceButton string

DeviceButton A physical button on an iOS device.

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

type DeviceInfo

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 DeviceOption

type DeviceOption func(d *Device)

func WithMjpegPort

func WithMjpegPort(port int) DeviceOption

func WithPort

func WithPort(port int) DeviceOption

func WithSerialNumber

func WithSerialNumber(serialNumber string) DeviceOption

type DeviceStatus

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

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

type ElementAttribute

type ElementAttribute map[string]interface{}

func NewElementAttribute

func NewElementAttribute() ElementAttribute

func (ElementAttribute) String

func (ea ElementAttribute) String() string

func (ElementAttribute) WithAccessibilityContainer

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

func (ea ElementAttribute) WithAccessible(b bool) ElementAttribute

WithAccessible Whether element is accessible

func (ElementAttribute) WithEnabled

func (ea ElementAttribute) WithEnabled(b bool) ElementAttribute

WithEnabled Whether element is enabled

func (ElementAttribute) WithLabel

func (ea ElementAttribute) WithLabel(s string) ElementAttribute

WithLabel Element's label

func (ElementAttribute) WithName

func (ea ElementAttribute) WithName(s string) ElementAttribute

WithName Element's name

func (ElementAttribute) WithSelected

func (ea ElementAttribute) WithSelected(b bool) ElementAttribute

WithSelected Element's selected state

func (ElementAttribute) WithType

func (ea ElementAttribute) WithType(elemType ElementType) ElementAttribute

WithType Element's type

func (ElementAttribute) WithUID

func (ea ElementAttribute) WithUID(uid string) ElementAttribute

WithUID Element's unique identifier

func (ElementAttribute) WithValue

func (ea ElementAttribute) WithValue(s string) ElementAttribute

WithValue Element's value

func (ElementAttribute) WithVisible

func (ea ElementAttribute) WithVisible(b bool) ElementAttribute

WithVisible

Whether element is visible

type ElementType

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

func (et ElementType) String() string

type EventPageID

type EventPageID int

EventPageID The event page identifier

const EventPageIDConsumer EventPageID = 0x0C

type EventUsageID

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

type FingerAction []map[string]interface{}

func NewFingerAction

func NewFingerAction(capacity ...int) *FingerAction

func (*FingerAction) Down

func (fa *FingerAction) Down() *FingerAction

func (*FingerAction) Move

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

func (*FingerAction) Pause

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

func (*FingerAction) Up

func (fa *FingerAction) Up() *FingerAction

type FingerMove

type FingerMove map[string]interface{}

func NewFingerMove

func NewFingerMove() FingerMove

func (FingerMove) WithDuration

func (fm FingerMove) WithDuration(second float64) FingerMove

func (FingerMove) WithOrigin

func (fm FingerMove) WithOrigin(element WebElement) FingerMove

func (FingerMove) WithXY

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

func (FingerMove) WithXYFloat

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

type Location

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

type NotificationType

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

type Orientation

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

type PasteboardType string

PasteboardType The type of the item on the pasteboard.

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

type PickerWheelOrder

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

type Point

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

type ProtectedResource

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

type Rect struct {
	Point
	Size
}

type Rotation

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

type Screen

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

type SessionInfo

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

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

type SourceOption

type SourceOption map[string]interface{}

SourceOption Configure the format or attribute of the Source

func NewSourceOption

func NewSourceOption() SourceOption

func (SourceOption) WithExcludedAttributes

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

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

func (SourceOption) WithFormatAsDescription

func (opt SourceOption) WithFormatAsDescription() SourceOption

WithFormatAsDescription Application elements tree in form of internal XCTest debugDescription string

func (SourceOption) WithFormatAsJson

func (opt SourceOption) WithFormatAsJson() SourceOption

WithFormatAsJson Application elements tree in form of json string

func (SourceOption) WithFormatAsXml

func (opt SourceOption) WithFormatAsXml() SourceOption

WithFormatAsXml Application elements tree in form of xml string

func (SourceOption) WithScope

func (opt SourceOption) WithScope(scope string) SourceOption

WithScope Allows to provide XML scope.

only `xml` is supported.

type TouchActionLongPress

type TouchActionLongPress map[string]interface{}

func NewTouchActionLongPress

func NewTouchActionLongPress() TouchActionLongPress

func (TouchActionLongPress) WithElement

func (opt TouchActionLongPress) WithElement(element WebElement) TouchActionLongPress

func (TouchActionLongPress) WithXY

func (TouchActionLongPress) WithXYFloat

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

type TouchActionMoveTo

type TouchActionMoveTo map[string]interface{}

func NewTouchActionMoveTo

func NewTouchActionMoveTo() TouchActionMoveTo

func (TouchActionMoveTo) WithElement

func (opt TouchActionMoveTo) WithElement(element WebElement) TouchActionMoveTo

func (TouchActionMoveTo) WithXY

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

func (TouchActionMoveTo) WithXYFloat

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

type TouchActionPress

type TouchActionPress map[string]interface{}

func NewTouchActionPress

func NewTouchActionPress() TouchActionPress

func (TouchActionPress) WithElement

func (opt TouchActionPress) WithElement(element WebElement) TouchActionPress

func (TouchActionPress) WithPressure

func (opt TouchActionPress) WithPressure(pressure float64) TouchActionPress

func (TouchActionPress) WithXY

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

func (TouchActionPress) WithXYFloat

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

type TouchActionTap

type TouchActionTap map[string]interface{}

func NewTouchActionTap

func NewTouchActionTap() TouchActionTap

func (TouchActionTap) WithCount

func (opt TouchActionTap) WithCount(count int) TouchActionTap

func (TouchActionTap) WithElement

func (opt TouchActionTap) WithElement(element WebElement) TouchActionTap

func (TouchActionTap) WithXY

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

func (TouchActionTap) WithXYFloat

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

type TouchActions

type TouchActions []map[string]interface{}

func NewTouchActions

func NewTouchActions(capacity ...int) *TouchActions

func (*TouchActions) Cancel

func (act *TouchActions) Cancel() *TouchActions

func (*TouchActions) LongPress

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

func (*TouchActions) MoveTo

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

func (*TouchActions) Press

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

func (*TouchActions) Release

func (act *TouchActions) Release() *TouchActions

func (*TouchActions) Tap

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

func (*TouchActions) Wait

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

type W3CActions

type W3CActions []map[string]interface{}

func NewW3CActions

func NewW3CActions(capacity ...int) *W3CActions

func (*W3CActions) DoubleTap

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

func (*W3CActions) FingerAction

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

func (*W3CActions) Press

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

func (*W3CActions) SendKeys

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

func (*W3CActions) Swipe

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

func (*W3CActions) SwipeFloat

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

func (*W3CActions) Tap

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

type WebDriver

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, delay 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

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

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

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, delay 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