mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
feat: add wait time between swipe and ocr
This commit is contained in:
+12
-5
@@ -66,6 +66,7 @@ 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
|
||||||
|
WaitTime float64 `json:"wait_time,omitempty" yaml:"wait_time,omitempty"` // wait time between swipe and ocr, unit: second
|
||||||
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
|
||||||
Scope []float64 `json:"scope,omitempty" yaml:"scope,omitempty"` // used by ocr to get text position in the scope
|
Scope []float64 `json:"scope,omitempty" yaml:"scope,omitempty"` // used by ocr to get text position in the scope
|
||||||
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
|
||||||
@@ -90,6 +91,12 @@ func WithIndex(index int) ActionOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithWaitTime(sec float64) ActionOption {
|
||||||
|
return func(o *MobileAction) {
|
||||||
|
o.WaitTime = sec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
@@ -413,7 +420,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
action.MaxRetryTimes = 5
|
action.MaxRetryTimes = 5
|
||||||
}
|
}
|
||||||
// swipe next screen until app found
|
// swipe next screen until app found
|
||||||
return dExt.SwipeUntil("left", findApp, foundAppAction, action.MaxRetryTimes)
|
return dExt.SwipeUntil("left", findApp, foundAppAction, action.MaxRetryTimes, action.WaitTime)
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -444,10 +451,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if action.Direction != nil {
|
if action.Direction != nil {
|
||||||
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes)
|
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes, action.WaitTime)
|
||||||
}
|
}
|
||||||
// swipe until found
|
// swipe until found
|
||||||
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes)
|
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes, action.WaitTime)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
||||||
ACTION_SwipeToTapText, action.Params)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
@@ -491,10 +498,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if action.Direction != nil {
|
if action.Direction != nil {
|
||||||
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes)
|
return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes, action.WaitTime)
|
||||||
}
|
}
|
||||||
// swipe until found
|
// swipe until found
|
||||||
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes)
|
return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes, action.WaitTime)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be app text([]string), got %v",
|
return fmt.Errorf("invalid %s params, should be app text([]string), got %v",
|
||||||
ACTION_SwipeToTapText, action.Params)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package uixt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -66,7 +67,7 @@ type FindCondition func(driver *DriverExt) error
|
|||||||
// FoundAction indicates the action to do after a UI element is found
|
// FoundAction indicates the action to do after a UI element is found
|
||||||
type FoundAction func(driver *DriverExt) error
|
type FoundAction func(driver *DriverExt) error
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUntil(direction interface{}, condition FindCondition, action FoundAction, maxTimes int) error {
|
func (dExt *DriverExt) SwipeUntil(direction interface{}, condition FindCondition, action FoundAction, maxTimes int, waitTime float64) error {
|
||||||
for i := 0; i < maxTimes; i++ {
|
for i := 0; i < maxTimes; i++ {
|
||||||
if err := condition(dExt); err == nil {
|
if err := condition(dExt); err == nil {
|
||||||
// do action after found
|
// do action after found
|
||||||
@@ -89,6 +90,8 @@ func (dExt *DriverExt) SwipeUntil(direction interface{}, condition FindCondition
|
|||||||
log.Error().Err(err).Msgf("swipe (%v, %v) to (%v, %v) failed", sx, sy, ex, ey)
|
log.Error().Err(err).Msgf("swipe (%v, %v) to (%v, %v) failed", sx, sy, ex, ey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// wait for swipe action to completed and content to load completely
|
||||||
|
time.Sleep(time.Duration(1000*waitTime) * time.Millisecond)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("swipe %s %d times, match condition failed", direction, maxTimes)
|
return fmt.Errorf("swipe %s %d times, match condition failed", direction, maxTimes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
WithIdentifier = uixt.WithIdentifier
|
WithIdentifier = uixt.WithIdentifier
|
||||||
WithMaxRetryTimes = uixt.WithMaxRetryTimes
|
WithMaxRetryTimes = uixt.WithMaxRetryTimes
|
||||||
|
WithWaitTime = uixt.WithWaitTime
|
||||||
WithIndex = uixt.WithIndex
|
WithIndex = uixt.WithIndex
|
||||||
WithTimeout = uixt.WithTimeout
|
WithTimeout = uixt.WithTimeout
|
||||||
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
|
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
|
||||||
|
|||||||
Reference in New Issue
Block a user