refactor: swipe actions

This commit is contained in:
lilong.129
2023-04-27 15:36:55 +08:00
parent df5731aafd
commit 0794ef8296
4 changed files with 49 additions and 39 deletions
+30 -29
View File
@@ -6,43 +6,44 @@ import (
"testing"
)
func TestSwipeUntil(t *testing.T) {
driverExt, err := iosDevice.NewDriver(nil)
func TestAndroidSwipeAction(t *testing.T) {
setupAndroid(t)
action := MobileAction{
Method: ACTION_Swipe,
Params: "up",
}
swipeAction := driverExt.prepareSwipeAction(action)
err := swipeAction(driverExt)
checkErr(t, err)
var point PointF
findApp := func(d *DriverExt) error {
var err error
point, err = d.FindScreenTextByOCR("抖音")
return err
}
foundAppAction := func(d *DriverExt) error {
// click app, launch douyin
return d.TapAbsXY(point.X, point.Y)
action = MobileAction{
Method: ACTION_Swipe,
Params: []float64{0.5, 0.5, 0.5, 0.9},
}
swipeAction = driverExt.prepareSwipeAction(action)
driverExt.Driver.Homescreen()
err = swipeAction(driverExt)
checkErr(t, err)
}
func TestAndroidSwipeToTapApp(t *testing.T) {
setupAndroid(t)
err := driverExt.swipeToTapApp("抖音", MobileAction{})
checkErr(t, err)
}
// swipe to first screen
for i := 0; i < 5; i++ {
driverExt.SwipeRight()
}
func TestAndroidSwipeToTapTexts(t *testing.T) {
setupAndroid(t)
// swipe until app found
err = driverExt.SwipeUntil("left", findApp, foundAppAction, WithDataMaxRetryTimes(10))
err := driverExt.Driver.AppLaunch("com.ss.android.ugc.aweme")
checkErr(t, err)
findLive := func(d *DriverExt) error {
var err error
point, err = d.FindScreenTextByOCR("点击进入直播间")
return err
}
foundLiveAction := func(d *DriverExt) error {
// enter live room
return d.TapAbsXY(point.X, point.Y)
action := MobileAction{
Params: "up",
}
// swipe until live room found
err = driverExt.SwipeUntil("up", findLive, foundLiveAction, WithDataMaxRetryTimes(20))
err = driverExt.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, action)
checkErr(t, err)
}