WebDriverAgent ( iOS ) Client Library in Golang

Golang-WDA

go doc go report license

appium/WebDriverAgent Client Library in Golang

Android can use electricbubble/guia2

中文 README

Installation

First, install WebDriverAgent for iOS devices

go get github.com/electricbubble/gwda

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)

	// 需要 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

Comments
  • src/github.com/electricbubble/gidevice/pkg/ipa/ipa.go:35:17: undefined: io.ReadAll

    src/github.com/electricbubble/gidevice/pkg/ipa/ipa.go:35:17: undefined: io.ReadAll

    我的代码是这样的

    	driver, err := gwda.NewUSBDriver(nil)
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	log.Println(driver.IsWdaHealthy())
    

    但运行时报了个这个错

    
    src/github.com/electricbubble/gidevice/pkg/ipa/ipa.go:35:17: undefined: io.ReadAll
    
    
  • 解析截图失败

    解析截图失败

    版本:

    • webdriveragent-xcode_12.3.zip v2.32.2
    • github.com/electricbubble/gwda v0.1.1
    • iOS 13.4.1
    bs, err := driver.Screenshot()
    session, _ := driver.ActiveSession()
    t.Log(session.SessionId)
    if nil != err {
    	t.Error("screenshot", err)
    } else {
    	// dst := base64.StdEncoding.EncodeToString(bs.Bytes())
    	// t.Log(dst)
    	img, format, err := image.Decode(bs)
    	if nil != err {
    		t.Error("decode", err) // image: unknown format <===
    	} else {
    		t.Log(bs.Len(), img, format)
    	}
    }
    

    经浏览器直接请求截图看到,返回的图片 base64 是带有 \r\n 换行符的,是否因这个问题解析失败呢?

    如下图所示:

    235434.png

  • go get错误,建议增加相应的安装说明

    go get错误,建议增加相应的安装说明

    $ go get -v github.com/ElectricBubble/gwda
    go: finding github.com/ElectricBubble/gwda latest
    go: downloading github.com/ElectricBubble/gwda v0.0.0-20200511015801-0e9736d3712a
    go: extracting github.com/ElectricBubble/gwda v0.0.0-20200511015801-0e9736d3712a
    go get: github.com/ElectricBubble/[email protected]: parsing go.mod:
    	module declares its path as: github.com/electricbubble/gwda
    	        but was required as: github.com/ElectricBubble/gwda
    
  • How does USBDriver work?

    How does USBDriver work?

    I found this code in NewUSBDriver

    if wd.urlPrefix, err = url.Parse("http://" + dev.serialNumber); err != nil {
    		return nil, err
    }
    

    but why http://xxxxxx can work in code?

  • add a helper function to get initialized giDevice.Device from gwda.Device

    add a helper function to get initialized giDevice.Device from gwda.Device

    • feat: get initialized giDevice.Device from gwda.Device
    • change: upgrade gidevice to v0.6.2
    • fix: go lint warnings

    examples:

    d := &gwda.Device{}
    
    d.GIDevice().AppLaunch("com.apple.springboard")
    d.GIDevice().Screenshot()
    
  • append options in post data for extra WDA configurations

    append options in post data for extra WDA configurations

    背景

    在体验评测中,我们需要精确度量出某些操作的耗时,例如点击启动抖音到开始播放视频的耗时(首帧)。

    在 iOS 系统中,不存在类似 Android debug 模式,因此要识别操作的起始点就十分困难。为了解决该问题,可以在 WDA 中加入打点日志,针对关键的 UI 操作记录其时间戳和步骤标识(identifier),然后就可以记录得到关键步骤的起始点时间。

    对应地,在 gwda 中调用 WDA 时,需要传入额外的控制参数,例如 开启日志、指定步骤标识(identifier)等。

    核心修改

    1、新增 DataOption,用于对请求 WDA 的 post data 进行修改:

    • WithPressDuration:设置 duration 字段,适用于 Drag、DragFloat
    • WithFrequency:设置 frequency 字段,适用于 SendKeys
    • WithCustomOption:支持添加自定义的字段,保障灵活性

    2、WebDriver 的方法签名调整:

    • Tap、TapFloat、Swipe、SwipeFloat:新增可选的 DataOption 参数
    • Drag、DragFloat:将可选参数 pressForDuration ...float64 替换为 options ...DataOption
    • SendKeys:将可选参数 frequency ...int 替换为 options ...DataOption

    替换可选参数的原因是可选参数可能需要传入多个。

    3、调用 debugLog 时,避免打印 screenshot 的响应内容

