Because Appium content is too rich. I don’t really want to install so many parts that I don’t need.

And the client library provided by Appium does not have an implementation version of Golang.

So I wrote a client library that uses Golang to implement Appium /WebDriverAgent.

These days the refactoring part is relatively close to tebeka/ Selenium

Inspired by Facebook in Python – WDA: github.com/openatx/fac…

Extension libraries

  • Electricbubble/gwda-ext-OpencV operates directly with the specified image

If using an Android device, check out ElectricBubble/Guia2

The installation

WDA must be installed first. For the installation procedure, refer to the ATX document – iOS How to Install WebDriverAgent or WebDriverAgent

go get github.com/electricbubble/gwda
Copy the code

Connected devices

package main

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

func main(a) {
	// var urlPrefix = "http://localhost:8100"
	// This function may also require 'iProxy 8100 8100' to perform device port forwarding first
	// driver, _ := gwda.NewDriver(nil, urlPrefix)

	// Connect the device directly through USB
	driver, _ := gwda.NewUSBDriver(nil)

	log.Println(driver.IsWdaHealthy())
}

Copy the code

gestures

package main

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

func main(a) {
	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 3D Touch hardware support
	/ / driver. ForceTouch (x, y, 0.8)
}

Copy the code

Custom gestures driver. PerformW3CActions driver. PerformAppiumTouchActions

App operation

package main

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

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

	var bundleId = "com.apple.Preferences"

	driver.AppLaunchUnattached(bundleId)

	driver.AppDeactivate(2)

	driver.AppTerminate(bundleId)

	driver.AppActivate(bundleId)

	// Reset the camera 📷 permission for the current App
	// driver.AppAuthReset(gwda.ProtectedResourceCamera)
}

Copy the code

Keyboard input

package main

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

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

	driver.SendKeys("hello")}Copy the code

Specifies the input element, element.sendkeys

Siri operation

package main

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

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

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

Popup window operation

package main

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

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

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

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

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

	// driver.SendKeys("ah")
}

Copy the code

Basic Device Information

package main

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

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

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

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

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

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

Copy the code

keystrokes

package main

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

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

	// driver.Homescreen()

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

Copy the code

screenshots

package main

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

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

	screenshot, _ := driver.Screenshot()

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

Copy the code

Debug function

package main

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

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

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

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

	// gwda.SetDebug(true)
}

Copy the code