mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 06:23:52 +08:00
refactor: XTDriver
This commit is contained in:
@@ -98,7 +98,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
||||||
// 退出回到推荐页
|
// 退出回到推荐页
|
||||||
driver.GetDriver().PressBack()
|
driver.PressBack()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
// 返回视频页面
|
// 返回视频页面
|
||||||
err = driver.GetDriver().PressBack()
|
err = driver.PressBack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
// 返回推荐页
|
// 返回推荐页
|
||||||
err = driver.GetDriver().PressBack()
|
err = driver.PressBack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,17 +36,17 @@ func launchAppDriver(pkgName string) (driverExt *uixt.XTDriver, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//_, err = driver.Driver.AppTerminate(pkgName)
|
//_, err = driver.AppTerminate(pkgName)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//err = driver.Driver.Homescreen()
|
//err = driver.Homescreen()
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//err = driver.Driver.AppLaunch(pkgName)
|
//err = driver.AppLaunch(pkgName)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
@@ -100,7 +100,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
||||||
// 退出回到推荐页
|
// 退出回到推荐页
|
||||||
driver.GetDriver().PressBack()
|
driver.PressBack()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
// 返回视频页面
|
// 返回视频页面
|
||||||
err = driver.GetDriver().PressBack()
|
err = driver.PressBack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
// 返回推荐页
|
// 返回推荐页
|
||||||
err = driver.GetDriver().PressBack()
|
err = driver.PressBack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func NewWorldCupLive(driver *uixt.XTDriver, matchName, bundleID string, duration
|
|||||||
log.Fatal().Err(err).Msg("failed to open file")
|
log.Fatal().Err(err).Msg("failed to open file")
|
||||||
}
|
}
|
||||||
// write title
|
// write title
|
||||||
f.WriteString(fmt.Sprintf("%s\t%s\t%s\n", matchName, driver.GetDriver().GetDevice().UUID(), bundleID))
|
f.WriteString(fmt.Sprintf("%s\t%s\t%s\n", matchName, driver.GetDevice().UUID(), bundleID))
|
||||||
f.WriteString("utc_time\tutc_timestamp\tlive_time\tlive_seconds\n")
|
f.WriteString("utc_time\tutc_timestamp\tlive_time\tlive_seconds\n")
|
||||||
|
|
||||||
if interval == 0 {
|
if interval == 0 {
|
||||||
@@ -174,13 +174,13 @@ func (wc *WorldCupLive) EnterLive(bundleID string) error {
|
|||||||
log.Info().Msg("enter world cup live")
|
log.Info().Msg("enter world cup live")
|
||||||
|
|
||||||
// kill app
|
// kill app
|
||||||
_, err := wc.driver.GetDriver().AppTerminate(bundleID)
|
_, err := wc.driver.AppTerminate(bundleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("terminate app failed")
|
log.Error().Err(err).Msg("terminate app failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// launch app
|
// launch app
|
||||||
err = wc.driver.GetDriver().AppLaunch(bundleID)
|
err = wc.driver.AppLaunch(bundleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("launch app failed")
|
log.Error().Err(err).Msg("launch app failed")
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0+2502111501
|
v5.0.0+2502111534
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ func (ad *ADBDriver) AppTerminate(packageName string) (successful bool, err erro
|
|||||||
return true, nil
|
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...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
|
||||||
if len(actionOptions.Offset) == 2 {
|
if len(actionOptions.Offset) == 2 {
|
||||||
@@ -317,7 +317,7 @@ func (ad *ADBDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
|||||||
return nil
|
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
|
// adb shell input tap x y
|
||||||
xStr := fmt.Sprintf("%.1f", x)
|
xStr := fmt.Sprintf("%.1f", x)
|
||||||
yStr := fmt.Sprintf("%.1f", y)
|
yStr := fmt.Sprintf("%.1f", y)
|
||||||
@@ -608,7 +608,7 @@ func (ad *ADBDriver) tapByTextUsingHierarchy(hierarchy *Hierarchy, text string,
|
|||||||
}
|
}
|
||||||
for _, bound := range bounds {
|
for _, bound := range bounds {
|
||||||
width, height := bound.Center()
|
width, height := bound.Center()
|
||||||
err := ad.Tap(width, height, opts...)
|
err := ad.TapXY(width, height, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
|
|||||||
return
|
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)
|
return ud.DoubleFloatTap(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ func (ud *UIA2Driver) DoubleFloatTap(x, y float64) error {
|
|||||||
return err
|
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"))
|
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func TestDriver_DeviceSize(t *testing.T) {
|
|||||||
func TestDriver_Source(t *testing.T) {
|
func TestDriver_Source(t *testing.T) {
|
||||||
setupAndroidUIA2Driver(t)
|
setupAndroidUIA2Driver(t)
|
||||||
|
|
||||||
source, err := driverExt.GetDriver().Source()
|
source, err := driverExt.Source()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ func TestDriver_DeviceInfo(t *testing.T) {
|
|||||||
|
|
||||||
func TestDriver_Tap(t *testing.T) {
|
func TestDriver_Tap(t *testing.T) {
|
||||||
setupAndroidUIA2Driver(t)
|
setupAndroidUIA2Driver(t)
|
||||||
driverExt.GetDriver().StartCaptureLog("")
|
driverExt.StartCaptureLog("")
|
||||||
err := driverExt.TapXY(0.5, 0.5,
|
err := driverExt.TapXY(0.5, 0.5,
|
||||||
option.WithIdentifier("test"),
|
option.WithIdentifier("test"),
|
||||||
option.WithPressDuration(4))
|
option.WithPressDuration(4))
|
||||||
@@ -143,18 +143,18 @@ func TestDriver_Tap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
//time.Sleep(time.Second)
|
//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 {
|
//if err != nil {
|
||||||
// t.Fatal(err)
|
// t.Fatal(err)
|
||||||
//}
|
//}
|
||||||
//time.Sleep(time.Second)
|
//time.Sleep(time.Second)
|
||||||
//result, _ := driverExt.GetDriver().StopCaptureLog()
|
//result, _ := driverExt.StopCaptureLog()
|
||||||
//t.Log(result)
|
//t.Log(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDriver_Swipe(t *testing.T) {
|
func TestDriver_Swipe(t *testing.T) {
|
||||||
setupAndroidUIA2Driver(t)
|
setupAndroidUIA2Driver(t)
|
||||||
err := driverExt.GetDriver().Swipe(400, 1000, 400, 500,
|
err := driverExt.Swipe(400, 1000, 400, 500,
|
||||||
option.WithPressDuration(0.5))
|
option.WithPressDuration(0.5))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -186,7 +186,7 @@ func TestDriver_Drag(t *testing.T) {
|
|||||||
func TestDriver_SendKeys(t *testing.T) {
|
func TestDriver_SendKeys(t *testing.T) {
|
||||||
setupAndroidUIA2Driver(t)
|
setupAndroidUIA2Driver(t)
|
||||||
|
|
||||||
err := driverExt.GetDriver().SendKeys("辽宁省沈阳市新民市民族街36-4",
|
err := driverExt.SendKeys("辽宁省沈阳市新民市民族街36-4",
|
||||||
option.WithIdentifier("test"))
|
option.WithIdentifier("test"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -224,10 +224,10 @@ func TestDriver_SetRotation(t *testing.T) {
|
|||||||
|
|
||||||
func TestDriver_GetOrientation(t *testing.T) {
|
func TestDriver_GetOrientation(t *testing.T) {
|
||||||
setupAndroidUIA2Driver(t)
|
setupAndroidUIA2Driver(t)
|
||||||
_, _ = driverExt.GetDriver().AppTerminate("com.quark.browser")
|
_, _ = driverExt.AppTerminate("com.quark.browser")
|
||||||
_ = driverExt.GetDriver().AppLaunch("com.quark.browser")
|
_ = driverExt.AppLaunch("com.quark.browser")
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
_ = driverExt.GetDriver().Homescreen()
|
_ = driverExt.Homescreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_getFreePort(t *testing.T) {
|
func Test_getFreePort(t *testing.T) {
|
||||||
@@ -262,10 +262,10 @@ func TestDriver_IsAppInForeground(t *testing.T) {
|
|||||||
setupAndroidUIA2Driver(t)
|
setupAndroidUIA2Driver(t)
|
||||||
// setupAndroidAdbDriver(t)
|
// setupAndroidAdbDriver(t)
|
||||||
|
|
||||||
err := driverExt.GetDriver().AppLaunch("com.android.settings")
|
err := driverExt.AppLaunch("com.android.settings")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
app, err := driverExt.GetDriver().GetForegroundApp()
|
app, err := driverExt.GetForegroundApp()
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
if app.PackageName != "com.android.settings" {
|
if app.PackageName != "com.android.settings" {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@@ -274,18 +274,18 @@ func TestDriver_IsAppInForeground(t *testing.T) {
|
|||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = driverExt.GetDriver().AssertForegroundApp("com.android.settings")
|
err = driverExt.AssertForegroundApp("com.android.settings")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
_, err = driverExt.GetDriver().AppTerminate("com.android.settings")
|
_, err = driverExt.AppTerminate("com.android.settings")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = driverExt.GetDriver().AssertForegroundApp("com.android.settings")
|
err = driverExt.AssertForegroundApp("com.android.settings")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,7 @@ func TestTapTexts(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := driverExt.GetDriver().TapByTexts(actions...)
|
err := driverExt.TapByTexts(actions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -393,7 +393,7 @@ func TestTapTexts(t *testing.T) {
|
|||||||
|
|
||||||
func TestRecordVideo(t *testing.T) {
|
func TestRecordVideo(t *testing.T) {
|
||||||
setupAndroidAdbDriver(t)
|
setupAndroidAdbDriver(t)
|
||||||
path, err := driverExt.GetDriver().(*ADBDriver).RecordScreen("", 5*time.Second)
|
path, err := driverExt.RecordScreen("", 5*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -403,7 +403,7 @@ func TestRecordVideo(t *testing.T) {
|
|||||||
func Test_Android_Backspace(t *testing.T) {
|
func Test_Android_Backspace(t *testing.T) {
|
||||||
setupAndroidAdbDriver(t)
|
setupAndroidAdbDriver(t)
|
||||||
|
|
||||||
err := driverExt.GetDriver().Backspace(1)
|
err := driverExt.Backspace(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func TestIOSDemo(t *testing.T) {
|
|||||||
|
|
||||||
// release session
|
// release session
|
||||||
defer func() {
|
defer func() {
|
||||||
driverExt.GetDriver().DeleteSession()
|
driverExt.DeleteSession()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 持续监测手机屏幕,直到出现青少年模式弹窗后,点击「我知道了」
|
// 持续监测手机屏幕,直到出现青少年模式弹窗后,点击「我知道了」
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ type IDriver interface {
|
|||||||
Homescreen() error
|
Homescreen() error
|
||||||
Unlock() (err error)
|
Unlock() (err error)
|
||||||
// tap
|
// tap
|
||||||
Tap(x, y float64, opts ...option.ActionOption) error
|
TapXY(x, y float64, opts ...option.ActionOption) error
|
||||||
DoubleTap(x, y float64, opts ...option.ActionOption) error
|
DoubleTapXY(x, y float64, opts ...option.ActionOption) error
|
||||||
TapByText(text string, opts ...option.ActionOption) error // TODO: remove
|
TapByText(text string, opts ...option.ActionOption) error // TODO: remove
|
||||||
TapByTexts(actions ...TapTextAction) error // TODO: remove
|
TapByTexts(actions ...TapTextAction) error // TODO: remove
|
||||||
// swipe
|
// swipe
|
||||||
@@ -93,7 +93,7 @@ type IDriver interface {
|
|||||||
func NewXTDriver(driver IDriver, opts ...ai.AIServiceOption) *XTDriver {
|
func NewXTDriver(driver IDriver, opts ...ai.AIServiceOption) *XTDriver {
|
||||||
services := ai.NewAIService(opts...)
|
services := ai.NewAIService(opts...)
|
||||||
driverExt := &XTDriver{
|
driverExt := &XTDriver{
|
||||||
Driver: driver,
|
IDriver: driver,
|
||||||
CVService: services.ICVService,
|
CVService: services.ICVService,
|
||||||
LLMService: services.ILLMService,
|
LLMService: services.ILLMService,
|
||||||
}
|
}
|
||||||
@@ -104,8 +104,6 @@ var _ IDriverExt = (*XTDriver)(nil)
|
|||||||
|
|
||||||
// XTDriver = IDriver + AI
|
// XTDriver = IDriver + AI
|
||||||
type IDriverExt interface {
|
type IDriverExt interface {
|
||||||
GetDriver() IDriver // get original driver
|
|
||||||
|
|
||||||
GetScreenResult(opts ...option.ActionOption) (screenResult *ScreenResult, err error)
|
GetScreenResult(opts ...option.ActionOption) (screenResult *ScreenResult, err error)
|
||||||
GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.OCRTexts, err error)
|
GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.OCRTexts, err error)
|
||||||
GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error)
|
GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error)
|
||||||
@@ -134,18 +132,14 @@ type IDriverExt interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type XTDriver struct {
|
type XTDriver struct {
|
||||||
Driver IDriver
|
IDriver
|
||||||
CVService ai.ICVService // OCR/CV
|
CVService ai.ICVService // OCR/CV
|
||||||
LLMService ai.ILLMService // LLM
|
LLMService ai.ILLMService // LLM
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) GetDriver() IDriver {
|
|
||||||
return dExt.Driver
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *XTDriver) Setup() error {
|
func (dExt *XTDriver) Setup() error {
|
||||||
// unlock device screen
|
// unlock device screen
|
||||||
err := dExt.Driver.Unlock()
|
err := dExt.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("unlock device screen failed")
|
log.Error().Err(err).Msg("unlock device screen failed")
|
||||||
return err
|
return err
|
||||||
@@ -188,7 +182,7 @@ func (dExt *XTDriver) assertOCR(text, assert string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) assertForegroundApp(appName, assert string) (err error) {
|
func (dExt *XTDriver) assertForegroundApp(appName, assert string) (err error) {
|
||||||
err = dExt.Driver.AssertForegroundApp(appName)
|
err = dExt.AssertForegroundApp(appName)
|
||||||
switch assert {
|
switch assert {
|
||||||
case AssertionEqual:
|
case AssertionEqual:
|
||||||
if err != nil {
|
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 {
|
func (dExt *XTDriver) GenAbsScope(x1, y1, x2, y2 float64) option.AbsScope {
|
||||||
// convert relative scope to absolute scope
|
// convert relative scope to absolute scope
|
||||||
windowSize, _ := dExt.Driver.WindowSize()
|
windowSize, _ := dExt.WindowSize()
|
||||||
absX1 := int(x1 * float64(windowSize.Width))
|
absX1 := int(x1 * float64(windowSize.Width))
|
||||||
absY1 := int(y1 * float64(windowSize.Height))
|
absY1 := int(y1 * float64(windowSize.Height))
|
||||||
absX2 := int(x2 * float64(windowSize.Width))
|
absX2 := int(x2 * float64(windowSize.Width))
|
||||||
@@ -153,13 +153,13 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
}
|
}
|
||||||
case ACTION_AppClear:
|
case ACTION_AppClear:
|
||||||
if packageName, ok := action.Params.(string); ok {
|
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")
|
return errors.Wrap(err, "failed to clear app")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ACTION_AppLaunch:
|
case ACTION_AppLaunch:
|
||||||
if bundleId, ok := action.Params.(string); ok {
|
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",
|
return fmt.Errorf("invalid %s params, should be bundleId(string), got %v",
|
||||||
ACTION_AppLaunch, action.Params)
|
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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
||||||
case ACTION_AppTerminate:
|
case ACTION_AppTerminate:
|
||||||
if bundleId, ok := action.Params.(string); ok {
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
success, err := dExt.Driver.AppTerminate(bundleId)
|
success, err := dExt.AppTerminate(bundleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to terminate app")
|
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)
|
return fmt.Errorf("app_terminate params should be bundleId(string), got %v", action.Params)
|
||||||
case ACTION_Home:
|
case ACTION_Home:
|
||||||
return dExt.Driver.Homescreen()
|
return dExt.Homescreen()
|
||||||
case ACTION_SetIme:
|
case ACTION_SetIme:
|
||||||
if ime, ok := action.Params.(string); ok {
|
if ime, ok := action.Params.(string); ok {
|
||||||
err = dExt.Driver.SetIme(ime)
|
err = dExt.SetIme(ime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to set ime")
|
return errors.Wrap(err, "failed to set ime")
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
case ACTION_GetSource:
|
case ACTION_GetSource:
|
||||||
if packageName, ok := action.Params.(string); ok {
|
if packageName, ok := action.Params.(string); ok {
|
||||||
source := option.NewSourceOption().WithProcessName(packageName)
|
source := option.NewSourceOption().WithProcessName(packageName)
|
||||||
_, err = dExt.Driver.Source(source)
|
_, err = dExt.Source(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to set ime")
|
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
|
// append \n to send text with enter
|
||||||
// send \b\b\b to delete 3 chars
|
// send \b\b\b to delete 3 chars
|
||||||
param := fmt.Sprintf("%v", action.Params)
|
param := fmt.Sprintf("%v", action.Params)
|
||||||
return dExt.Driver.Input(param, action.GetOptions()...)
|
return dExt.Input(param)
|
||||||
case ACTION_Back:
|
case ACTION_Back:
|
||||||
return dExt.Driver.PressBack()
|
return dExt.PressBack()
|
||||||
case ACTION_Sleep:
|
case ACTION_Sleep:
|
||||||
if param, ok := action.Params.(json.Number); ok {
|
if param, ok := action.Params.(json.Number); ok {
|
||||||
seconds, _ := param.Float64()
|
seconds, _ := param.Float64()
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func TestSwipe(t *testing.T) {
|
|||||||
|
|
||||||
func TestTap(t *testing.T) {
|
func TestTap(t *testing.T) {
|
||||||
setupShootsAndroidDriver(t)
|
setupShootsAndroidDriver(t)
|
||||||
err := shootsAndroidDriver.Tap(900, 400)
|
err := shootsAndroidDriver.TapXY(900, 400)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ func TestTap(t *testing.T) {
|
|||||||
|
|
||||||
func TestDoubleTap(t *testing.T) {
|
func TestDoubleTap(t *testing.T) {
|
||||||
setupShootsAndroidDriver(t)
|
setupShootsAndroidDriver(t)
|
||||||
err := shootsAndroidDriver.DoubleTap(500, 500)
|
err := shootsAndroidDriver.DoubleTapXY(500, 500)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,22 +200,22 @@ func (s *ShootsIOSDriver) Orientation() (orientation types.Orientation, err erro
|
|||||||
return s.WDADriver.Orientation()
|
return s.WDADriver.Orientation()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tap Sends a tap event at the coordinate.
|
// TapXY Sends a tap event at the coordinate.
|
||||||
func (s *ShootsIOSDriver) Tap(x, y float64, opts ...option.ActionOption) error {
|
func (s *ShootsIOSDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
err := s.setUpWda()
|
err := s.setUpWda()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.
|
// DoubleTapXY Sends a double tap event at the coordinate.
|
||||||
func (s *ShootsIOSDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
|
func (s *ShootsIOSDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
err := s.setUpWda()
|
err := s.setUpWda()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.
|
// 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 {
|
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{})
|
stopChan := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
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(
|
_ = 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 {
|
func (dExt *XTDriver) Uninstall(packageName string, opts ...option.ActionOption) error {
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
err := dExt.Driver.GetDevice().Uninstall(packageName)
|
err := dExt.GetDevice().Uninstall(packageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("failed to uninstall")
|
log.Warn().Err(err).Msg("failed to uninstall")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
windowSize, err = dExt.Driver.WindowSize()
|
windowSize, err = dExt.WindowSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lastErr = errors.Wrap(code.DeviceGetInfoError, err.Error())
|
lastErr = errors.Wrap(code.DeviceGetInfoError, err.Error())
|
||||||
continue
|
continue
|
||||||
@@ -101,7 +101,7 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cache screen result
|
// cache screen result
|
||||||
dExt.Driver.GetSession().addScreenResult(screenResult)
|
dExt.GetSession().addScreenResult(screenResult)
|
||||||
|
|
||||||
if imageResult != nil {
|
if imageResult != nil {
|
||||||
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
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
|
// GetScreenShot takes screenshot and saves image file to $CWD/screenshots/ folder
|
||||||
func (dExt *XTDriver) GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error) {
|
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")
|
log.Error().Err(err).Msg("capture screenshot data failed")
|
||||||
return nil, "", errors.Wrap(code.DeviceScreenShotError, err.Error())
|
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]
|
// 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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.Driver.Swipe(absFromX, absFromY, absToX, absToY, opts...)
|
err = dExt.Swipe(absFromX, absFromY, absToX, absToY, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(code.MobileUISwipeError, err.Error())
|
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 {
|
func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) error {
|
||||||
// go to home screen
|
// 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")
|
return errors.Wrap(err, "go to home screen failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func TestAndroidSwipeToTapApp(t *testing.T) {
|
|||||||
func TestAndroidSwipeToTapTexts(t *testing.T) {
|
func TestAndroidSwipeToTapTexts(t *testing.T) {
|
||||||
setupAndroidAdbDriver(t)
|
setupAndroidAdbDriver(t)
|
||||||
|
|
||||||
err := driverExt.GetDriver().AppLaunch("com.ss.android.ugc.aweme")
|
err := driverExt.AppLaunch("com.ss.android.ugc.aweme")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
err = driverExt.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, option.WithDirection("up"))
|
err = driverExt.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, option.WithDirection("up"))
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func (dExt *XTDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
func (dExt *XTDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
// tap on absolute coordinate [x, y]
|
// tap on absolute coordinate [x, y]
|
||||||
err := dExt.Driver.Tap(x, y, opts...)
|
err := dExt.TapXY(x, y, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
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)
|
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 {
|
if err != nil {
|
||||||
return err
|
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)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
x = x * float64(windowSize.Width)
|
x = x * float64(windowSize.Width)
|
||||||
y = y * float64(windowSize.Height)
|
y = y * float64(windowSize.Height)
|
||||||
err = dExt.Driver.DoubleTap(x, y, opts...)
|
err = dExt.DoubleTapXY(x, y, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
return errors.Wrap(code.MobileUITapError, err.Error())
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ func (dExt *XTDriver) DoubleTapOffset(param string, xOffset, yOffset float64, op
|
|||||||
return err
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
return errors.Wrap(code.MobileUITapError, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestNewDriverExt(t *testing.T) {
|
|||||||
t.Log(texts)
|
t.Log(texts)
|
||||||
|
|
||||||
// get original dirver
|
// get original dirver
|
||||||
driver = driverExt.GetDriver().(*ADBDriver)
|
driver = driverExt.IDriver.(*ADBDriver)
|
||||||
|
|
||||||
// get device
|
// get device
|
||||||
device = driver.GetDevice().(*AndroidDevice)
|
device = driver.GetDevice().(*AndroidDevice)
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ func (hd *HDCDriver) Orientation() (orientation types.Orientation, err error) {
|
|||||||
return types.OrientationPortrait, nil
|
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...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
|
||||||
if len(actionOptions.Offset) == 2 {
|
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))
|
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
|
return types.ErrDriverNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ func (wd *WDADriver) AssertForegroundApp(bundleId string, viewControllerType ...
|
|||||||
return nil
|
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:)]
|
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
|
||||||
@@ -544,7 +544,7 @@ func (wd *WDADriver) Tap(x, y float64, opts ...option.ActionOption) (err error)
|
|||||||
return
|
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:)]
|
// [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
x = wd.toScale(x)
|
x = wd.toScale(x)
|
||||||
@@ -569,7 +569,7 @@ func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (er
|
|||||||
if actionOptions.Duration == 0 {
|
if actionOptions.Duration == 0 {
|
||||||
opts = append(opts, option.WithDuration(1))
|
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) {
|
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) {
|
func TestInstall(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
err := iOSDriverExt.GetDriver().GetDevice().Install("xxx.ipa",
|
err := iOSDriverExt.GetDevice().Install("xxx.ipa",
|
||||||
option.WithRetryTimes(5))
|
option.WithRetryTimes(5))
|
||||||
log.Error().Err(err)
|
log.Error().Err(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -268,7 +268,7 @@ func Test_remoteWD_AppTerminate(t *testing.T) {
|
|||||||
func Test_remoteWD_Tap(t *testing.T) {
|
func Test_remoteWD_Tap(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
|
|
||||||
err := driver.Tap(200, 300)
|
err := driver.TapXY(200, 300)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -277,7 +277,7 @@ func Test_remoteWD_Tap(t *testing.T) {
|
|||||||
func Test_remoteWD_DoubleTap(t *testing.T) {
|
func Test_remoteWD_DoubleTap(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
|
|
||||||
err := driver.DoubleTap(200, 300)
|
err := driver.DoubleTapXY(200, 300)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
|
|||||||
// release UI driver session
|
// release UI driver session
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, client := range caseRunner.uixtDrivers {
|
for _, client := range caseRunner.uixtDrivers {
|
||||||
client.Driver.DeleteSession()
|
client.DeleteSession()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -604,8 +604,8 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) (summary *TestCa
|
|||||||
"uuid": uuid,
|
"uuid": uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.GetDriver().GetDevice().LogEnabled() {
|
if client.GetDevice().LogEnabled() {
|
||||||
log, err1 := client.GetDriver().StopCaptureLog()
|
log, err1 := client.StopCaptureLog()
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = errors.Wrap(err1, "stop capture log failed")
|
err = errors.Wrap(err1, "stop capture log failed")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func foregroundAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
appInfo, err := dExt.GetDriver().GetForegroundApp()
|
appInfo, err := dExt.GetForegroundApp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
@@ -42,7 +42,7 @@ func clearAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.Driver.AppClear(appClearReq.PackageName)
|
err = dExt.AppClear(appClearReq.PackageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
@@ -69,7 +69,7 @@ func launchAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.GetDriver().AppLaunch(appLaunchReq.PackageName)
|
err = dExt.AppLaunch(appLaunchReq.PackageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to launch app %s", c.HandlerName(), appLaunchReq.PackageName))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to launch app %s", c.HandlerName(), appLaunchReq.PackageName))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
@@ -96,7 +96,7 @@ func terminalAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
success, err := dExt.GetDriver().AppTerminate(appTerminalReq.PackageName)
|
success, err := dExt.AppTerminate(appTerminalReq.PackageName)
|
||||||
if !success {
|
if !success {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to launch app %s", c.HandlerName(), appTerminalReq.PackageName))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to launch app %s", c.HandlerName(), appTerminalReq.PackageName))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func unlockHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.GetDriver().Unlock()
|
err = dExt.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
@@ -37,7 +37,7 @@ func homeHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.GetDriver().Homescreen()
|
err = dExt.Homescreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to enter homescreen", c.HandlerName()))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to enter homescreen", c.HandlerName()))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
@@ -64,7 +64,7 @@ func keycodeHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.GetDriver().PressKeyCode(uixt.KeyCode(keycodeReq.Keycode))
|
err = dExt.PressKeyCode(uixt.KeyCode(keycodeReq.Keycode))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to input keycode %d", c.HandlerName(), keycodeReq.Keycode))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to input keycode %d", c.HandlerName(), keycodeReq.Keycode))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func screenshotHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
raw, err := dExt.GetDriver().Screenshot()
|
raw, err := dExt.Screenshot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get screenshot", c.HandlerName()))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get screenshot", c.HandlerName()))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
@@ -84,7 +84,7 @@ func adbSourceHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
source, err := dExt.GetDriver().Source()
|
source, err := dExt.Source()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get adb source", c.HandlerName()))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get adb source", c.HandlerName()))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func dragHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := dExt.GetDriver().Swipe(
|
err := dExt.Swipe(
|
||||||
dragReq.FromX, dragReq.FromY, dragReq.ToX, dragReq.ToY,
|
dragReq.FromX, dragReq.FromY, dragReq.ToX, dragReq.ToY,
|
||||||
actionOptions...)
|
actionOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -140,7 +140,7 @@ func inputHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dExt.GetDriver().SendKeys(inputReq.Text,
|
err = dExt.SendKeys(inputReq.Text,
|
||||||
option.WithFrequency(inputReq.Frequency))
|
option.WithFrequency(inputReq.Frequency))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to input text %s", c.HandlerName(), inputReq.Text))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to input text %s", c.HandlerName(), inputReq.Text))
|
||||||
|
|||||||
@@ -666,7 +666,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
},
|
},
|
||||||
StartTime: startTime.Unix(),
|
StartTime: startTime.Unix(),
|
||||||
}
|
}
|
||||||
if app, err1 := uiDriver.GetDriver().GetForegroundApp(); err1 == nil {
|
if app, err1 := uiDriver.GetForegroundApp(); err1 == nil {
|
||||||
attachments["foreground_app"] = app.AppBaseInfo
|
attachments["foreground_app"] = app.AppBaseInfo
|
||||||
} else {
|
} else {
|
||||||
log.Warn().Err(err1).Msg("save foreground app failed, ignore")
|
log.Warn().Err(err1).Msg("save foreground app failed, ignore")
|
||||||
@@ -693,7 +693,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save attachments
|
// save attachments
|
||||||
session := uiDriver.GetDriver().GetSession()
|
session := uiDriver.GetSession()
|
||||||
for key, value := range session.GetData(true) {
|
for key, value := range session.GetData(true) {
|
||||||
attachments[key] = value
|
attachments[key] = value
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user