Golang HTTP client testing framework

flute Golang HTTP client testing framework Presentation https://speakerdeck.com/szksh/flute-golang-http-client-testing-framework Overview flute is the

Sep 27, 2022
go websocket client for unit testing of a websocket handler

wstest A websocket client for unit-testing a websocket server The gorilla organization provides full featured websocket implementation that the standa

Dec 21, 2022
A basic lightweight HTTP client for Go with included mock features.

A basic lightweight HTTP client for Go with included mock features. Features Support almost all http method like G

May 2, 2022
Test TiDB with multiple client versions

Usage Put multiple client versions in ~/opt/mysql/<version>/bin/mysql. If you are using dbdeployer you might already have this. Recommended set of ver

Nov 16, 2021
mock server to aid testing the jaguar-java client API

stripe-mock stripe-mock is a mock HTTP server that responds like the real Stripe API. It can be used instead of Stripe's test mode to make test suites

Dec 24, 2021
Client tool for testing HTTP server timeouts

HTTP timeout test client While testing Go HTTP server timeouts I wrote this little tool to help me test. It allows for slowing down header write and b

Sep 21, 2022
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.

Fortio Fortio (Φορτίο) started as, and is, Istio's load testing tool and now graduated to be its own project. Fortio is also used by, among others, Me

Jan 2, 2023
A library to aid unittesting code that uses Golang's Github SDK

go-github-mock A library to aid unittesting code that uses Golang's Github SDK Installation go get github.com/migueleliasweb/go-github-mock Features C

Dec 30, 2022
Gostresslib - A golang library for stress testing.

GoStressLib A golang library for stress testing. Install go get github.com/tenhan/gostresslib Usage package main import ( "github.com/tenhan/gostres

Nov 9, 2022
A yaml data-driven testing format together with golang testing library

Specimen Yaml-based data-driven testing Specimen is a yaml data format for data-driven testing. This enforces separation between feature being tested

Nov 24, 2022
Random - A Golang library that provides functions for generating random values

Random A Golang library that provides functions for generating random values. Us

Dec 15, 2022
:exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions

Package assert Package assert is a Basic Assertion library used along side native go testing Installation Use go get. go get github.com/go-playground/

Jan 6, 2023
Library created for testing JSON against patterns.

Gomatch Library created for testing JSON against patterns. The goal was to be able to validate JSON focusing only on parts essential in given test cas

Oct 28, 2022
A BDD library for Go

gospecify This provides a BDD syntax for testing your Go code. It should be familiar to anybody who has used libraries such as rspec. Installation The

Sep 27, 2022
A Go test assertion library for verifying that two representations of JSON are semantically equal
A Go test assertion library for verifying that two representations of JSON are semantically equal

jsonassert is a Go test assertion library for verifying that two representations of JSON are semantically equal. Usage Create a new *jsonassert.Assert

Jan 4, 2023
A Go library help testing your RESTful API application

RESTit A Go micro-framework to help writing RESTful API integration test Package RESTit provides helps to those who want to write an integration test

Oct 28, 2022
testcase is an opinionated behavior-driven-testing library

Table of Contents testcase Guide Official API Documentation Getting Started / Example Modules Summary DRY Modularization Stability Case Study About te

Nov 10, 2022
A toolkit with common assertions and mocks that plays nicely with the standard library

Testify - Thou Shalt Write Tests ℹ️ We are working on testify v2 and would love to hear what you'd like to see in it, have your say here: https://cutt

Dec 30, 2022
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.

?? Playwright for API reference | Example recipes Playwright is a Go library to automate Chromium, Firefox and WebKit with a single API. Playwright is

Jan 1, 2023