mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-19 05:09:30 +08:00
refactor: XTDriver
This commit is contained in:
@@ -296,7 +296,7 @@ func (ad *ADBDriver) AppTerminate(packageName string) (successful bool, err erro
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (ad *ADBDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
||||
func (ad *ADBDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
|
||||
if len(actionOptions.Offset) == 2 {
|
||||
@@ -317,7 +317,7 @@ func (ad *ADBDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
|
||||
func (ad *ADBDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
// adb shell input tap x y
|
||||
xStr := fmt.Sprintf("%.1f", x)
|
||||
yStr := fmt.Sprintf("%.1f", y)
|
||||
@@ -608,7 +608,7 @@ func (ad *ADBDriver) tapByTextUsingHierarchy(hierarchy *Hierarchy, text string,
|
||||
}
|
||||
for _, bound := range bounds {
|
||||
width, height := bound.Center()
|
||||
err := ad.Tap(width, height, opts...)
|
||||
err := ad.TapXY(width, height, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
|
||||
func (ud *UIA2Driver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
return ud.DoubleFloatTap(x, y)
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ func (ud *UIA2Driver) DoubleFloatTap(x, y float64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (ud *UIA2Driver) Tap(x, y float64, opts ...option.ActionOption) (err error) {
|
||||
func (ud *UIA2Driver) TapXY(x, y float64, opts ...option.ActionOption) (err error) {
|
||||
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestDriver_DeviceSize(t *testing.T) {
|
||||
func TestDriver_Source(t *testing.T) {
|
||||
setupAndroidUIA2Driver(t)
|
||||
|
||||
source, err := driverExt.GetDriver().Source()
|
||||
source, err := driverExt.Source()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func TestDriver_DeviceInfo(t *testing.T) {
|
||||
|
||||
func TestDriver_Tap(t *testing.T) {
|
||||
setupAndroidUIA2Driver(t)
|
||||
driverExt.GetDriver().StartCaptureLog("")
|
||||
driverExt.StartCaptureLog("")
|
||||
err := driverExt.TapXY(0.5, 0.5,
|
||||
option.WithIdentifier("test"),
|
||||
option.WithPressDuration(4))
|
||||
@@ -143,18 +143,18 @@ func TestDriver_Tap(t *testing.T) {
|
||||
}
|
||||
//time.Sleep(time.Second)
|
||||
//
|
||||
//err = driverExt.GetDriver().Tap(60.5, 125.5, WithIdentifier("test"))
|
||||
//err = driverExt.Tap(60.5, 125.5, WithIdentifier("test"))
|
||||
//if err != nil {
|
||||
// t.Fatal(err)
|
||||
//}
|
||||
//time.Sleep(time.Second)
|
||||
//result, _ := driverExt.GetDriver().StopCaptureLog()
|
||||
//result, _ := driverExt.StopCaptureLog()
|
||||
//t.Log(result)
|
||||
}
|
||||
|
||||
func TestDriver_Swipe(t *testing.T) {
|
||||
setupAndroidUIA2Driver(t)
|
||||
err := driverExt.GetDriver().Swipe(400, 1000, 400, 500,
|
||||
err := driverExt.Swipe(400, 1000, 400, 500,
|
||||
option.WithPressDuration(0.5))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -186,7 +186,7 @@ func TestDriver_Drag(t *testing.T) {
|
||||
func TestDriver_SendKeys(t *testing.T) {
|
||||
setupAndroidUIA2Driver(t)
|
||||
|
||||
err := driverExt.GetDriver().SendKeys("辽宁省沈阳市新民市民族街36-4",
|
||||
err := driverExt.SendKeys("辽宁省沈阳市新民市民族街36-4",
|
||||
option.WithIdentifier("test"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -224,10 +224,10 @@ func TestDriver_SetRotation(t *testing.T) {
|
||||
|
||||
func TestDriver_GetOrientation(t *testing.T) {
|
||||
setupAndroidUIA2Driver(t)
|
||||
_, _ = driverExt.GetDriver().AppTerminate("com.quark.browser")
|
||||
_ = driverExt.GetDriver().AppLaunch("com.quark.browser")
|
||||
_, _ = driverExt.AppTerminate("com.quark.browser")
|
||||
_ = driverExt.AppLaunch("com.quark.browser")
|
||||
time.Sleep(2 * time.Second)
|
||||
_ = driverExt.GetDriver().Homescreen()
|
||||
_ = driverExt.Homescreen()
|
||||
}
|
||||
|
||||
func Test_getFreePort(t *testing.T) {
|
||||
@@ -262,10 +262,10 @@ func TestDriver_IsAppInForeground(t *testing.T) {
|
||||
setupAndroidUIA2Driver(t)
|
||||
// setupAndroidAdbDriver(t)
|
||||
|
||||
err := driverExt.GetDriver().AppLaunch("com.android.settings")
|
||||
err := driverExt.AppLaunch("com.android.settings")
|
||||
checkErr(t, err)
|
||||
|
||||
app, err := driverExt.GetDriver().GetForegroundApp()
|
||||
app, err := driverExt.GetForegroundApp()
|
||||
checkErr(t, err)
|
||||
if app.PackageName != "com.android.settings" {
|
||||
t.FailNow()
|
||||
@@ -274,18 +274,18 @@ func TestDriver_IsAppInForeground(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
err = driverExt.GetDriver().AssertForegroundApp("com.android.settings")
|
||||
err = driverExt.AssertForegroundApp("com.android.settings")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
_, err = driverExt.GetDriver().AppTerminate("com.android.settings")
|
||||
_, err = driverExt.AppTerminate("com.android.settings")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = driverExt.GetDriver().AssertForegroundApp("com.android.settings")
|
||||
err = driverExt.AssertForegroundApp("com.android.settings")
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func TestTapTexts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
err := driverExt.GetDriver().TapByTexts(actions...)
|
||||
err := driverExt.TapByTexts(actions...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -393,7 +393,7 @@ func TestTapTexts(t *testing.T) {
|
||||
|
||||
func TestRecordVideo(t *testing.T) {
|
||||
setupAndroidAdbDriver(t)
|
||||
path, err := driverExt.GetDriver().(*ADBDriver).RecordScreen("", 5*time.Second)
|
||||
path, err := driverExt.RecordScreen("", 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -403,7 +403,7 @@ func TestRecordVideo(t *testing.T) {
|
||||
func Test_Android_Backspace(t *testing.T) {
|
||||
setupAndroidAdbDriver(t)
|
||||
|
||||
err := driverExt.GetDriver().Backspace(1)
|
||||
err := driverExt.Backspace(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestIOSDemo(t *testing.T) {
|
||||
|
||||
// release session
|
||||
defer func() {
|
||||
driverExt.GetDriver().DeleteSession()
|
||||
driverExt.DeleteSession()
|
||||
}()
|
||||
|
||||
// 持续监测手机屏幕,直到出现青少年模式弹窗后,点击「我知道了」
|
||||
|
||||
@@ -49,8 +49,8 @@ type IDriver interface {
|
||||
Homescreen() error
|
||||
Unlock() (err error)
|
||||
// tap
|
||||
Tap(x, y float64, opts ...option.ActionOption) error
|
||||
DoubleTap(x, y float64, opts ...option.ActionOption) error
|
||||
TapXY(x, y float64, opts ...option.ActionOption) error
|
||||
DoubleTapXY(x, y float64, opts ...option.ActionOption) error
|
||||
TapByText(text string, opts ...option.ActionOption) error // TODO: remove
|
||||
TapByTexts(actions ...TapTextAction) error // TODO: remove
|
||||
// swipe
|
||||
@@ -93,7 +93,7 @@ type IDriver interface {
|
||||
func NewXTDriver(driver IDriver, opts ...ai.AIServiceOption) *XTDriver {
|
||||
services := ai.NewAIService(opts...)
|
||||
driverExt := &XTDriver{
|
||||
Driver: driver,
|
||||
IDriver: driver,
|
||||
CVService: services.ICVService,
|
||||
LLMService: services.ILLMService,
|
||||
}
|
||||
@@ -104,8 +104,6 @@ var _ IDriverExt = (*XTDriver)(nil)
|
||||
|
||||
// XTDriver = IDriver + AI
|
||||
type IDriverExt interface {
|
||||
GetDriver() IDriver // get original driver
|
||||
|
||||
GetScreenResult(opts ...option.ActionOption) (screenResult *ScreenResult, err error)
|
||||
GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.OCRTexts, err error)
|
||||
GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error)
|
||||
@@ -134,18 +132,14 @@ type IDriverExt interface {
|
||||
}
|
||||
|
||||
type XTDriver struct {
|
||||
Driver IDriver
|
||||
IDriver
|
||||
CVService ai.ICVService // OCR/CV
|
||||
LLMService ai.ILLMService // LLM
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) GetDriver() IDriver {
|
||||
return dExt.Driver
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) Setup() error {
|
||||
// unlock device screen
|
||||
err := dExt.Driver.Unlock()
|
||||
err := dExt.Unlock()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("unlock device screen failed")
|
||||
return err
|
||||
@@ -188,7 +182,7 @@ func (dExt *XTDriver) assertOCR(text, assert string) error {
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) assertForegroundApp(appName, assert string) (err error) {
|
||||
err = dExt.Driver.AssertForegroundApp(appName)
|
||||
err = dExt.AssertForegroundApp(appName)
|
||||
switch assert {
|
||||
case AssertionEqual:
|
||||
if err != nil {
|
||||
|
||||
@@ -113,7 +113,7 @@ func (dExt *XTDriver) ParseActionOptions(opts ...option.ActionOption) []option.A
|
||||
|
||||
func (dExt *XTDriver) GenAbsScope(x1, y1, x2, y2 float64) option.AbsScope {
|
||||
// convert relative scope to absolute scope
|
||||
windowSize, _ := dExt.Driver.WindowSize()
|
||||
windowSize, _ := dExt.WindowSize()
|
||||
absX1 := int(x1 * float64(windowSize.Width))
|
||||
absY1 := int(y1 * float64(windowSize.Height))
|
||||
absX2 := int(x2 * float64(windowSize.Width))
|
||||
@@ -153,13 +153,13 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
||||
}
|
||||
case ACTION_AppClear:
|
||||
if packageName, ok := action.Params.(string); ok {
|
||||
if err = dExt.Driver.AppClear(packageName); err != nil {
|
||||
if err = dExt.AppClear(packageName); err != nil {
|
||||
return errors.Wrap(err, "failed to clear app")
|
||||
}
|
||||
}
|
||||
case ACTION_AppLaunch:
|
||||
if bundleId, ok := action.Params.(string); ok {
|
||||
return dExt.Driver.AppLaunch(bundleId)
|
||||
return dExt.AppLaunch(bundleId)
|
||||
}
|
||||
return fmt.Errorf("invalid %s params, should be bundleId(string), got %v",
|
||||
ACTION_AppLaunch, action.Params)
|
||||
@@ -185,7 +185,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
||||
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
||||
case ACTION_AppTerminate:
|
||||
if bundleId, ok := action.Params.(string); ok {
|
||||
success, err := dExt.Driver.AppTerminate(bundleId)
|
||||
success, err := dExt.AppTerminate(bundleId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to terminate app")
|
||||
}
|
||||
@@ -196,10 +196,10 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
||||
}
|
||||
return fmt.Errorf("app_terminate params should be bundleId(string), got %v", action.Params)
|
||||
case ACTION_Home:
|
||||
return dExt.Driver.Homescreen()
|
||||
return dExt.Homescreen()
|
||||
case ACTION_SetIme:
|
||||
if ime, ok := action.Params.(string); ok {
|
||||
err = dExt.Driver.SetIme(ime)
|
||||
err = dExt.SetIme(ime)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to set ime")
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
||||
case ACTION_GetSource:
|
||||
if packageName, ok := action.Params.(string); ok {
|
||||
source := option.NewSourceOption().WithProcessName(packageName)
|
||||
_, err = dExt.Driver.Source(source)
|
||||
_, err = dExt.Source(source)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to set ime")
|
||||
}
|
||||
@@ -274,9 +274,9 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
||||
// append \n to send text with enter
|
||||
// send \b\b\b to delete 3 chars
|
||||
param := fmt.Sprintf("%v", action.Params)
|
||||
return dExt.Driver.Input(param, action.GetOptions()...)
|
||||
return dExt.Input(param)
|
||||
case ACTION_Back:
|
||||
return dExt.Driver.PressBack()
|
||||
return dExt.PressBack()
|
||||
case ACTION_Sleep:
|
||||
if param, ok := action.Params.(json.Number); ok {
|
||||
seconds, _ := param.Float64()
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestSwipe(t *testing.T) {
|
||||
|
||||
func TestTap(t *testing.T) {
|
||||
setupShootsAndroidDriver(t)
|
||||
err := shootsAndroidDriver.Tap(900, 400)
|
||||
err := shootsAndroidDriver.TapXY(900, 400)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func TestTap(t *testing.T) {
|
||||
|
||||
func TestDoubleTap(t *testing.T) {
|
||||
setupShootsAndroidDriver(t)
|
||||
err := shootsAndroidDriver.DoubleTap(500, 500)
|
||||
err := shootsAndroidDriver.DoubleTapXY(500, 500)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -200,22 +200,22 @@ func (s *ShootsIOSDriver) Orientation() (orientation types.Orientation, err erro
|
||||
return s.WDADriver.Orientation()
|
||||
}
|
||||
|
||||
// Tap Sends a tap event at the coordinate.
|
||||
func (s *ShootsIOSDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
||||
// TapXY Sends a tap event at the coordinate.
|
||||
func (s *ShootsIOSDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
err := s.setUpWda()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.WDADriver.Tap(x, y, opts...)
|
||||
return s.WDADriver.TapXY(x, y, opts...)
|
||||
}
|
||||
|
||||
// DoubleTap Sends a double tap event at the coordinate.
|
||||
func (s *ShootsIOSDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
|
||||
// DoubleTapXY Sends a double tap event at the coordinate.
|
||||
func (s *ShootsIOSDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
err := s.setUpWda()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.WDADriver.DoubleTap(x, y, opts...)
|
||||
return s.WDADriver.DoubleTapXY(x, y, opts...)
|
||||
}
|
||||
|
||||
// TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration.
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package uixt
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
)
|
||||
|
||||
func (dExt *XTDriver) Input(text string) (err error) {
|
||||
err = dExt.Driver.Input(text)
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUIInputError, err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (dExt *XTDriver) InstallByUrl(url string, opts ...option.InstallOption) err
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) error {
|
||||
if _, ok := dExt.Driver.GetDevice().(*AndroidDevice); ok {
|
||||
if _, ok := dExt.GetDevice().(*AndroidDevice); ok {
|
||||
stopChan := make(chan struct{})
|
||||
go func() {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
@@ -69,7 +69,7 @@ func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) err
|
||||
},
|
||||
},
|
||||
}
|
||||
_ = dExt.Driver.TapByTexts(actions...)
|
||||
_ = dExt.TapByTexts(actions...)
|
||||
|
||||
_ = dExt.TapByOCR(
|
||||
"^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|授权本次安装|稍后提醒|继续安装|重新安装|安装)$",
|
||||
@@ -87,12 +87,12 @@ func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) err
|
||||
}()
|
||||
}
|
||||
|
||||
return dExt.Driver.GetDevice().Install(filePath, opts...)
|
||||
return dExt.GetDevice().Install(filePath, opts...)
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) Uninstall(packageName string, opts ...option.ActionOption) error {
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
err := dExt.Driver.GetDevice().Uninstall(packageName)
|
||||
err := dExt.GetDevice().Uninstall(packageName)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("failed to uninstall")
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
|
||||
continue
|
||||
}
|
||||
|
||||
windowSize, err = dExt.Driver.WindowSize()
|
||||
windowSize, err = dExt.WindowSize()
|
||||
if err != nil {
|
||||
lastErr = errors.Wrap(code.DeviceGetInfoError, err.Error())
|
||||
continue
|
||||
@@ -101,7 +101,7 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
|
||||
}
|
||||
|
||||
// cache screen result
|
||||
dExt.Driver.GetSession().addScreenResult(screenResult)
|
||||
dExt.GetSession().addScreenResult(screenResult)
|
||||
|
||||
if imageResult != nil {
|
||||
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
||||
@@ -200,7 +200,7 @@ func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (point ai.PointF
|
||||
|
||||
// GetScreenShot takes screenshot and saves image file to $CWD/screenshots/ folder
|
||||
func (dExt *XTDriver) GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error) {
|
||||
if raw, err = dExt.Driver.Screenshot(); err != nil {
|
||||
if raw, err = dExt.Screenshot(); err != nil {
|
||||
log.Error().Err(err).Msg("capture screenshot data failed")
|
||||
return nil, "", errors.Wrap(code.DeviceScreenShotError, err.Error())
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ import (
|
||||
|
||||
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
||||
func (dExt *XTDriver) SwipeRelative(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error {
|
||||
absFromX, absFromY, absToX, absToY, err := convertToAbsoluteCoordinates(dExt.Driver, fromX, fromY, toX, toY)
|
||||
absFromX, absFromY, absToX, absToY, err := convertToAbsoluteCoordinates(dExt.IDriver, fromX, fromY, toX, toY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dExt.Driver.Swipe(absFromX, absFromY, absToX, absToY, opts...)
|
||||
err = dExt.Swipe(absFromX, absFromY, absToX, absToY, opts...)
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUISwipeError, err.Error())
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func (dExt *XTDriver) swipeToTapTexts(texts []string, opts ...option.ActionOptio
|
||||
|
||||
func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) error {
|
||||
// go to home screen
|
||||
if err := dExt.Driver.Homescreen(); err != nil {
|
||||
if err := dExt.Homescreen(); err != nil {
|
||||
return errors.Wrap(err, "go to home screen failed")
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestAndroidSwipeToTapApp(t *testing.T) {
|
||||
func TestAndroidSwipeToTapTexts(t *testing.T) {
|
||||
setupAndroidAdbDriver(t)
|
||||
|
||||
err := driverExt.GetDriver().AppLaunch("com.ss.android.ugc.aweme")
|
||||
err := driverExt.AppLaunch("com.ss.android.ugc.aweme")
|
||||
checkErr(t, err)
|
||||
|
||||
err = driverExt.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, option.WithDirection("up"))
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func (dExt *XTDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||
// tap on absolute coordinate [x, y]
|
||||
err := dExt.Driver.Tap(x, y, opts...)
|
||||
err := dExt.TapXY(x, y, opts...)
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func (dExt *XTDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
return fmt.Errorf("x, y percentage should be <= 1, got x=%v, y=%v", x, y)
|
||||
}
|
||||
|
||||
windowSize, err := dExt.Driver.WindowSize()
|
||||
windowSize, err := dExt.WindowSize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -88,13 +88,13 @@ func (dExt *XTDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) err
|
||||
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
|
||||
}
|
||||
|
||||
windowSize, err := dExt.Driver.WindowSize()
|
||||
windowSize, err := dExt.WindowSize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x = x * float64(windowSize.Width)
|
||||
y = y * float64(windowSize.Height)
|
||||
err = dExt.Driver.DoubleTap(x, y, opts...)
|
||||
err = dExt.DoubleTapXY(x, y, opts...)
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (dExt *XTDriver) DoubleTapOffset(param string, xOffset, yOffset float64, op
|
||||
return err
|
||||
}
|
||||
|
||||
err = dExt.Driver.DoubleTap(point.X+xOffset, point.Y+yOffset, opts...)
|
||||
err = dExt.DoubleTapXY(point.X+xOffset, point.Y+yOffset, opts...)
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestNewDriverExt(t *testing.T) {
|
||||
t.Log(texts)
|
||||
|
||||
// get original dirver
|
||||
driver = driverExt.GetDriver().(*ADBDriver)
|
||||
driver = driverExt.IDriver.(*ADBDriver)
|
||||
|
||||
// get device
|
||||
device = driver.GetDevice().(*AndroidDevice)
|
||||
|
||||
@@ -151,7 +151,7 @@ func (hd *HDCDriver) Orientation() (orientation types.Orientation, err error) {
|
||||
return types.OrientationPortrait, nil
|
||||
}
|
||||
|
||||
func (hd *HDCDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
||||
func (hd *HDCDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
|
||||
if len(actionOptions.Offset) == 2 {
|
||||
@@ -168,7 +168,7 @@ func (hd *HDCDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
||||
return hd.uiDriver.InjectGesture(ghdc.NewGesture().Start(ghdc.Point{X: int(x), Y: int(y)}).Pause(100))
|
||||
}
|
||||
|
||||
func (hd *HDCDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
|
||||
func (hd *HDCDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
|
||||
return types.ErrDriverNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -520,7 +520,7 @@ func (wd *WDADriver) AssertForegroundApp(bundleId string, viewControllerType ...
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Tap(x, y float64, opts ...option.ActionOption) (err error) {
|
||||
func (wd *WDADriver) TapXY(x, y float64, opts ...option.ActionOption) (err error) {
|
||||
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
|
||||
@@ -544,7 +544,7 @@ func (wd *WDADriver) Tap(x, y float64, opts ...option.ActionOption) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) (err error) {
|
||||
func (wd *WDADriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) (err error) {
|
||||
// [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
x = wd.toScale(x)
|
||||
@@ -569,7 +569,7 @@ func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (er
|
||||
if actionOptions.Duration == 0 {
|
||||
opts = append(opts, option.WithDuration(1))
|
||||
}
|
||||
return wd.Tap(x, y, opts...)
|
||||
return wd.TapXY(x, y, opts...)
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) (err error) {
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestViaUSB(t *testing.T) {
|
||||
|
||||
func TestInstall(t *testing.T) {
|
||||
setup(t)
|
||||
err := iOSDriverExt.GetDriver().GetDevice().Install("xxx.ipa",
|
||||
err := iOSDriverExt.GetDevice().Install("xxx.ipa",
|
||||
option.WithRetryTimes(5))
|
||||
log.Error().Err(err)
|
||||
if err != nil {
|
||||
@@ -268,7 +268,7 @@ func Test_remoteWD_AppTerminate(t *testing.T) {
|
||||
func Test_remoteWD_Tap(t *testing.T) {
|
||||
setup(t)
|
||||
|
||||
err := driver.Tap(200, 300)
|
||||
err := driver.TapXY(200, 300)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -277,7 +277,7 @@ func Test_remoteWD_Tap(t *testing.T) {
|
||||
func Test_remoteWD_DoubleTap(t *testing.T) {
|
||||
setup(t)
|
||||
|
||||
err := driver.DoubleTap(200, 300)
|
||||
err := driver.DoubleTapXY(200, 300)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user