mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
fix: add swipe_to_tap_texts action
This commit is contained in:
@@ -94,7 +94,7 @@
|
|||||||
"ios": {
|
"ios": {
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"method": "swipe_to_tap_text",
|
"method": "swipe_to_tap_texts",
|
||||||
"params": [
|
"params": [
|
||||||
"理肤泉",
|
"理肤泉",
|
||||||
"婉宝"
|
"婉宝"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ teststeps:
|
|||||||
- name: 向上滑动 2 次
|
- name: 向上滑动 2 次
|
||||||
ios:
|
ios:
|
||||||
actions:
|
actions:
|
||||||
- method: swipe_to_tap_text
|
- method: swipe_to_tap_texts
|
||||||
params:
|
params:
|
||||||
- 理肤泉
|
- 理肤泉
|
||||||
- 婉宝
|
- 婉宝
|
||||||
|
|||||||
+42
-24
@@ -55,8 +55,9 @@ const (
|
|||||||
ACTION_Input MobileMethod = "input"
|
ACTION_Input MobileMethod = "input"
|
||||||
|
|
||||||
// custom actions
|
// custom actions
|
||||||
ACTION_SwipeToTapApp MobileMethod = "swipe_to_tap_app" // swipe left & right to find app and tap
|
ACTION_SwipeToTapApp MobileMethod = "swipe_to_tap_app" // swipe left & right to find app and tap
|
||||||
ACTION_SwipeToTapText MobileMethod = "swipe_to_tap_text" // swipe up & down to find text and tap
|
ACTION_SwipeToTapText MobileMethod = "swipe_to_tap_text" // swipe up & down to find text and tap
|
||||||
|
ACTION_SwipeToTapTexts MobileMethod = "swipe_to_tap_texts" // swipe up & down to find text and tap
|
||||||
)
|
)
|
||||||
|
|
||||||
type MobileAction struct {
|
type MobileAction struct {
|
||||||
@@ -401,17 +402,35 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
return fmt.Errorf("invalid %s params, should be app name(string), got %v",
|
return fmt.Errorf("invalid %s params, should be app name(string), got %v",
|
||||||
ACTION_SwipeToTapApp, action.Params)
|
ACTION_SwipeToTapApp, action.Params)
|
||||||
case ACTION_SwipeToTapText:
|
case ACTION_SwipeToTapText:
|
||||||
var point PointF
|
|
||||||
var findText func(d *DriverExt) error
|
|
||||||
|
|
||||||
if text, ok := action.Params.(string); ok {
|
if text, ok := action.Params.(string); ok {
|
||||||
findText = func(d *DriverExt) error {
|
var point PointF
|
||||||
|
findText := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
point, err = d.GetTextXY(text, action.Index)
|
point, err = d.GetTextXY(text, action.Index)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if texts, ok := action.Params.([]interface{}); ok {
|
foundTextAction := func(d *DriverExt) error {
|
||||||
findText = func(d *DriverExt) error {
|
// tap text
|
||||||
|
return d.TapAbsXY(point.X, point.Y, action.Identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
// default to retry 10 times
|
||||||
|
if action.MaxRetryTimes == 0 {
|
||||||
|
action.MaxRetryTimes = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
if action.Direction != nil {
|
||||||
|
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes)
|
||||||
|
}
|
||||||
|
// swipe until found
|
||||||
|
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
||||||
|
ACTION_SwipeToTapText, action.Params)
|
||||||
|
case ACTION_SwipeToTapTexts:
|
||||||
|
if texts, ok := action.Params.([]interface{}); ok {
|
||||||
|
var point PointF
|
||||||
|
findText := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
var ts []string
|
var ts []string
|
||||||
for _, t := range texts {
|
for _, t := range texts {
|
||||||
@@ -428,25 +447,24 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
return errors.New("failed to find text position")
|
return errors.New("failed to find text position")
|
||||||
}
|
}
|
||||||
} else {
|
foundTextAction := func(d *DriverExt) error {
|
||||||
return fmt.Errorf("invalid %s params, should be app text(string or []string), got %v",
|
// tap text
|
||||||
ACTION_SwipeToTapText, action.Params)
|
return d.TapAbsXY(point.X, point.Y, action.Identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
foundTextAction := func(d *DriverExt) error {
|
// default to retry 10 times
|
||||||
// tap text
|
if action.MaxRetryTimes == 0 {
|
||||||
return d.TapAbsXY(point.X, point.Y, action.Identifier)
|
action.MaxRetryTimes = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to retry 10 times
|
if action.Direction != nil {
|
||||||
if action.MaxRetryTimes == 0 {
|
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes)
|
||||||
action.MaxRetryTimes = 10
|
}
|
||||||
|
// swipe until found
|
||||||
|
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes)
|
||||||
}
|
}
|
||||||
if action.Direction != nil {
|
return fmt.Errorf("invalid %s params, should be app text([]string), got %v",
|
||||||
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
}
|
|
||||||
// swipe until found
|
|
||||||
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes)
|
|
||||||
case AppTerminate:
|
case AppTerminate:
|
||||||
if bundleId, ok := action.Params.(string); ok {
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
success, err := dExt.Driver.AppTerminate(bundleId)
|
success, err := dExt.Driver.AppTerminate(bundleId)
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ func (s *StepAndroid) SwipeToTapText(text string, options ...uixt.ActionOption)
|
|||||||
|
|
||||||
func (s *StepAndroid) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepAndroid {
|
func (s *StepAndroid) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepAndroid {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_SwipeToTapText,
|
Method: uixt.ACTION_SwipeToTapTexts,
|
||||||
Params: texts,
|
Params: texts,
|
||||||
}
|
}
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
|
|||||||
+1
-1
@@ -246,7 +246,7 @@ func (s *StepIOS) SwipeToTapText(text string, options ...uixt.ActionOption) *Ste
|
|||||||
|
|
||||||
func (s *StepIOS) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepIOS {
|
func (s *StepIOS) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepIOS {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_SwipeToTapText,
|
Method: uixt.ACTION_SwipeToTapTexts,
|
||||||
Params: texts,
|
Params: texts,
|
||||||
}
|
}
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
|
|||||||
Reference in New Issue
Block a user