由於 Appium 的內容過於豐富。。我又不太想安裝那麼多我用不到的部分。。
而且 Appium 提供的 客戶端庫 並沒有 Golang 的實現版本。
於是我寫了使用 Golang 實現 appium/WebDriverAgent 的客戶端庫。
這些天重構了部分,相對來說使用會更接近 tebeka/selenium
靈感來自 Python 版的 facebook-wda : https://github.com/openatx/facebook-wda
擴充套件庫
Android
安裝
go get github.com/electricbubble/gwda
package main
import (
"github.com/electricbubble/gwda"
"log"
)
func main() {
// var urlPrefix = "http://localhost:8100"
// 該函式或許還需要 `iproxy 8100 8100` 先進行裝置埠轉發
// driver, _ := gwda.NewDriver(nil, urlPrefix)
// 通過 USB 直連裝置
driver, _ := gwda.NewUSBDriver(nil)
log.Println(driver.IsWdaHealthy())
}
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)
}
driver.PerformW3CActionsdriver.PerformAppiumTouchActions
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)
// 重置當前 App 的 相機📷 許可權
// driver.AppAuthReset(gwda.ProtectedResourceCamera)
}
package main
import (
"github.com/electricbubble/gwda"
)
func main() {
driver, _ := gwda.NewUSBDriver(nil)
driver.SendKeys("hello")
}
package main
import (
"github.com/electricbubble/gwda"
)
func main() {
driver, _ := gwda.NewUSBDriver(nil)
driver.SiriActivate("What's the weather like today")
}
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")
}
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)
// screen, _ := driver.Screen()
// log.Println(screen)
}
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)
}
package main
import (
"github.com/electricbubble/gwda"
"image"
)
func main() {
driver, _ := gwda.NewUSBDriver(nil)
screenshot, _ := driver.Screenshot()
img, format, _ := image.Decode(screenshot)
_, _ = img, format
}
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)
}