mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 19:47:14 +08:00
fix: fix rotate tap swipe error
This commit is contained in:
@@ -185,6 +185,11 @@ func (ad *adbDriver) StopCamera() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ad *adbDriver) Orientation() (orientation Orientation, err error) {
|
||||||
|
err = errDriverNotImplemented
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Homescreen() (err error) {
|
func (ad *adbDriver) Homescreen() (err error) {
|
||||||
return ad.PressKeyCode(KCHome, KMEmpty)
|
return ad.PressKeyCode(KCHome, KMEmpty)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uiaServerURL = "http://localhost:6790/wd/hub"
|
uiaServerURL = "http://forward-to-6790:6790/wd/hub"
|
||||||
driverExt *DriverExt
|
driverExt *DriverExt
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupAndroid(t *testing.T) {
|
func setupAndroid(t *testing.T) {
|
||||||
device, err := NewAndroidDevice()
|
device, err := NewAndroidDevice()
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
device.UIA2 = true
|
||||||
driverExt, err = device.NewDriver()
|
driverExt, err = device.NewDriver()
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
}
|
}
|
||||||
@@ -215,6 +216,14 @@ func TestDriver_Swipe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDriver_Swipe_Relative(t *testing.T) {
|
||||||
|
setupAndroid(t)
|
||||||
|
err := driverExt.SwipeRelative(0.5, 0.7, 0.5, 0.5)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDriver_Drag(t *testing.T) {
|
func TestDriver_Drag(t *testing.T) {
|
||||||
driver, err := NewUIADriver(nil, uiaServerURL)
|
driver, err := NewUIADriver(nil, uiaServerURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -253,6 +253,20 @@ func (ud *uiaDriver) PressKeyCode(keyCode KeyCode, metaState KeyMeta, flags ...K
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ud *uiaDriver) Orientation() (orientation Orientation, err error) {
|
||||||
|
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
|
||||||
|
var rawResp rawResponse
|
||||||
|
if rawResp, err = ud.httpGET("/session", ud.sessionId, "/orientation"); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
reply := new(struct{ Value Orientation })
|
||||||
|
if err = json.Unmarshal(rawResp, reply); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
orientation = reply.Value
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) Tap(x, y int, options ...ActionOption) error {
|
func (ud *uiaDriver) Tap(x, y int, options ...ActionOption) error {
|
||||||
return ud.TapFloat(float64(x), float64(y), options...)
|
return ud.TapFloat(float64(x), float64(y), options...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -537,6 +537,8 @@ type WebDriver interface {
|
|||||||
// StopCamera Stops the camera for recording
|
// StopCamera Stops the camera for recording
|
||||||
StopCamera() error
|
StopCamera() error
|
||||||
|
|
||||||
|
Orientation() (orientation Orientation, err error)
|
||||||
|
|
||||||
// Tap Sends a tap event at the coordinate.
|
// Tap Sends a tap event at the coordinate.
|
||||||
Tap(x, y int, options ...ActionOption) error
|
Tap(x, y int, options ...ActionOption) error
|
||||||
TapFloat(x, y float64, options ...ActionOption) error
|
TapFloat(x, y float64, options ...ActionOption) error
|
||||||
|
|||||||
+18
-5
@@ -19,17 +19,30 @@ func assertRelative(p float64) bool {
|
|||||||
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
width := dExt.windowSize.Width
|
width := dExt.windowSize.Width
|
||||||
height := dExt.windowSize.Height
|
height := dExt.windowSize.Height
|
||||||
|
orientation, err := dExt.Driver.Orientation()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) get orientation failed, use default orientation",
|
||||||
|
fromX, fromY, toX, toY)
|
||||||
|
orientation = OrientationPortrait
|
||||||
|
}
|
||||||
|
|
||||||
if !assertRelative(fromX) || !assertRelative(fromY) ||
|
if !assertRelative(fromX) || !assertRelative(fromY) ||
|
||||||
!assertRelative(toX) || !assertRelative(toY) {
|
!assertRelative(toX) || !assertRelative(toY) {
|
||||||
return fmt.Errorf("fromX(%f), fromY(%f), toX(%f), toY(%f) must be less than 1",
|
return fmt.Errorf("fromX(%f), fromY(%f), toX(%f), toY(%f) must be less than 1",
|
||||||
fromX, fromY, toX, toY)
|
fromX, fromY, toX, toY)
|
||||||
}
|
}
|
||||||
|
// 左转和右转都是"LANDSCAPE"
|
||||||
fromX = float64(width) * fromX
|
if orientation == OrientationPortrait {
|
||||||
fromY = float64(height) * fromY
|
fromX = float64(width) * fromX
|
||||||
toX = float64(width) * toX
|
fromY = float64(height) * fromY
|
||||||
toY = float64(height) * toY
|
toX = float64(width) * toX
|
||||||
|
toY = float64(height) * toY
|
||||||
|
} else {
|
||||||
|
fromX = float64(height) * fromX
|
||||||
|
fromY = float64(width) * fromY
|
||||||
|
toX = float64(height) * toX
|
||||||
|
toY = float64(width) * toY
|
||||||
|
}
|
||||||
|
|
||||||
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
|
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-4
@@ -2,6 +2,7 @@ package uixt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
|
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
|
||||||
@@ -15,9 +16,19 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...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)
|
||||||
}
|
}
|
||||||
|
|
||||||
x = x * float64(dExt.windowSize.Width)
|
orientation, err := dExt.Driver.Orientation()
|
||||||
y = y * float64(dExt.windowSize.Height)
|
if err != nil {
|
||||||
|
log.Warn().Err(err).Msgf("tap (%v, %v) get orientation failed, use default orientation",
|
||||||
|
x, y)
|
||||||
|
orientation = OrientationPortrait
|
||||||
|
}
|
||||||
|
if orientation == OrientationPortrait {
|
||||||
|
x = x * float64(dExt.windowSize.Width)
|
||||||
|
y = y * float64(dExt.windowSize.Height)
|
||||||
|
} else {
|
||||||
|
x = x * float64(dExt.windowSize.Height)
|
||||||
|
y = y * float64(dExt.windowSize.Width)
|
||||||
|
}
|
||||||
return dExt.TapAbsXY(x, y, options...)
|
return dExt.TapAbsXY(x, y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +97,19 @@ func (dExt *DriverExt) DoubleTapXY(x, y float64) error {
|
|||||||
if x > 1 || y > 1 {
|
if x > 1 || y > 1 {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
orientation, err := dExt.Driver.Orientation()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Err(err).Msgf("tap (%v, %v) get orientation failed, use default orientation",
|
||||||
|
x, y)
|
||||||
|
orientation = OrientationPortrait
|
||||||
|
}
|
||||||
|
if orientation == OrientationPortrait {
|
||||||
|
x = x * float64(dExt.windowSize.Width)
|
||||||
|
y = y * float64(dExt.windowSize.Height)
|
||||||
|
} else {
|
||||||
|
x = x * float64(dExt.windowSize.Height)
|
||||||
|
y = y * float64(dExt.windowSize.Width)
|
||||||
|
}
|
||||||
x = x * float64(dExt.windowSize.Width)
|
x = x * float64(dExt.windowSize.Width)
|
||||||
y = y * float64(dExt.windowSize.Height)
|
y = y * float64(dExt.windowSize.Height)
|
||||||
return dExt.Driver.DoubleTapFloat(x, y)
|
return dExt.Driver.DoubleTapFloat(x, y)
|
||||||
|
|||||||
Reference in New Issue
Block a user