mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-06 20:32:44 +08:00
fix: wda offset error by scale
This commit is contained in:
@@ -30,7 +30,8 @@
|
||||
"params": "$app_name",
|
||||
"options": {
|
||||
"identifier": "启动抖音",
|
||||
"max_retry_times": 5
|
||||
"max_retry_times": 5,
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -72,7 +73,8 @@
|
||||
"method": "tap_ocr",
|
||||
"params": "商城",
|
||||
"options": {
|
||||
"identifier": "点击商城"
|
||||
"identifier": "点击商城",
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -90,11 +92,14 @@
|
||||
{
|
||||
"method": "tap_ocr",
|
||||
"params": "推荐",
|
||||
"identifier": "点击推荐",
|
||||
"offset": [
|
||||
0,
|
||||
-1
|
||||
]
|
||||
"options": {
|
||||
"identifier": "点击推荐",
|
||||
"offset": [
|
||||
0,
|
||||
-1
|
||||
],
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "sleep",
|
||||
@@ -112,7 +117,8 @@
|
||||
"method": "swipe_direction",
|
||||
"params": "up",
|
||||
"options": {
|
||||
"identifier": "第 1 次上划"
|
||||
"identifier": "第 1 次上划",
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -123,7 +129,8 @@
|
||||
"method": "swipe_direction",
|
||||
"params": "up",
|
||||
"options": {
|
||||
"identifier": "第 2 次上划"
|
||||
"identifier": "第 2 次上划",
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -134,7 +141,8 @@
|
||||
"method": "swipe_direction",
|
||||
"params": "up",
|
||||
"options": {
|
||||
"identifier": "第 3 次上划"
|
||||
"identifier": "第 3 次上划",
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -148,7 +156,8 @@
|
||||
0.1
|
||||
],
|
||||
"options": {
|
||||
"identifier": "点击进入搜索框"
|
||||
"identifier": "点击进入搜索框",
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -159,7 +168,8 @@
|
||||
"method": "input",
|
||||
"params": "httprunner 发版记录",
|
||||
"options": {
|
||||
"identifier": "输入搜索关键词"
|
||||
"identifier": "输入搜索关键词",
|
||||
"pre_mark_operation": true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -27,23 +27,30 @@ func TestWDALog(t *testing.T) {
|
||||
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
|
||||
SwipeToTapApp("$app_name",
|
||||
option.WithMaxRetryTimes(5),
|
||||
option.WithIdentifier("启动抖音")).Sleep(5).
|
||||
option.WithIdentifier("启动抖音"),
|
||||
option.WithPreMarkOperation(true)).Sleep(5).
|
||||
Validate().
|
||||
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
IOS().
|
||||
TapByOCR("我知道了", option.WithIgnoreNotFoundError(true)),
|
||||
TapByOCR("我知道了",
|
||||
option.WithIgnoreNotFoundError(true)),
|
||||
hrp.NewStep("进入购物页").
|
||||
IOS().TapByOCR("商城", option.WithIdentifier("点击商城")).Sleep(5),
|
||||
IOS().TapByOCR("商城",
|
||||
option.WithIdentifier("点击商城"),
|
||||
option.WithPreMarkOperation(true)).Sleep(5),
|
||||
hrp.NewStep("进入推荐页").
|
||||
IOS().TapByOCR("推荐", option.WithIdentifier("点击推荐")).Sleep(5),
|
||||
IOS().TapByOCR("推荐",
|
||||
option.WithIdentifier("点击推荐"),
|
||||
option.WithPreMarkOperation(true),
|
||||
option.WithTapOffset(0, -1)).Sleep(5),
|
||||
hrp.NewStep("向上滑动 2 次").
|
||||
IOS().
|
||||
SwipeUp(option.WithIdentifier("第 1 次上划")).Sleep(2).
|
||||
SwipeUp(option.WithIdentifier("第 2 次上划")).Sleep(2).
|
||||
SwipeUp(option.WithIdentifier("第 3 次上划")).Sleep(2).
|
||||
TapXY(0.9, 0.1, option.WithIdentifier("点击进入搜索框")).Sleep(2).
|
||||
Input("httprunner 发版记录", option.WithIdentifier("输入搜索关键词")).
|
||||
SwipeUp(option.WithIdentifier("第 1 次上划"), option.WithPreMarkOperation(true)).Sleep(2).
|
||||
SwipeUp(option.WithIdentifier("第 2 次上划"), option.WithPreMarkOperation(true)).Sleep(2).
|
||||
SwipeUp(option.WithIdentifier("第 3 次上划"), option.WithPreMarkOperation(true)).Sleep(2).
|
||||
TapXY(0.9, 0.1, option.WithIdentifier("点击进入搜索框"), option.WithPreMarkOperation(true)).Sleep(2).
|
||||
Input("httprunner 发版记录", option.WithIdentifier("输入搜索关键词"), option.WithPreMarkOperation(true)).
|
||||
TapByOCR("搜索", option.WithIdentifier("点击搜索")),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -75,6 +75,6 @@ func TestLoadCaseWithTapOffset(t *testing.T) {
|
||||
action := tc.Steps[3].IOS.Actions[0]
|
||||
assert.Equal(t, option.ACTION_TapByOCR, action.Method)
|
||||
assert.Equal(t, "推荐", action.Params)
|
||||
assert.Equal(t, "点击推荐", action.ActionOptions.Identifier)
|
||||
assert.Equal(t, []int{0, -1}, action.ActionOptions.ScreenFilterOptions.TapOffset)
|
||||
assert.Equal(t, "点击推荐", action.Options.Identifier)
|
||||
assert.Equal(t, []int{0, -1}, action.Options.ScreenFilterOptions.TapOffset)
|
||||
}
|
||||
|
||||
@@ -538,13 +538,6 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
||||
|
||||
var err error
|
||||
if x, err = wd.toScale(x); err != nil {
|
||||
return err
|
||||
}
|
||||
if y, err = wd.toScale(y); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
x, y, err = preHandler_TapAbsXY(wd, actionOptions, x, y)
|
||||
if err != nil {
|
||||
@@ -552,6 +545,13 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||
}
|
||||
defer postHandler(wd, option.ACTION_TapAbsXY, actionOptions)
|
||||
|
||||
if x, err = wd.toScale(x); err != nil {
|
||||
return err
|
||||
}
|
||||
if y, err = wd.toScale(y); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
"x": x,
|
||||
"y": y,
|
||||
@@ -567,13 +567,6 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
|
||||
// [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
|
||||
|
||||
var err error
|
||||
if x, err = wd.toScale(x); err != nil {
|
||||
return err
|
||||
}
|
||||
if y, err = wd.toScale(y); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
x, y, err = preHandler_DoubleTap(wd, actionOptions, x, y)
|
||||
if err != nil {
|
||||
@@ -581,6 +574,12 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
|
||||
}
|
||||
defer postHandler(wd, option.ACTION_DoubleTapXY, actionOptions)
|
||||
|
||||
if x, err = wd.toScale(x); err != nil {
|
||||
return err
|
||||
}
|
||||
if y, err = wd.toScale(y); err != nil {
|
||||
return err
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"x": x,
|
||||
"y": y,
|
||||
@@ -606,6 +605,13 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
|
||||
// [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)]
|
||||
|
||||
var err error
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
fromX, fromY, toX, toY, err = preHandler_Drag(wd, actionOptions, fromX, fromY, toX, toY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer postHandler(wd, option.ACTION_Drag, actionOptions)
|
||||
|
||||
if fromX, err = wd.toScale(fromX); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -618,14 +624,6 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
|
||||
if toY, err = wd.toScale(toY); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionOptions := option.NewActionOptions(opts...)
|
||||
fromX, fromY, toX, toY, err = preHandler_Drag(wd, actionOptions, fromX, fromY, toX, toY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer postHandler(wd, option.ACTION_Drag, actionOptions)
|
||||
|
||||
data := map[string]interface{}{
|
||||
"fromX": builtin.RoundToOneDecimal(fromX),
|
||||
"fromY": builtin.RoundToOneDecimal(fromY),
|
||||
|
||||
@@ -354,29 +354,52 @@ func (o *ActionOptions) ToMap() map[string]interface{} {
|
||||
}
|
||||
|
||||
func (o *ActionOptions) ApplyTapOffset(absX, absY float64) (float64, float64) {
|
||||
xOffset := 0.0
|
||||
yOffset := 0.0
|
||||
if len(o.TapOffset) == 2 {
|
||||
absX += float64(o.TapOffset[0])
|
||||
absY += float64(o.TapOffset[1])
|
||||
xOffset += float64(o.TapOffset[0])
|
||||
yOffset += float64(o.TapOffset[1])
|
||||
}
|
||||
absX += o.generateRandomOffset()
|
||||
absY += o.generateRandomOffset()
|
||||
return absX, absY
|
||||
xOffset += o.generateRandomOffset()
|
||||
yOffset += o.generateRandomOffset()
|
||||
|
||||
if xOffset != 0.0 || yOffset != 0.0 {
|
||||
log.Debug().
|
||||
Float64("x_offset", xOffset).
|
||||
Float64("y_offset", yOffset).
|
||||
Msg("ApplyTapOffset")
|
||||
}
|
||||
return absX + xOffset, absY + yOffset
|
||||
}
|
||||
|
||||
func (o *ActionOptions) ApplySwipeOffset(absFromX, absFromY, absToX, absToY float64) (
|
||||
float64, float64, float64, float64,
|
||||
) {
|
||||
fromXOffset := 0.0
|
||||
fromYOffset := 0.0
|
||||
toXOffset := 0.0
|
||||
toYOffset := 0.0
|
||||
if len(o.SwipeOffset) == 4 {
|
||||
absFromX += float64(o.SwipeOffset[0])
|
||||
absFromY += float64(o.SwipeOffset[1])
|
||||
absToX += float64(o.SwipeOffset[2])
|
||||
absToY += float64(o.SwipeOffset[3])
|
||||
fromXOffset += float64(o.SwipeOffset[0])
|
||||
fromYOffset += float64(o.SwipeOffset[1])
|
||||
toXOffset += float64(o.SwipeOffset[2])
|
||||
toYOffset += float64(o.SwipeOffset[3])
|
||||
}
|
||||
absFromX += o.generateRandomOffset()
|
||||
absFromY += o.generateRandomOffset()
|
||||
absToX += o.generateRandomOffset()
|
||||
absToY += o.generateRandomOffset()
|
||||
return absFromX, absFromY, absToX, absToY
|
||||
fromXOffset += o.generateRandomOffset()
|
||||
fromYOffset += o.generateRandomOffset()
|
||||
toXOffset += o.generateRandomOffset()
|
||||
toYOffset += o.generateRandomOffset()
|
||||
|
||||
if fromXOffset != 0.0 || fromYOffset != 0.0 || toXOffset != 0.0 || toYOffset != 0.0 {
|
||||
log.Debug().
|
||||
Float64("from_x_offset", fromXOffset).
|
||||
Float64("from_y_offset", fromYOffset).
|
||||
Float64("to_x_offset", toXOffset).
|
||||
Float64("to_y_offset", toYOffset).
|
||||
Msg("ApplySwipeOffset")
|
||||
}
|
||||
return absFromX + fromXOffset, absFromY + fromYOffset,
|
||||
absToX + toXOffset, absToY + toYOffset
|
||||
}
|
||||
|
||||
func (o *ActionOptions) generateRandomOffset() float64 {
|
||||
|
||||
Reference in New Issue
Block a user