mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: swipe with identifier for logging
This commit is contained in:
2
go.mod
2
go.mod
@@ -40,4 +40,4 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// replace github.com/httprunner/funplugin => ../funplugin
|
// replace github.com/httprunner/funplugin => ../funplugin
|
||||||
replace github.com/electricbubble/gwda => github.com/debugtalk/gwda v0.0.0-20220828065105-59203789a7e7
|
replace github.com/electricbubble/gwda => github.com/debugtalk/gwda v0.0.0-20220920103757-8c05b6218f45
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -94,8 +94,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/debugtalk/gwda v0.0.0-20220828065105-59203789a7e7 h1:pAvqLivdxSqCttO6lbEzg/zjxJO6oOQayfPKqBVD3t0=
|
github.com/debugtalk/gwda v0.0.0-20220920103757-8c05b6218f45 h1:n/O+tMRl7XmuP778Oy2wunq8QpftRS0rlBkKumaJSbc=
|
||||||
github.com/debugtalk/gwda v0.0.0-20220828065105-59203789a7e7/go.mod h1:kyzKpP1/iKJ2i4AxmT8sEmSvB8Pz5NcDVwc/m/Jsg6k=
|
github.com/debugtalk/gwda v0.0.0-20220920103757-8c05b6218f45/go.mod h1:kyzKpP1/iKJ2i4AxmT8sEmSvB8Pz5NcDVwc/m/Jsg6k=
|
||||||
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||||
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||||
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package uixt
|
package uixt
|
||||||
|
|
||||||
|
import "github.com/electricbubble/gwda"
|
||||||
|
|
||||||
func (dExt *DriverExt) Drag(pathname string, toX, toY int, pressForDuration ...float64) (err error) {
|
func (dExt *DriverExt) Drag(pathname string, toX, toY int, pressForDuration ...float64) (err error) {
|
||||||
return dExt.DragFloat(pathname, float64(toX), float64(toY), pressForDuration...)
|
return dExt.DragFloat(pathname, float64(toX), float64(toY), pressForDuration...)
|
||||||
}
|
}
|
||||||
@@ -25,5 +27,6 @@ func (dExt *DriverExt) DragOffsetFloat(pathname string, toX, toY, xOffset, yOffs
|
|||||||
fromX := x + width*xOffset
|
fromX := x + width*xOffset
|
||||||
fromY := y + height*yOffset
|
fromY := y + height*yOffset
|
||||||
|
|
||||||
return dExt.WebDriver.DragFloat(fromX, fromY, toX, toY, pressForDuration[0])
|
return dExt.WebDriver.DragFloat(fromX, fromY, toX, toY,
|
||||||
|
gwda.WithPressDuration(pressForDuration[0]))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,25 +3,68 @@ package uixt
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/electricbubble/gwda"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeTo(direction string) (err error) {
|
func assertRelative(p float64) bool {
|
||||||
|
return p >= 0 && p <= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
||||||
|
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, identifier ...string) error {
|
||||||
width := dExt.windowSize.Width
|
width := dExt.windowSize.Width
|
||||||
height := dExt.windowSize.Height
|
height := dExt.windowSize.Height
|
||||||
|
|
||||||
var fromX, fromY, toX, toY int
|
if !assertRelative(fromX) || !assertRelative(fromY) ||
|
||||||
|
!assertRelative(toX) || !assertRelative(toY) {
|
||||||
|
return fmt.Errorf("fromX(%f), fromY(%f), toX(%f), toY(%f) must be less than 1",
|
||||||
|
fromX, fromY, toX, toY)
|
||||||
|
}
|
||||||
|
|
||||||
|
fromX = float64(width) * fromX
|
||||||
|
fromY = float64(height) * fromY
|
||||||
|
toX = float64(width) * toX
|
||||||
|
toY = float64(height) * toY
|
||||||
|
|
||||||
|
if len(identifier) > 0 && identifier[0] != "" {
|
||||||
|
option := gwda.WithCustomOption("log", map[string]interface{}{
|
||||||
|
"enable": true,
|
||||||
|
"data": identifier[0],
|
||||||
|
})
|
||||||
|
dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY, option)
|
||||||
|
}
|
||||||
|
return dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) SwipeTo(direction string, identifier ...string) (err error) {
|
||||||
switch direction {
|
switch direction {
|
||||||
case "up":
|
case "up":
|
||||||
fromX, fromY, toX, toY = width/2, height*3/4, width/2, height*1/4
|
return dExt.SwipeUp(identifier...)
|
||||||
case "down":
|
case "down":
|
||||||
fromX, fromY, toX, toY = width/2, height*1/4, width/2, height*3/4
|
return dExt.SwipeDown(identifier...)
|
||||||
case "left":
|
case "left":
|
||||||
fromX, fromY, toX, toY = width*3/4, height/2, width*1/4, height/2
|
return dExt.SwipeLeft(identifier...)
|
||||||
case "right":
|
case "right":
|
||||||
fromX, fromY, toX, toY = width*1/4, height/2, width*3/4, height/2
|
return dExt.SwipeRight(identifier...)
|
||||||
}
|
}
|
||||||
return dExt.WebDriver.Swipe(fromX, fromY, toX, toY)
|
return fmt.Errorf("unexpected direction: %s", direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) SwipeUp(identifier ...string) (err error) {
|
||||||
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, identifier...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) SwipeDown(identifier ...string) (err error) {
|
||||||
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, identifier...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) SwipeLeft(identifier ...string) (err error) {
|
||||||
|
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, identifier...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) SwipeRight(identifier ...string) (err error) {
|
||||||
|
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, identifier...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindCondition indicates the condition to find a UI element
|
// FindCondition indicates the condition to find a UI element
|
||||||
@@ -42,119 +85,3 @@ func (dExt *DriverExt) SwipeUntil(direction string, condition FindCondition, act
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("swipe %s %d times, match condition failed", direction, maxTimes)
|
return fmt.Errorf("swipe %s %d times, match condition failed", direction, maxTimes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) Swipe(pathname string, toX, toY int) (err error) {
|
|
||||||
return dExt.SwipeFloat(pathname, float64(toX), float64(toY))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeFloat(pathname string, toX, toY float64) (err error) {
|
|
||||||
return dExt.SwipeOffsetFloat(pathname, toX, toY, 0.5, 0.5)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeOffset(pathname string, toX, toY int, xOffset, yOffset float64) (err error) {
|
|
||||||
return dExt.SwipeOffsetFloat(pathname, float64(toX), float64(toY), xOffset, yOffset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeOffsetFloat(pathname string, toX, toY, xOffset, yOffset float64) (err error) {
|
|
||||||
var x, y, width, height float64
|
|
||||||
if x, y, width, height, err = dExt.FindUIRectInUIKit(pathname); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fromX := x + width*xOffset
|
|
||||||
fromY := y + height*yOffset
|
|
||||||
|
|
||||||
return dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUp(pathname string, distance ...float64) (err error) {
|
|
||||||
return dExt.SwipeUpOffset(pathname, 0.5, 0.9, distance...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUpOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
|
|
||||||
if len(distance) == 0 {
|
|
||||||
distance = []float64{1.0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var x, y, width, height float64
|
|
||||||
if x, y, width, height, err = dExt.FindUIRectInUIKit(pathname); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fromX := x + width*xOffset
|
|
||||||
fromY := (y + height) - height*(1.0-yOffset)
|
|
||||||
|
|
||||||
toX := fromX
|
|
||||||
toY := fromY - height*distance[0]
|
|
||||||
|
|
||||||
return dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeDown(pathname string, distance ...float64) (err error) {
|
|
||||||
return dExt.SwipeDownOffset(pathname, 0.5, 0.1, distance...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeDownOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
|
|
||||||
if len(distance) == 0 {
|
|
||||||
distance = []float64{1.0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var x, y, width, height float64
|
|
||||||
if x, y, width, height, err = dExt.FindUIRectInUIKit(pathname); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fromX := x + width*xOffset
|
|
||||||
fromY := y + height*yOffset
|
|
||||||
|
|
||||||
toX := fromX
|
|
||||||
toY := fromY + height*distance[0]
|
|
||||||
|
|
||||||
return dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeLeft(pathname string, distance ...float64) (err error) {
|
|
||||||
return dExt.SwipeLeftOffset(pathname, 0.9, 0.5, distance...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeLeftOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
|
|
||||||
if len(distance) == 0 {
|
|
||||||
distance = []float64{1.0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var x, y, width, height float64
|
|
||||||
if x, y, width, height, err = dExt.FindUIRectInUIKit(pathname); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fromX := x + width*xOffset
|
|
||||||
fromY := y + height*yOffset
|
|
||||||
|
|
||||||
toX := fromX - width*distance[0]
|
|
||||||
toY := fromY
|
|
||||||
|
|
||||||
return dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeRight(pathname string, distance ...float64) (err error) {
|
|
||||||
return dExt.SwipeRightOffset(pathname, 0.1, 0.5, distance...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeRightOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
|
|
||||||
if len(distance) == 0 {
|
|
||||||
distance = []float64{1.0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var x, y, width, height float64
|
|
||||||
if x, y, width, height, err = dExt.FindUIRectInUIKit(pathname); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fromX := x + width*xOffset
|
|
||||||
fromY := y + height*yOffset
|
|
||||||
|
|
||||||
toX := fromX + width*distance[0]
|
|
||||||
toY := fromY
|
|
||||||
|
|
||||||
return dExt.WebDriver.SwipeFloat(fromX, fromY, toX, toY)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,29 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDriverExt_Swipe(t *testing.T) {
|
|
||||||
driverExt, err := InitWDAClient()
|
|
||||||
checkErr(t, err)
|
|
||||||
|
|
||||||
pathSearch := "/Users/hero/Documents/temp/2020-05/opencv/flag7.png"
|
|
||||||
|
|
||||||
// gwda.SetDebug(true)
|
|
||||||
|
|
||||||
err = driverExt.Swipe(pathSearch, 300, 500)
|
|
||||||
checkErr(t, err)
|
|
||||||
|
|
||||||
err = driverExt.SwipeFloat(pathSearch, 300.9, 500)
|
|
||||||
checkErr(t, err)
|
|
||||||
|
|
||||||
err = driverExt.SwipeOffset(pathSearch, 300, 500, 0.2, 0.5)
|
|
||||||
checkErr(t, err)
|
|
||||||
|
|
||||||
driverExt.Debug(DmNotMatch)
|
|
||||||
|
|
||||||
err = driverExt.OnlyOnceThreshold(0.92).SwipeOffsetFloat(pathSearch, 300.9, 499.1, 0.2, 0.5)
|
|
||||||
checkErr(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSwipeUntil(t *testing.T) {
|
func TestSwipeUntil(t *testing.T) {
|
||||||
driverExt, err := InitWDAClient()
|
driverExt, err := InitWDAClient()
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
@@ -46,7 +23,7 @@ func TestSwipeUntil(t *testing.T) {
|
|||||||
|
|
||||||
// swipe to first screen
|
// swipe to first screen
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
driverExt.SwipeTo("right")
|
driverExt.SwipeRight()
|
||||||
}
|
}
|
||||||
|
|
||||||
// swipe until app found
|
// swipe until app found
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ import (
|
|||||||
|
|
||||||
func (dExt *DriverExt) tapFloat(x, y float64, identifier string) error {
|
func (dExt *DriverExt) tapFloat(x, y float64, identifier string) error {
|
||||||
if len(identifier) > 0 {
|
if len(identifier) > 0 {
|
||||||
option := gwda.DataOption{
|
option := gwda.WithCustomOption("log", map[string]interface{}{
|
||||||
"log": map[string]interface{}{
|
"enable": true,
|
||||||
"enable": true,
|
"data": identifier,
|
||||||
"data": identifier,
|
})
|
||||||
},
|
|
||||||
}
|
|
||||||
return dExt.WebDriver.TapFloat(x, y, option)
|
return dExt.WebDriver.TapFloat(x, y, option)
|
||||||
}
|
}
|
||||||
return dExt.WebDriver.TapFloat(x, y)
|
return dExt.WebDriver.TapFloat(x, y)
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ func (ud *uiDriver) doAction(action MobileAction) error {
|
|||||||
|
|
||||||
// swipe to first screen
|
// swipe to first screen
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
ud.SwipeTo("right")
|
ud.SwipeRight()
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to retry 5 times
|
// default to retry 5 times
|
||||||
@@ -721,8 +721,16 @@ func (ud *uiDriver) doAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", uiDoubleTap, action.Params)
|
return fmt.Errorf("invalid %s params: %v", uiDoubleTap, action.Params)
|
||||||
case uiSwipe:
|
case uiSwipe:
|
||||||
if param, ok := action.Params.(string); ok {
|
if positions, ok := action.Params.([]float64); ok {
|
||||||
return ud.SwipeTo(param)
|
// relative fromX, fromY, toX, toY of window size: [0.5, 0.9, 0.5, 0.1]
|
||||||
|
if len(positions) != 4 {
|
||||||
|
return fmt.Errorf("invalid swipe params [fromX, fromY, toX, toY]: %v", positions)
|
||||||
|
}
|
||||||
|
return ud.SwipeRelative(
|
||||||
|
positions[0], positions[1], positions[2], positions[3], action.Identifier)
|
||||||
|
}
|
||||||
|
if direction, ok := action.Params.(string); ok {
|
||||||
|
return ud.SwipeTo(direction, action.Identifier)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", uiSwipe, action.Params)
|
return fmt.Errorf("invalid %s params: %v", uiSwipe, action.Params)
|
||||||
case uiInput:
|
case uiInput:
|
||||||
|
|||||||
Reference in New Issue
Block a user