Merge pull request #1495 from httprunner/dev-v4.3-bugfix

feat: input params using function in SwipeToTapTexts of ui automation
This commit is contained in:
debugtalk
2022-10-13 16:48:02 +08:00
committed by GitHub
6 changed files with 310 additions and 6 deletions

View File

@@ -0,0 +1,60 @@
//go:build localtest
package uitest
import (
"testing"
"github.com/httprunner/httprunner/v4/hrp"
)
func TestIOSKuaiShouLive(t *testing.T) {
testCase := &hrp.TestCase{
Config: hrp.NewConfig("直播_快手_关注天窗_ios").
WithVariables(map[string]interface{}{
"device": "${ENV(UDID)}",
"ups": "${ENV(LIVEUPLIST)}",
}).
SetIOS(hrp.WithUDID("$device"), hrp.WithLogOn(true), hrp.WithWDAPort(8100), hrp.WithWDAMjpegPort(9100)),
TestSteps: []hrp.IStep{
hrp.NewStep("启动快手").
IOS().
AppTerminate("com.jiangjia.gif").
AppLaunch("com.jiangjia.gif").
Home().
SwipeToTapApp("快手", hrp.WithMaxRetryTimes(5)).Sleep(10).
Validate().
AssertOCRExists("精选", "进入快手失败"),
hrp.NewStep("点击首页").
IOS().
TapByOCR("首页", hrp.WithIndex(-1)).Sleep(10),
hrp.NewStep("点击发现页").
IOS().
TapByOCR("发现", hrp.WithIndex(1)).Sleep(10),
hrp.NewStep("点击关注页").
IOS().
TapByOCR("关注", hrp.WithIndex(1)).Sleep(10),
hrp.NewStep("点击直播标签,进入直播间").
IOS().
SwipeToTapTexts("${split_by_comma($ups)}", hrp.WithCustomDirection(0.6, 0.2, 0.2, 0.2), hrp.WithIdentifier("click_live")).Sleep(60).
Validate().
AssertOCRExists("说点什么", "进入直播间失败"),
hrp.NewStep("下滑进入下一个直播间").
IOS().
Swipe(0.9, 0.7, 0.9, 0.3, hrp.WithIdentifier("slide_in_live")).Sleep(60),
},
}
if err := testCase.Dump2JSON("ios_kuaishou_follow_live_test.json"); err != nil {
t.Fatal(err)
}
if err := testCase.Dump2YAML("ios_kuaishou_follow_live_test.yaml"); err != nil {
t.Fatal(err)
}
runner := hrp.NewRunner(t).SetSaveTests(true)
err := runner.Run(testCase)
if err != nil {
t.Fatal(err)
}
}

View File

@@ -0,0 +1,153 @@
{
"config": {
"name": "直播_快手_关注天窗_ios",
"variables": {
"device": "${ENV(UDID)}",
"ups": "${ENV(LIVEUPLIST)}"
},
"ios": [
{
"udid": "$device",
"port": 8100,
"mjpeg_port": 9100,
"log_on": true
}
]
},
"teststeps": [
{
"name": "启动快手",
"ios": {
"actions": [
{
"method": "app_terminate",
"params": "com.jiangjia.gif"
},
{
"method": "app_launch",
"params": "com.jiangjia.gif"
},
{
"method": "home"
},
{
"method": "swipe_to_tap_app",
"params": "快手",
"max_retry_times": 5
},
{
"method": "sleep",
"params": 10
}
]
},
"validate": [
{
"check": "ui_ocr",
"assert": "exists",
"expect": "精选",
"msg": "进入快手失败"
}
]
},
{
"name": "点击首页",
"ios": {
"actions": [
{
"method": "tap_ocr",
"params": "首页",
"index": -1
},
{
"method": "sleep",
"params": 10
}
]
}
},
{
"name": "点击发现页",
"ios": {
"actions": [
{
"method": "tap_ocr",
"params": "发现",
"index": 1
},
{
"method": "sleep",
"params": 10
}
]
}
},
{
"name": "点击关注页",
"ios": {
"actions": [
{
"method": "tap_ocr",
"params": "关注",
"index": 1
},
{
"method": "sleep",
"params": 10
}
]
}
},
{
"name": "点击直播标签,进入直播间",
"ios": {
"actions": [
{
"method": "swipe_to_tap_texts",
"params": "${split_by_comma($ups)}",
"identifier": "click_live",
"direction": [
0.6,
0.2,
0.2,
0.2
]
},
{
"method": "sleep",
"params": 60
}
]
},
"validate": [
{
"check": "ui_ocr",
"assert": "exists",
"expect": "说点什么",
"msg": "进入直播间失败"
}
]
},
{
"name": "下滑进入下一个直播间",
"ios": {
"actions": [
{
"method": "swipe",
"params": [
0.9,
0.7,
0.9,
0.3
],
"identifier": "slide_in_live"
},
{
"method": "sleep",
"params": 60
}
]
}
}
]
}

