mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix: unittest
This commit is contained in:
@@ -13,7 +13,7 @@ func TestIOSKuaiShouLive(t *testing.T) {
|
|||||||
Config: hrp.NewConfig("直播_快手_关注天窗_ios").
|
Config: hrp.NewConfig("直播_快手_关注天窗_ios").
|
||||||
WithVariables(map[string]interface{}{
|
WithVariables(map[string]interface{}{
|
||||||
"device": "${ENV(UDID)}",
|
"device": "${ENV(UDID)}",
|
||||||
"ups": "大哥,王者",
|
"ups": "${ENV(LIVEUPLIST)}",
|
||||||
}).
|
}).
|
||||||
SetIOS(hrp.WithUDID("$device"), hrp.WithLogOn(true), hrp.WithWDAPort(8100), hrp.WithWDAMjpegPort(9100)),
|
SetIOS(hrp.WithUDID("$device"), hrp.WithLogOn(true), hrp.WithWDAPort(8100), hrp.WithWDAMjpegPort(9100)),
|
||||||
TestSteps: []hrp.IStep{
|
TestSteps: []hrp.IStep{
|
||||||
@@ -36,7 +36,7 @@ func TestIOSKuaiShouLive(t *testing.T) {
|
|||||||
TapByOCR("关注", hrp.WithIndex(1)).Sleep(10),
|
TapByOCR("关注", hrp.WithIndex(1)).Sleep(10),
|
||||||
hrp.NewStep("点击直播标签,进入直播间").
|
hrp.NewStep("点击直播标签,进入直播间").
|
||||||
IOS().
|
IOS().
|
||||||
SwipeToTapTexts([]string{}, hrp.WithFunction("${split_by_comma($ups)}"), hrp.WithCustomDirection(0.6, 0.2, 0.2, 0.2), hrp.WithIdentifier("click_live")).Sleep(60).
|
SwipeToTapTexts("${split_by_comma($ups)}", hrp.WithCustomDirection(0.6, 0.2, 0.2, 0.2), hrp.WithIdentifier("click_live")).Sleep(60).
|
||||||
Validate().
|
Validate().
|
||||||
AssertOCRExists("说点什么", "进入直播间失败"),
|
AssertOCRExists("说点什么", "进入直播间失败"),
|
||||||
hrp.NewStep("下滑进入下一个直播间").
|
hrp.NewStep("下滑进入下一个直播间").
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"name": "直播_快手_关注天窗_ios",
|
"name": "直播_快手_关注天窗_ios",
|
||||||
"variables": {
|
"variables": {
|
||||||
"device": "${ENV(UDID)}",
|
"device": "${ENV(UDID)}",
|
||||||
"ups": "大哥,王者"
|
"ups": "${ENV(LIVEUPLIST)}"
|
||||||
},
|
},
|
||||||
"ios": [
|
"ios": [
|
||||||
{
|
{
|
||||||
@@ -104,15 +104,14 @@
|
|||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"method": "swipe_to_tap_texts",
|
"method": "swipe_to_tap_texts",
|
||||||
"params": [],
|
"params": "${split_by_comma($ups)}",
|
||||||
"identifier": "click_live",
|
"identifier": "click_live",
|
||||||
"direction": [
|
"direction": [
|
||||||
0.6,
|
0.6,
|
||||||
0.2,
|
0.2,
|
||||||
0.2,
|
0.2,
|
||||||
0.2
|
0.2
|
||||||
],
|
]
|
||||||
"function": "${split_by_comma($ups)}"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "sleep",
|
"method": "sleep",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ config:
|
|||||||
name: 直播_快手_关注天窗_ios
|
name: 直播_快手_关注天窗_ios
|
||||||
variables:
|
variables:
|
||||||
device: ${ENV(UDID)}
|
device: ${ENV(UDID)}
|
||||||
ups: 大哥,王者
|
ups: ${ENV(LIVEUPLIST)}
|
||||||
ios:
|
ios:
|
||||||
- udid: $device
|
- udid: $device
|
||||||
port: 8100
|
port: 8100
|
||||||
@@ -55,14 +55,13 @@ teststeps:
|
|||||||
ios:
|
ios:
|
||||||
actions:
|
actions:
|
||||||
- method: swipe_to_tap_texts
|
- method: swipe_to_tap_texts
|
||||||
params: []
|
params: ${split_by_comma($ups)}
|
||||||
identifier: click_live
|
identifier: click_live
|
||||||
direction:
|
direction:
|
||||||
- 0.6
|
- 0.6
|
||||||
- 0.2
|
- 0.2
|
||||||
- 0.2
|
- 0.2
|
||||||
- 0.2
|
- 0.2
|
||||||
function: ${split_by_comma($ups)}
|
|
||||||
- method: sleep
|
- method: sleep
|
||||||
params: 60
|
params: 60
|
||||||
validate:
|
validate:
|
||||||
|
|||||||
+8
-13
@@ -67,7 +67,6 @@ type MobileAction struct {
|
|||||||
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
||||||
MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times
|
MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times
|
||||||
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app
|
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app
|
||||||
Function string `json:"function,omitempty" yaml:"function,omitempty"` // used to replace params
|
|
||||||
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1
|
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1
|
||||||
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action
|
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action
|
||||||
IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found
|
IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found
|
||||||
@@ -90,13 +89,6 @@ func WithIndex(index int) ActionOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithFunction replaces params
|
|
||||||
func WithFunction(function string) ActionOption {
|
|
||||||
return func(o *MobileAction) {
|
|
||||||
o.Function = function
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDirection inputs direction (up, down, left, right)
|
// WithDirection inputs direction (up, down, left, right)
|
||||||
func WithDirection(direction string) ActionOption {
|
func WithDirection(direction string) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *MobileAction) {
|
||||||
@@ -437,14 +429,17 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
ACTION_SwipeToTapText, action.Params)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
case ACTION_SwipeToTapTexts:
|
case ACTION_SwipeToTapTexts:
|
||||||
if texts, ok := action.Params.([]interface{}); ok {
|
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
|
var point PointF
|
||||||
findText := func(d *DriverExt) error {
|
findText := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
var ts []string
|
points, err := d.GetTextXYs(texts)
|
||||||
for _, t := range texts {
|
|
||||||
ts = append(ts, t.(string))
|
|
||||||
}
|
|
||||||
points, err := d.GetTextXYs(ts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ var (
|
|||||||
WithDescription = uixt.WithDescription
|
WithDescription = uixt.WithDescription
|
||||||
WithDirection = uixt.WithDirection
|
WithDirection = uixt.WithDirection
|
||||||
WithCustomDirection = uixt.WithCustomDirection
|
WithCustomDirection = uixt.WithCustomDirection
|
||||||
WithFunction = uixt.WithFunction
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ func (s *StepMobile) SwipeToTapText(text string, options ...uixt.ActionOption) *
|
|||||||
return &StepMobile{step: s.step}
|
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{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_SwipeToTapTexts,
|
Method: uixt.ACTION_SwipeToTapTexts,
|
||||||
Params: texts,
|
Params: texts,
|
||||||
@@ -618,13 +618,6 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
|
|
||||||
// run actions
|
// run actions
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
if action.Function != "" {
|
|
||||||
parsedParams, err := parser.ParseString(action.Function, stepVariables)
|
|
||||||
if err != nil {
|
|
||||||
return stepResult, err
|
|
||||||
}
|
|
||||||
action.Params = parsedParams
|
|
||||||
}
|
|
||||||
if action.Params, err = parser.Parse(action.Params, stepVariables); err != nil {
|
if action.Params, err = parser.Parse(action.Params, stepVariables); err != nil {
|
||||||
return stepResult, errors.Wrap(err, "parse action params failed")
|
return stepResult, errors.Wrap(err, "parse action params failed")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user