View File

@@ -0,0 +1,83 @@
config:
name: 直播_快手_关注天窗_ios
variables:
device: ${ENV(UDID)}
ups: ${ENV(LIVEUPLIST)}
ios:
- udid: $device
port: 8100
mjpeg_port: 9100
log_on: true
teststeps:
- name: 启动快手
ios:
actions:
- method: app_terminate
params: com.jiangjia.gif
- method: app_launch
params: com.jiangjia.gif
- method: home
- method: swipe_to_tap_app
params: 快手
max_retry_times: 5
- method: sleep
params: 10
validate:
- check: ui_ocr
assert: exists
expect: 精选
msg: 进入快手失败
- name: 点击首页
ios:
actions:
- method: tap_ocr
params: 首页
index: -1
- method: sleep
params: 10
- name: 点击发现页
ios:
actions:
- method: tap_ocr
params: 发现
index: 1
- method: sleep
params: 10
- name: 点击关注页
ios:
actions:
- method: tap_ocr
params: 关注
index: 1
- method: sleep
params: 10
- name: 点击直播标签,进入直播间
ios:
actions:
- method: swipe_to_tap_texts
params: ${split_by_comma($ups)}
identifier: click_live
direction:
- 0.6
- 0.2
- 0.2
- 0.2
- method: sleep
params: 60
validate:
- check: ui_ocr
assert: exists
expect: 说点什么
msg: 进入直播间失败
- name: 下滑进入下一个直播间
ios:
actions:
- method: swipe
params:
- 0.9
- 0.7
- 0.9
- 0.3
identifier: slide_in_live
- method: sleep
params: 60

View File

@@ -28,6 +28,7 @@ var Functions = map[string]interface{}{
"md5": MD5, // call with one argument
"parameterize": loadFromCSV,
"P": loadFromCSV,
"split_by_comma": splitByComma, // call with one argument
"environ": os.Getenv,
"ENV": os.Getenv,
"load_ws_message": loadMessage,
@@ -225,3 +226,7 @@ func multipartContentType(w *TFormDataWriter) string {
}
return w.Writer.FormDataContentType()
}
func splitByComma(s string) []string {
return strings.Split(s, ",")
}

View File

@@ -429,14 +429,17 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
ACTION_SwipeToTapText, action.Params)
case ACTION_SwipeToTapTexts:
if texts, ok := action.Params.([]interface{}); ok {
var textList []string
for _, t := range texts {
textList = append(textList, t.(string))
}
action.Params = textList
}
if texts, ok := action.Params.([]string); ok {
var point PointF
findText := func(d *DriverExt) error {
var err error
var ts []string
for _, t := range texts {
ts = append(ts, t.(string))
}
points, err := d.GetTextXYs(ts)
points, err := d.GetTextXYs(texts)
if err != nil {
return err
}

View File

@@ -263,7 +263,7 @@ func (s *StepMobile) SwipeToTapText(text string, options ...uixt.ActionOption) *
return &StepMobile{step: s.step}
}
func (s *StepMobile) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepMobile {
func (s *StepMobile) SwipeToTapTexts(texts interface{}, options ...uixt.ActionOption) *StepMobile {
action := uixt.MobileAction{
Method: uixt.ACTION_SwipeToTapTexts,
Params: texts,