mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 06:49:38 +08:00
refactor: merge ActionOption with DataOption
This commit is contained in:
@@ -39,7 +39,7 @@ func TestAndroidKuaiShouFeedCardLive(t *testing.T) {
|
|||||||
uixt.WithCustomDirection(0.9, 0.7, 0.9, 0.3),
|
uixt.WithCustomDirection(0.9, 0.7, 0.9, 0.3),
|
||||||
uixt.WithScope(0.2, 0.5, 0.8, 0.8),
|
uixt.WithScope(0.2, 0.5, 0.8, 0.8),
|
||||||
uixt.WithMaxRetryTimes(20),
|
uixt.WithMaxRetryTimes(20),
|
||||||
uixt.WithWaitTime(60),
|
uixt.WithInterval(60),
|
||||||
uixt.WithIdentifier("click_live"),
|
uixt.WithIdentifier("click_live"),
|
||||||
),
|
),
|
||||||
hrp.NewStep("等待1分钟").
|
hrp.NewStep("等待1分钟").
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func TestIOSDouyinWorldCupLive(t *testing.T) {
|
|||||||
uixt.WithMaxRetryTimes(5),
|
uixt.WithMaxRetryTimes(5),
|
||||||
uixt.WithCustomDirection(0.4, 0.07, 0.6, 0.07), // 滑动 tab,从左到右,解决「世界杯」被遮挡的问题
|
uixt.WithCustomDirection(0.4, 0.07, 0.6, 0.07), // 滑动 tab,从左到右,解决「世界杯」被遮挡的问题
|
||||||
uixt.WithScope(0, 0, 1, 0.15), // 限定 tab 区域
|
uixt.WithScope(0, 0, 1, 0.15), // 限定 tab 区域
|
||||||
uixt.WithWaitTime(1),
|
uixt.WithInterval(1),
|
||||||
),
|
),
|
||||||
hrp.NewStep("点击进入赛程晋级").
|
hrp.NewStep("点击进入赛程晋级").
|
||||||
Loop(5). // 重复执行 5 次
|
Loop(5). // 重复执行 5 次
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package uixt
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -61,116 +62,260 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MobileAction struct {
|
type MobileAction struct {
|
||||||
Method ActionMethod `json:"method,omitempty" yaml:"method,omitempty"`
|
Method ActionMethod `json:"method,omitempty" yaml:"method,omitempty"`
|
||||||
Params interface{} `json:"params,omitempty" yaml:"params,omitempty"`
|
Params interface{} `json:"params,omitempty" yaml:"params,omitempty"`
|
||||||
|
Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
||||||
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
|
|
||||||
WaitTime float64 `json:"wait_time,omitempty" yaml:"wait_time,omitempty"` // wait time between swipe and ocr, unit: second
|
|
||||||
Duration float64 `json:"duration,omitempty" yaml:"duration,omitempty"` // used to set duration of ios swipe action
|
|
||||||
Steps int `json:"steps,omitempty" yaml:"steps,omitempty"` // used to set steps of android swipe action
|
|
||||||
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
|
|
||||||
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
|
||||||
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
|
|
||||||
IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found
|
|
||||||
Text string `json:"text,omitempty" yaml:"text,omitempty"`
|
|
||||||
ID string `json:"id,omitempty" yaml:"id,omitempty"`
|
|
||||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionOption func(o *MobileAction)
|
type ActionOptions struct {
|
||||||
|
// log
|
||||||
|
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
||||||
|
|
||||||
|
// control related
|
||||||
|
MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times
|
||||||
|
IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found
|
||||||
|
Interval float64 `json:"interval,omitempty" yaml:"interval,omitempty"` // interval between retries in seconds
|
||||||
|
PressDuration float64 `json:"duration,omitempty" yaml:"duration,omitempty"` // used to set duration of ios swipe action
|
||||||
|
Steps int `json:"steps,omitempty" yaml:"steps,omitempty"` // used to set steps of android swipe action
|
||||||
|
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app
|
||||||
|
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action
|
||||||
|
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty"`
|
||||||
|
|
||||||
|
// scope related
|
||||||
|
Scope []float64 `json:"scope,omitempty" yaml:"scope,omitempty"` // used by ocr to get text position in the scope
|
||||||
|
AbsScope []int `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"` // used by ocr to get text position in the scope
|
||||||
|
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
||||||
|
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1
|
||||||
|
|
||||||
|
// element related
|
||||||
|
Text string `json:"text,omitempty" yaml:"text,omitempty"`
|
||||||
|
ID string `json:"id,omitempty" yaml:"id,omitempty"`
|
||||||
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||||
|
|
||||||
|
// set custiom options such as textview, id, description
|
||||||
|
Custom map[string]interface{} `json:"custom,omitempty" yaml:"custom,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ActionOptions) Options() []ActionOption {
|
||||||
|
options := make([]ActionOption, 0)
|
||||||
|
|
||||||
|
if o.Identifier != "" {
|
||||||
|
options = append(options, WithIdentifier(o.Identifier))
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.MaxRetryTimes != 0 {
|
||||||
|
options = append(options, WithMaxRetryTimes(o.MaxRetryTimes))
|
||||||
|
}
|
||||||
|
if o.IgnoreNotFoundError {
|
||||||
|
options = append(options, WithIgnoreNotFoundError(true))
|
||||||
|
}
|
||||||
|
if o.Interval != 0 {
|
||||||
|
options = append(options, WithInterval(o.Interval))
|
||||||
|
}
|
||||||
|
if o.PressDuration != 0 {
|
||||||
|
options = append(options, WithPressDuration(o.PressDuration))
|
||||||
|
}
|
||||||
|
if o.Steps != 0 {
|
||||||
|
options = append(options, WithSteps(o.Steps))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v := o.Direction.(type) {
|
||||||
|
case string:
|
||||||
|
options = append(options, WithDirection(v))
|
||||||
|
case []float64:
|
||||||
|
options = append(options, WithCustomDirection(
|
||||||
|
v[0], v[1],
|
||||||
|
v[2], v[3],
|
||||||
|
))
|
||||||
|
case []interface{}:
|
||||||
|
// loaded from json case
|
||||||
|
// custom direction: [fromX, fromY, toX, toY]
|
||||||
|
sx, _ := builtin.Interface2Float64(v[0])
|
||||||
|
sy, _ := builtin.Interface2Float64(v[1])
|
||||||
|
ex, _ := builtin.Interface2Float64(v[2])
|
||||||
|
ey, _ := builtin.Interface2Float64(v[3])
|
||||||
|
options = append(options, WithCustomDirection(
|
||||||
|
sx, sy,
|
||||||
|
ex, ey,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.Timeout != 0 {
|
||||||
|
options = append(options, WithTimeout(o.Timeout))
|
||||||
|
}
|
||||||
|
if o.Frequency != 0 {
|
||||||
|
options = append(options, WithFrequency(o.Frequency))
|
||||||
|
}
|
||||||
|
if len(o.Scope) != 4 {
|
||||||
|
options = append(options, WithScope(0, 0, 1, 1))
|
||||||
|
}
|
||||||
|
if len(o.AbsScope) != 4 {
|
||||||
|
o.AbsScope = []int{0, 0, math.MaxInt64, math.MaxInt64}
|
||||||
|
}
|
||||||
|
if len(o.Offset) == 2 {
|
||||||
|
options = append(options, WithOffset(o.Offset[0], o.Offset[1]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// custom options
|
||||||
|
if o.Custom != nil {
|
||||||
|
for k, v := range o.Custom {
|
||||||
|
options = append(options, WithCustomOption(k, v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewActionOptions(options ...ActionOption) *ActionOptions {
|
||||||
|
actionOptions := &ActionOptions{
|
||||||
|
Custom: make(map[string]interface{}),
|
||||||
|
}
|
||||||
|
for _, option := range options {
|
||||||
|
option(actionOptions)
|
||||||
|
}
|
||||||
|
return actionOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeDataWithOptions(data map[string]interface{}, options ...ActionOption) map[string]interface{} {
|
||||||
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
|
// custom options
|
||||||
|
for k, v := range actionOptions.Custom {
|
||||||
|
data[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
if actionOptions.Identifier != "" {
|
||||||
|
data["log"] = map[string]interface{}{
|
||||||
|
"enable": true,
|
||||||
|
"data": actionOptions.Identifier,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle point offset
|
||||||
|
if len(actionOptions.Offset) == 2 {
|
||||||
|
if x, ok := data["x"]; ok {
|
||||||
|
xf, _ := builtin.Interface2Float64(x)
|
||||||
|
data["x"] = xf + float64(actionOptions.Offset[0])
|
||||||
|
}
|
||||||
|
if y, ok := data["y"]; ok {
|
||||||
|
yf, _ := builtin.Interface2Float64(y)
|
||||||
|
data["y"] = yf + float64(actionOptions.Offset[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if actionOptions.Steps > 0 {
|
||||||
|
data["steps"] = actionOptions.Steps
|
||||||
|
}
|
||||||
|
if _, ok := data["steps"]; !ok {
|
||||||
|
data["steps"] = 12 // default steps
|
||||||
|
}
|
||||||
|
|
||||||
|
if actionOptions.PressDuration > 0 {
|
||||||
|
data["duration"] = actionOptions.PressDuration
|
||||||
|
}
|
||||||
|
if _, ok := data["duration"]; !ok {
|
||||||
|
data["duration"] = 0 // default duration
|
||||||
|
}
|
||||||
|
|
||||||
|
if actionOptions.Frequency > 0 {
|
||||||
|
data["frequency"] = actionOptions.Frequency
|
||||||
|
}
|
||||||
|
if _, ok := data["frequency"]; !ok {
|
||||||
|
data["frequency"] = 60 // default frequency
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := data["isReplace"]; !ok {
|
||||||
|
data["isReplace"] = true // default true
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
type ActionOption func(o *ActionOptions)
|
||||||
|
|
||||||
|
func WithCustomOption(key string, value interface{}) ActionOption {
|
||||||
|
return func(o *ActionOptions) {
|
||||||
|
o.Custom[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithIdentifier(identifier string) ActionOption {
|
func WithIdentifier(identifier string) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Identifier = identifier
|
o.Identifier = identifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithIndex(index int) ActionOption {
|
func WithIndex(index int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Index = index
|
o.Index = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithWaitTime(sec float64) ActionOption {
|
func WithInterval(sec float64) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.WaitTime = sec
|
o.Interval = sec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithDuration(duration float64) ActionOption {
|
func WithPressDuration(duration float64) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Duration = duration
|
o.PressDuration = duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithSteps(steps int) ActionOption {
|
func WithSteps(steps int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Steps = steps
|
o.Steps = steps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 *ActionOptions) {
|
||||||
o.Direction = direction
|
o.Direction = direction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCustomDirection inputs sx, sy, ex, ey
|
// WithCustomDirection inputs sx, sy, ex, ey
|
||||||
func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
|
func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Direction = []float64{sx, sy, ex, ey}
|
o.Direction = []float64{sx, sy, ex, ey}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithScope inputs area of [(x1,y1), (x2,y2)]
|
// WithScope inputs area of [(x1,y1), (x2,y2)]
|
||||||
func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Scope = []float64{x1, y1, x2, y2}
|
o.Scope = []float64{x1, y1, x2, y2}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithOffset(offsetX, offsetY int) ActionOption {
|
func WithOffset(offsetX, offsetY int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Offset = []int{offsetX, offsetY}
|
o.Offset = []int{offsetX, offsetY}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithText(text string) ActionOption {
|
func WithFrequency(frequency int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Text = text
|
o.Frequency = frequency
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithID(id string) ActionOption {
|
|
||||||
return func(o *MobileAction) {
|
|
||||||
o.ID = id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDescription(description string) ActionOption {
|
|
||||||
return func(o *MobileAction) {
|
|
||||||
o.Description = description
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithMaxRetryTimes(maxRetryTimes int) ActionOption {
|
func WithMaxRetryTimes(maxRetryTimes int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.MaxRetryTimes = maxRetryTimes
|
o.MaxRetryTimes = maxRetryTimes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithTimeout(timeout int) ActionOption {
|
func WithTimeout(timeout int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.Timeout = timeout
|
o.Timeout = timeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithIgnoreNotFoundError(ignoreError bool) ActionOption {
|
func WithIgnoreNotFoundError(ignoreError bool) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *ActionOptions) {
|
||||||
o.IgnoreNotFoundError = ignoreError
|
o.IgnoreNotFoundError = ignoreError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,13 +335,13 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
ACTION_AppLaunch, action.Params)
|
ACTION_AppLaunch, action.Params)
|
||||||
case ACTION_SwipeToTapApp:
|
case ACTION_SwipeToTapApp:
|
||||||
if appName, ok := action.Params.(string); ok {
|
if appName, ok := action.Params.(string); ok {
|
||||||
return dExt.swipeToTapApp(appName, action)
|
return dExt.swipeToTapApp(appName, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
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:
|
||||||
if text, ok := action.Params.(string); ok {
|
if text, ok := action.Params.(string); ok {
|
||||||
return dExt.swipeToTapTexts([]string{text}, action)
|
return dExt.swipeToTapTexts([]string{text}, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -209,7 +354,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
action.Params = textList
|
action.Params = textList
|
||||||
}
|
}
|
||||||
if texts, ok := action.Params.([]string); ok {
|
if texts, ok := action.Params.([]string); ok {
|
||||||
return dExt.swipeToTapTexts(texts, action)
|
return dExt.swipeToTapTexts(texts, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -235,7 +380,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
x, _ := location[0].(float64)
|
x, _ := location[0].(float64)
|
||||||
y, _ := location[1].(float64)
|
y, _ := location[1].(float64)
|
||||||
return dExt.TapXY(x, y, WithDataIdentifier(action.Identifier))
|
return dExt.TapXY(x, y, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapXY, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapXY, action.Params)
|
||||||
case ACTION_TapAbsXY:
|
case ACTION_TapAbsXY:
|
||||||
@@ -246,37 +391,32 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
x, _ := location[0].(float64)
|
x, _ := location[0].(float64)
|
||||||
y, _ := location[1].(float64)
|
y, _ := location[1].(float64)
|
||||||
if len(action.Offset) != 2 {
|
if len(action.Options.Offset) != 2 {
|
||||||
action.Offset = []int{0, 0}
|
action.Options.Offset = []int{0, 0}
|
||||||
}
|
}
|
||||||
return dExt.TapAbsXY(x, y, WithDataIdentifier(action.Identifier), WithDataOffset(action.Offset[0], action.Offset[1]))
|
return dExt.TapAbsXY(x, y, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
|
||||||
case ACTION_Tap:
|
case ACTION_Tap:
|
||||||
if param, ok := action.Params.(string); ok {
|
if param, ok := action.Params.(string); ok {
|
||||||
return dExt.Tap(param, WithDataIdentifier(action.Identifier), WithDataIgnoreNotFoundError(true), WithDataIndex(action.Index))
|
return dExt.Tap(param, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
|
||||||
case ACTION_TapByOCR:
|
case ACTION_TapByOCR:
|
||||||
if ocrText, ok := action.Params.(string); ok {
|
if ocrText, ok := action.Params.(string); ok {
|
||||||
if len(action.Scope) != 4 {
|
if len(action.Options.Scope) != 4 {
|
||||||
action.Scope = []float64{0, 0, 1, 1}
|
action.Options.Scope = []float64{0, 0, 1, 1}
|
||||||
}
|
}
|
||||||
if len(action.Offset) != 2 {
|
if len(action.Options.Offset) != 2 {
|
||||||
action.Offset = []int{0, 0}
|
action.Options.Offset = []int{0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
indexOption := WithDataIndex(action.Index)
|
return dExt.TapByOCR(ocrText, action.Options.Options()...)
|
||||||
offsetOption := WithDataOffset(action.Offset[0], action.Offset[1])
|
|
||||||
scopeOption := WithDataScope(dExt.getAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
|
|
||||||
identifierOption := WithDataIdentifier(action.Identifier)
|
|
||||||
IgnoreNotFoundErrorOption := WithDataIgnoreNotFoundError(action.IgnoreNotFoundError)
|
|
||||||
return dExt.TapByOCR(ocrText, identifierOption, IgnoreNotFoundErrorOption, indexOption, scopeOption, offsetOption)
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
||||||
case ACTION_TapByCV:
|
case ACTION_TapByCV:
|
||||||
if imagePath, ok := action.Params.(string); ok {
|
if imagePath, ok := action.Params.(string); ok {
|
||||||
return dExt.TapByCV(imagePath, WithDataIdentifier(action.Identifier), WithDataIgnoreNotFoundError(true), WithDataIndex(action.Index))
|
return dExt.TapByCV(imagePath, action.Options.Options()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
||||||
case ACTION_DoubleTapXY:
|
case ACTION_DoubleTapXY:
|
||||||
@@ -296,27 +436,14 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
||||||
case ACTION_Swipe:
|
case ACTION_Swipe:
|
||||||
swipeAction := dExt.prepareSwipeAction(action)
|
swipeAction := dExt.prepareSwipeAction(action.Options.Options()...)
|
||||||
return swipeAction(dExt)
|
return swipeAction(dExt)
|
||||||
case ACTION_Input:
|
case ACTION_Input:
|
||||||
// input text on current active element
|
// input text on current active element
|
||||||
// append \n to send text with enter
|
// append \n to send text with enter
|
||||||
// send \b\b\b to delete 3 chars
|
// send \b\b\b to delete 3 chars
|
||||||
param := fmt.Sprintf("%v", action.Params)
|
param := fmt.Sprintf("%v", action.Params)
|
||||||
options := []DataOption{}
|
return dExt.Driver.Input(param, action.Options.Options()...)
|
||||||
if action.Text != "" {
|
|
||||||
options = append(options, WithCustomOption("textview", action.Text))
|
|
||||||
}
|
|
||||||
if action.ID != "" {
|
|
||||||
options = append(options, WithCustomOption("id", action.ID))
|
|
||||||
}
|
|
||||||
if action.Description != "" {
|
|
||||||
options = append(options, WithCustomOption("description", action.Description))
|
|
||||||
}
|
|
||||||
if action.Identifier != "" {
|
|
||||||
options = append(options, WithDataIdentifier(action.Identifier))
|
|
||||||
}
|
|
||||||
return dExt.Driver.Input(param, options...)
|
|
||||||
case ACTION_Back:
|
case ACTION_Back:
|
||||||
return dExt.Driver.PressBack()
|
return dExt.Driver.PressBack()
|
||||||
case ACTION_Sleep:
|
case ACTION_Sleep:
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (ad *adbDriver) Scale() (scale float64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PressBack simulates a short press on the BACK button.
|
// PressBack simulates a short press on the BACK button.
|
||||||
func (ad *adbDriver) PressBack(options ...DataOption) (err error) {
|
func (ad *adbDriver) PressBack(options ...ActionOption) (err error) {
|
||||||
// adb shell input keyevent 4
|
// adb shell input keyevent 4
|
||||||
_, err = ad.adbClient.RunShellCommand("input", "keyevent", fmt.Sprintf("%d", KCBack))
|
_, err = ad.adbClient.RunShellCommand("input", "keyevent", fmt.Sprintf("%d", KCBack))
|
||||||
return
|
return
|
||||||
@@ -185,16 +185,16 @@ func (ad *adbDriver) AppTerminate(packageName string) (successful bool, err erro
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Tap(x, y int, options ...DataOption) error {
|
func (ad *adbDriver) Tap(x, y int, options ...ActionOption) error {
|
||||||
return ad.TapFloat(float64(x), float64(y), options...)
|
return ad.TapFloat(float64(x), float64(y), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) TapFloat(x, y float64, options ...DataOption) (err error) {
|
func (ad *adbDriver) TapFloat(x, y float64, options ...ActionOption) (err error) {
|
||||||
dataOptions := NewDataOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
if len(dataOptions.Offset) == 2 {
|
if len(actionOptions.Offset) == 2 {
|
||||||
x += float64(dataOptions.Offset[0])
|
x += float64(actionOptions.Offset[0])
|
||||||
y += float64(dataOptions.Offset[1])
|
y += float64(actionOptions.Offset[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// adb shell input tap x y
|
// adb shell input tap x y
|
||||||
@@ -221,20 +221,20 @@ func (ad *adbDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Drag(fromX, fromY, toX, toY int, options ...DataOption) error {
|
func (ad *adbDriver) Drag(fromX, fromY, toX, toY int, options ...ActionOption) error {
|
||||||
return ad.DragFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
return ad.DragFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) (err error) {
|
func (ad *adbDriver) DragFloat(fromX, fromY, toX, toY float64, options ...ActionOption) (err error) {
|
||||||
err = errDriverNotImplemented
|
err = errDriverNotImplemented
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
|
func (ad *adbDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error {
|
||||||
return ad.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
return ad.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error {
|
func (ad *adbDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
// adb shell input swipe fromX fromY toX toY
|
// adb shell input swipe fromX fromY toX toY
|
||||||
_, err := ad.adbClient.RunShellCommand(
|
_, err := ad.adbClient.RunShellCommand(
|
||||||
"input", "swipe",
|
"input", "swipe",
|
||||||
@@ -263,13 +263,13 @@ func (ad *adbDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) SendKeys(text string, options ...DataOption) (err error) {
|
func (ad *adbDriver) SendKeys(text string, options ...ActionOption) (err error) {
|
||||||
// adb shell input text <text>
|
// adb shell input text <text>
|
||||||
_, err = ad.adbClient.RunShellCommand("input", "text", text)
|
_, err = ad.adbClient.RunShellCommand("input", "text", text)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Input(text string, options ...DataOption) (err error) {
|
func (ad *adbDriver) Input(text string, options ...ActionOption) (err error) {
|
||||||
return ad.SendKeys(text, options...)
|
return ad.SendKeys(text, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ func (ud *uiaDriver) WindowSize() (size Size, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PressBack simulates a short press on the BACK button.
|
// PressBack simulates a short press on the BACK button.
|
||||||
func (ud *uiaDriver) PressBack(options ...DataOption) (err error) {
|
func (ud *uiaDriver) PressBack(options ...ActionOption) (err error) {
|
||||||
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
|
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
|
||||||
_, err = ud.httpPOST(nil, "/session", ud.sessionId, "back")
|
_, err = ud.httpPOST(nil, "/session", ud.sessionId, "back")
|
||||||
return
|
return
|
||||||
@@ -199,18 +199,18 @@ func (ud *uiaDriver) PressKeyCode(keyCode KeyCode, metaState KeyMeta, flags ...K
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) Tap(x, y int, options ...DataOption) error {
|
func (ud *uiaDriver) Tap(x, y int, options ...ActionOption) error {
|
||||||
return ud.TapFloat(float64(x), float64(y), options...)
|
return ud.TapFloat(float64(x), float64(y), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) TapFloat(x, y float64, options ...DataOption) (err error) {
|
func (ud *uiaDriver) TapFloat(x, y float64, options ...ActionOption) (err error) {
|
||||||
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
|
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"x": x,
|
"x": x,
|
||||||
"y": y,
|
"y": y,
|
||||||
}
|
}
|
||||||
// new data options in post data for extra uiautomator configurations
|
// new data options in post data for extra uiautomator configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "appium/tap")
|
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "appium/tap")
|
||||||
return
|
return
|
||||||
@@ -240,11 +240,11 @@ func (ud *uiaDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err
|
|||||||
// the smoothness and speed of the swipe by specifying the number of steps.
|
// the smoothness and speed of the swipe by specifying the number of steps.
|
||||||
// Each step execution is throttled to 5 milliseconds per step, so for a 100
|
// Each step execution is throttled to 5 milliseconds per step, so for a 100
|
||||||
// steps, the swipe will take around 0.5 seconds to complete.
|
// steps, the swipe will take around 0.5 seconds to complete.
|
||||||
func (ud *uiaDriver) Drag(fromX, fromY, toX, toY int, options ...DataOption) error {
|
func (ud *uiaDriver) Drag(fromX, fromY, toX, toY int, options ...ActionOption) error {
|
||||||
return ud.DragFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
return ud.DragFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) (err error) {
|
func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...ActionOption) (err error) {
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"startX": fromX,
|
"startX": fromX,
|
||||||
"startY": fromY,
|
"startY": fromY,
|
||||||
@@ -253,7 +253,7 @@ func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new data options in post data for extra uiautomator configurations
|
// new data options in post data for extra uiautomator configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
// register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag"))
|
// register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag"))
|
||||||
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "touch/drag")
|
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "touch/drag")
|
||||||
@@ -264,11 +264,11 @@ func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
|
|||||||
// to determine smoothness and speed. Each step execution is throttled to 5ms
|
// to determine smoothness and speed. Each step execution is throttled to 5ms
|
||||||
// per step. So for a 100 steps, the swipe will take about 1/2 second to complete.
|
// per step. So for a 100 steps, the swipe will take about 1/2 second to complete.
|
||||||
// `steps` is the number of move steps sent to the system
|
// `steps` is the number of move steps sent to the system
|
||||||
func (ud *uiaDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
|
func (ud *uiaDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error {
|
||||||
return ud.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
return ud.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error {
|
func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
// register(postHandler, new Swipe("/wd/hub/session/:sessionId/touch/perform"))
|
// register(postHandler, new Swipe("/wd/hub/session/:sessionId/touch/perform"))
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"startX": fromX,
|
"startX": fromX,
|
||||||
@@ -278,7 +278,7 @@ func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new data options in post data for extra uiautomator configurations
|
// new data options in post data for extra uiautomator configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err := ud.httpPOST(newData, "/session", ud.sessionId, "touch/perform")
|
_, err := ud.httpPOST(newData, "/session", ud.sessionId, "touch/perform")
|
||||||
return err
|
return err
|
||||||
@@ -327,20 +327,20 @@ func (ud *uiaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) SendKeys(text string, options ...DataOption) (err error) {
|
func (ud *uiaDriver) SendKeys(text string, options ...ActionOption) (err error) {
|
||||||
// register(postHandler, new SendKeysToElement("/wd/hub/session/:sessionId/keys"))
|
// register(postHandler, new SendKeysToElement("/wd/hub/session/:sessionId/keys"))
|
||||||
// https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/handler/SendKeysToElement.java#L76-L85
|
// https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/handler/SendKeysToElement.java#L76-L85
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"text": text,
|
"text": text,
|
||||||
}
|
}
|
||||||
// new data options in post data for extra uiautomator configurations
|
// new data options in post data for extra uiautomator configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "keys")
|
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "keys")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *uiaDriver) Input(text string, options ...DataOption) (err error) {
|
func (ud *uiaDriver) Input(text string, options ...ActionOption) (err error) {
|
||||||
return ud.SendKeys(text, options...)
|
return ud.SendKeys(text, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,5 +24,5 @@ func (dExt *DriverExt) DragOffsetFloat(pathname string, toX, toY, xOffset, yOffs
|
|||||||
|
|
||||||
// FIXME: handle offset
|
// FIXME: handle offset
|
||||||
return dExt.Driver.DragFloat(point.X+xOffset, point.Y+yOffset, toX, toY,
|
return dExt.Driver.DragFloat(point.X+xOffset, point.Y+yOffset, toX, toY,
|
||||||
WithDataPressDuration(pressForDuration[0]))
|
WithPressDuration(pressForDuration[0]))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func init() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) FindUIRectInUIKit(search string, options ...DataOption) (point PointF, err error) {
|
func (dExt *DriverExt) FindUIRectInUIKit(search string, options ...ActionOption) (point PointF, err error) {
|
||||||
// click on text, using OCR
|
// click on text, using OCR
|
||||||
if !isPathExists(search) {
|
if !isPathExists(search) {
|
||||||
return dExt.FindScreenTextByOCR(search, options...)
|
return dExt.FindScreenTextByOCR(search, options...)
|
||||||
|
|||||||
@@ -2,11 +2,8 @@ package uixt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"math"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -431,144 +428,6 @@ type Rect struct {
|
|||||||
Size
|
Size
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataOptions struct {
|
|
||||||
Data map[string]interface{} // configurations used by ios/android driver
|
|
||||||
Scope []int // used by ocr to get text position in the scope
|
|
||||||
Offset []int // used to tap offset of point
|
|
||||||
Index int // index of the target element, should start from 1
|
|
||||||
IgnoreNotFoundError bool // ignore error if target element not found
|
|
||||||
MaxRetryTimes int // max retry times if target element not found
|
|
||||||
Interval float64 // interval between retries in seconds
|
|
||||||
}
|
|
||||||
|
|
||||||
type DataOption func(data *DataOptions)
|
|
||||||
|
|
||||||
func WithCustomOption(key string, value interface{}) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Data[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataPressDuration(duration float64) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Data["duration"] = duration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataSteps(steps int) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Data["steps"] = steps
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataFrequency(frequency int) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Data["frequency"] = frequency
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataIndex(index int) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Index = index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataScope(x1, x2, y1, y2 int) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Scope = []int{x1, x2, y1, y2}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataOffset(offsetX, offsetY int) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Offset = []int{offsetX, offsetY}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataIdentifier(identifier string) DataOption {
|
|
||||||
if identifier == "" {
|
|
||||||
return func(data *DataOptions) {}
|
|
||||||
}
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Data["log"] = map[string]interface{}{
|
|
||||||
"enable": true,
|
|
||||||
"data": identifier,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataIgnoreNotFoundError(ignoreError bool) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.IgnoreNotFoundError = ignoreError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataMaxRetryTimes(maxRetryTimes int) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.MaxRetryTimes = maxRetryTimes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDataWaitTime(sec float64) DataOption {
|
|
||||||
return func(data *DataOptions) {
|
|
||||||
data.Interval = sec
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDataOptions(options ...DataOption) *DataOptions {
|
|
||||||
dataOptions := &DataOptions{
|
|
||||||
Data: make(map[string]interface{}),
|
|
||||||
}
|
|
||||||
for _, option := range options {
|
|
||||||
option(dataOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(dataOptions.Scope) == 0 {
|
|
||||||
dataOptions.Scope = []int{0, 0, math.MaxInt64, math.MaxInt64} // default scope
|
|
||||||
}
|
|
||||||
return dataOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewData(data map[string]interface{}, options ...DataOption) map[string]interface{} {
|
|
||||||
dataOptions := NewDataOptions(options...)
|
|
||||||
|
|
||||||
// merge with data options
|
|
||||||
for k, v := range dataOptions.Data {
|
|
||||||
data[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle point offset
|
|
||||||
if len(dataOptions.Offset) == 2 {
|
|
||||||
if x, ok := data["x"]; ok {
|
|
||||||
xf, _ := builtin.Interface2Float64(x)
|
|
||||||
data["x"] = xf + float64(dataOptions.Offset[0])
|
|
||||||
}
|
|
||||||
if y, ok := data["y"]; ok {
|
|
||||||
yf, _ := builtin.Interface2Float64(y)
|
|
||||||
data["y"] = yf + float64(dataOptions.Offset[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add default options
|
|
||||||
if _, ok := data["steps"]; !ok {
|
|
||||||
data["steps"] = 12 // default steps
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := data["duration"]; !ok {
|
|
||||||
data["duration"] = 0 // default duration
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := data["frequency"]; !ok {
|
|
||||||
data["frequency"] = 60 // default frequency
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := data["isReplace"]; !ok {
|
|
||||||
data["isReplace"] = true // default true
|
|
||||||
}
|
|
||||||
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
// current implemeted device: IOSDevice, AndroidDevice
|
// current implemeted device: IOSDevice, AndroidDevice
|
||||||
type Device interface {
|
type Device interface {
|
||||||
UUID() string // ios udid or android serial
|
UUID() string // ios udid or android serial
|
||||||
@@ -640,8 +499,8 @@ type WebDriver interface {
|
|||||||
StopCamera() error
|
StopCamera() error
|
||||||
|
|
||||||
// Tap Sends a tap event at the coordinate.
|
// Tap Sends a tap event at the coordinate.
|
||||||
Tap(x, y int, options ...DataOption) error
|
Tap(x, y int, options ...ActionOption) error
|
||||||
TapFloat(x, y float64, options ...DataOption) error
|
TapFloat(x, y float64, options ...ActionOption) error
|
||||||
|
|
||||||
// DoubleTap Sends a double tap event at the coordinate.
|
// DoubleTap Sends a double tap event at the coordinate.
|
||||||
DoubleTap(x, y int) error
|
DoubleTap(x, y int) error
|
||||||
@@ -654,12 +513,12 @@ type WebDriver interface {
|
|||||||
|
|
||||||
// Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.
|
// Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.
|
||||||
// WithPressDurationOption option can be used to set pressForDuration (default to 1 second).
|
// WithPressDurationOption option can be used to set pressForDuration (default to 1 second).
|
||||||
Drag(fromX, fromY, toX, toY int, options ...DataOption) error
|
Drag(fromX, fromY, toX, toY int, options ...ActionOption) error
|
||||||
DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) error
|
DragFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error
|
||||||
|
|
||||||
// Swipe works like Drag, but `pressForDuration` value is 0
|
// Swipe works like Drag, but `pressForDuration` value is 0
|
||||||
Swipe(fromX, fromY, toX, toY int, options ...DataOption) error
|
Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error
|
||||||
SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error
|
SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error
|
||||||
|
|
||||||
// SetPasteboard Sets data to the general pasteboard
|
// SetPasteboard Sets data to the general pasteboard
|
||||||
SetPasteboard(contentType PasteboardType, content string) error
|
SetPasteboard(contentType PasteboardType, content string) error
|
||||||
@@ -670,16 +529,16 @@ type WebDriver interface {
|
|||||||
// SendKeys Types a string into active element. There must be element with keyboard focus,
|
// SendKeys Types a string into active element. There must be element with keyboard focus,
|
||||||
// otherwise an error is raised.
|
// otherwise an error is raised.
|
||||||
// WithFrequency option can be used to set frequency of typing (letters per sec). The default value is 60
|
// WithFrequency option can be used to set frequency of typing (letters per sec). The default value is 60
|
||||||
SendKeys(text string, options ...DataOption) error
|
SendKeys(text string, options ...ActionOption) error
|
||||||
|
|
||||||
// Input works like SendKeys
|
// Input works like SendKeys
|
||||||
Input(text string, options ...DataOption) error
|
Input(text string, options ...ActionOption) error
|
||||||
|
|
||||||
// PressButton Presses the corresponding hardware button on the device
|
// PressButton Presses the corresponding hardware button on the device
|
||||||
PressButton(devBtn DeviceButton) error
|
PressButton(devBtn DeviceButton) error
|
||||||
|
|
||||||
// PressBack Presses the back button
|
// PressBack Presses the back button
|
||||||
PressBack(options ...DataOption) error
|
PressBack(options ...ActionOption) error
|
||||||
|
|
||||||
Screenshot() (*bytes.Buffer, error)
|
Screenshot() (*bytes.Buffer, error)
|
||||||
|
|
||||||
|
|||||||
@@ -377,18 +377,18 @@ func (wd *wdaDriver) GetForegroundApp() (app AppInfo, err error) {
|
|||||||
return AppInfo{}, nil
|
return AppInfo{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) Tap(x, y int, options ...DataOption) error {
|
func (wd *wdaDriver) Tap(x, y int, options ...ActionOption) error {
|
||||||
return wd.TapFloat(float64(x), float64(y), options...)
|
return wd.TapFloat(float64(x), float64(y), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) TapFloat(x, y float64, options ...DataOption) (err error) {
|
func (wd *wdaDriver) TapFloat(x, y float64, options ...ActionOption) (err error) {
|
||||||
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"x": wd.toScale(x),
|
"x": wd.toScale(x),
|
||||||
"y": wd.toScale(y),
|
"y": wd.toScale(y),
|
||||||
}
|
}
|
||||||
// new data options in post data for extra WDA configurations
|
// new data options in post data for extra WDA configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/tap/0")
|
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/tap/0")
|
||||||
return
|
return
|
||||||
@@ -426,11 +426,11 @@ func (wd *wdaDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) Drag(fromX, fromY, toX, toY int, options ...DataOption) error {
|
func (wd *wdaDriver) Drag(fromX, fromY, toX, toY int, options ...ActionOption) error {
|
||||||
return wd.DragFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
return wd.DragFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) (err error) {
|
func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...ActionOption) (err error) {
|
||||||
// [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)]
|
// [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)]
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"fromX": wd.toScale(fromX),
|
"fromX": wd.toScale(fromX),
|
||||||
@@ -440,17 +440,17 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new data options in post data for extra WDA configurations
|
// new data options in post data for extra WDA configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
|
func (wd *wdaDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error {
|
||||||
return wd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
return wd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error {
|
func (wd *wdaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
return wd.DragFloat(fromX, fromY, toX, toY, options...)
|
return wd.DragFloat(fromX, fromY, toX, toY, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,23 +477,23 @@ func (wd *wdaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) SendKeys(text string, options ...DataOption) (err error) {
|
func (wd *wdaDriver) SendKeys(text string, options ...ActionOption) (err error) {
|
||||||
// [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)]
|
// [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)]
|
||||||
data := map[string]interface{}{"value": strings.Split(text, "")}
|
data := map[string]interface{}{"value": strings.Split(text, "")}
|
||||||
|
|
||||||
// new data options in post data for extra WDA configurations
|
// new data options in post data for extra WDA configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/keys")
|
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/keys")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) Input(text string, options ...DataOption) (err error) {
|
func (wd *wdaDriver) Input(text string, options ...ActionOption) (err error) {
|
||||||
return wd.SendKeys(text, options...)
|
return wd.SendKeys(text, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PressBack simulates a short press on the BACK button.
|
// PressBack simulates a short press on the BACK button.
|
||||||
func (wd *wdaDriver) PressBack(options ...DataOption) (err error) {
|
func (wd *wdaDriver) PressBack(options ...ActionOption) (err error) {
|
||||||
windowSize, err := wd.WindowSize()
|
windowSize, err := wd.WindowSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -507,7 +507,7 @@ func (wd *wdaDriver) PressBack(options ...DataOption) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new data options in post data for extra WDA configurations
|
// new data options in post data for extra WDA configurations
|
||||||
newData := NewData(data, options...)
|
newData := mergeDataWithOptions(data, options...)
|
||||||
|
|
||||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ func (t OCRTexts) texts() (texts []string) {
|
|||||||
return texts
|
return texts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t OCRTexts) FindText(text string, options ...DataOption) (
|
func (t OCRTexts) FindText(text string, options ...ActionOption) (
|
||||||
point PointF, err error) {
|
point PointF, err error) {
|
||||||
|
|
||||||
dataOptions := NewDataOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
var rects []image.Rectangle
|
var rects []image.Rectangle
|
||||||
for _, ocrText := range t {
|
for _, ocrText := range t {
|
||||||
@@ -63,8 +63,8 @@ func (t OCRTexts) FindText(text string, options ...DataOption) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if text in scope
|
// check if text in scope
|
||||||
if rect.Min.X < dataOptions.Scope[0] || rect.Max.X > dataOptions.Scope[2] ||
|
if rect.Min.X < actionOptions.AbsScope[0] || rect.Min.Y < actionOptions.AbsScope[1] ||
|
||||||
rect.Min.Y < dataOptions.Scope[1] || rect.Max.Y > dataOptions.Scope[3] {
|
rect.Max.X > actionOptions.AbsScope[2] || rect.Max.Y > actionOptions.AbsScope[3] {
|
||||||
// not in scope
|
// not in scope
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ func (t OCRTexts) FindText(text string, options ...DataOption) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// match exactly, and not specify index, return the first one
|
// match exactly, and not specify index, return the first one
|
||||||
if dataOptions.Index == 0 {
|
if actionOptions.Index == 0 {
|
||||||
return getRectangleCenterPoint(rect), nil
|
return getRectangleCenterPoint(rect), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ func (t OCRTexts) FindText(text string, options ...DataOption) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get index
|
// get index
|
||||||
idx := dataOptions.Index
|
idx := actionOptions.Index
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
// NOTICE: index start from 1
|
// NOTICE: index start from 1
|
||||||
idx = idx - 1
|
idx = idx - 1
|
||||||
@@ -105,7 +105,7 @@ func (t OCRTexts) FindText(text string, options ...DataOption) (
|
|||||||
return getRectangleCenterPoint(rects[idx]), nil
|
return getRectangleCenterPoint(rects[idx]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t OCRTexts) FindTexts(texts []string, options ...DataOption) (points []PointF, err error) {
|
func (t OCRTexts) FindTexts(texts []string, options ...ActionOption) (points []PointF, err error) {
|
||||||
for _, text := range texts {
|
for _, text := range texts {
|
||||||
point, err := t.FindText(text, options...)
|
point, err := t.FindText(text, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -296,7 +296,7 @@ func (dExt *DriverExt) GetScreenTextsByOCR() (texts OCRTexts, err error) {
|
|||||||
return ocrTexts, nil
|
return ocrTexts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) FindScreenTextByOCR(text string, options ...DataOption) (point PointF, err error) {
|
func (dExt *DriverExt) FindScreenTextByOCR(text string, options ...ActionOption) (point PointF, err error) {
|
||||||
ocrTexts, err := dExt.GetScreenTextsByOCR()
|
ocrTexts, err := dExt.GetScreenTextsByOCR()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...DataOption) (point PointF, err error) {
|
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...ActionOption) (point PointF, err error) {
|
||||||
var bufSource, bufSearch *bytes.Buffer
|
var bufSource, bufSearch *bytes.Buffer
|
||||||
if bufSearch, err = getBufFromDisk(imagePath); err != nil {
|
if bufSearch, err = getBufFromDisk(imagePath); err != nil {
|
||||||
return PointF{}, err
|
return PointF{}, err
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...DataOption) (point PointF, err error) {
|
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...ActionOption) (point PointF, err error) {
|
||||||
log.Fatal().Msg("opencv is not supported")
|
log.Fatal().Msg("opencv is not supported")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ func assertRelative(p float64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
||||||
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...DataOption) error {
|
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
width := dExt.windowSize.Width
|
width := dExt.windowSize.Width
|
||||||
height := dExt.windowSize.Height
|
height := dExt.windowSize.Height
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...
|
|||||||
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
|
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeTo(direction string, options ...DataOption) (err error) {
|
func (dExt *DriverExt) SwipeTo(direction string, options ...ActionOption) (err error) {
|
||||||
switch direction {
|
switch direction {
|
||||||
case "up":
|
case "up":
|
||||||
return dExt.SwipeUp(options...)
|
return dExt.SwipeUp(options...)
|
||||||
@@ -48,28 +47,28 @@ func (dExt *DriverExt) SwipeTo(direction string, options ...DataOption) (err err
|
|||||||
return fmt.Errorf("unexpected direction: %s", direction)
|
return fmt.Errorf("unexpected direction: %s", direction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUp(options ...DataOption) (err error) {
|
func (dExt *DriverExt) SwipeUp(options ...ActionOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, options...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeDown(options ...DataOption) (err error) {
|
func (dExt *DriverExt) SwipeDown(options ...ActionOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, options...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeLeft(options ...DataOption) (err error) {
|
func (dExt *DriverExt) SwipeLeft(options ...ActionOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, options...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeRight(options ...DataOption) (err error) {
|
func (dExt *DriverExt) SwipeRight(options ...ActionOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, options...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Action func(driver *DriverExt) error
|
type Action func(driver *DriverExt) error
|
||||||
|
|
||||||
func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action, options ...DataOption) error {
|
func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action, options ...ActionOption) error {
|
||||||
dataOptions := NewDataOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
maxRetryTimes := dataOptions.MaxRetryTimes
|
maxRetryTimes := actionOptions.MaxRetryTimes
|
||||||
interval := dataOptions.Interval
|
interval := actionOptions.Interval
|
||||||
|
|
||||||
for i := 0; i < maxRetryTimes; i++ {
|
for i := 0; i < maxRetryTimes; i++ {
|
||||||
if err := findCondition(dExt); err == nil {
|
if err := findCondition(dExt); err == nil {
|
||||||
@@ -89,56 +88,38 @@ func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action,
|
|||||||
fmt.Sprintf("loop %d times, match find condition failed", maxRetryTimes))
|
fmt.Sprintf("loop %d times, match find condition failed", maxRetryTimes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) prepareSwipeAction(action MobileAction) func(d *DriverExt) error {
|
func (dExt *DriverExt) prepareSwipeAction(options ...ActionOption) func(d *DriverExt) error {
|
||||||
identifierOption := WithDataIdentifier(action.Identifier)
|
actionOptions := NewActionOptions(options...)
|
||||||
durationOption := WithDataPressDuration(action.Duration)
|
|
||||||
|
|
||||||
if action.Steps == 0 {
|
|
||||||
action.Steps = 10
|
|
||||||
}
|
|
||||||
stepsOption := WithDataSteps(action.Steps)
|
|
||||||
|
|
||||||
dataOptions := make([]DataOption, 3)
|
|
||||||
dataOptions = append(dataOptions, identifierOption, durationOption, stepsOption)
|
|
||||||
|
|
||||||
var swipeDirection interface{}
|
var swipeDirection interface{}
|
||||||
if action.Direction != nil {
|
if actionOptions.Direction != nil {
|
||||||
swipeDirection = action.Direction
|
swipeDirection = actionOptions.Direction
|
||||||
} else {
|
} else {
|
||||||
swipeDirection = "up" // default swipe up
|
swipeDirection = "up" // default swipe up
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if actionOptions.Steps == 0 {
|
||||||
|
actionOptions.Steps = 10
|
||||||
|
}
|
||||||
|
|
||||||
return func(d *DriverExt) error {
|
return func(d *DriverExt) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
// wait for swipe action to completed and content to load completely
|
// wait for swipe action to completed and content to load completely
|
||||||
time.Sleep(time.Duration(1000*action.WaitTime) * time.Millisecond)
|
time.Sleep(time.Duration(1000*actionOptions.Interval) * time.Millisecond)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if d, ok := swipeDirection.(string); ok {
|
if d, ok := swipeDirection.(string); ok {
|
||||||
// enum direction: up, down, left, right
|
// enum direction: up, down, left, right
|
||||||
if err := dExt.SwipeTo(d, dataOptions...); err != nil {
|
if err := dExt.SwipeTo(d, options...); err != nil {
|
||||||
log.Error().Err(err).Msgf("swipe %s failed", d)
|
log.Error().Err(err).Msgf("swipe %s failed", d)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if d, ok := swipeDirection.([]float64); ok {
|
} else if d, ok := swipeDirection.([]float64); ok {
|
||||||
// custom direction: [fromX, fromY, toX, toY]
|
// custom direction: [fromX, fromY, toX, toY]
|
||||||
if err := dExt.SwipeRelative(d[0], d[1], d[2], d[3], dataOptions...); err != nil {
|
if err := dExt.SwipeRelative(d[0], d[1], d[2], d[3], options...); err != nil {
|
||||||
log.Error().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) failed",
|
log.Error().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) failed",
|
||||||
d[0], d[1], d[2], d[3])
|
d[0], d[1], d[2], d[3])
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if d, ok := swipeDirection.([]interface{}); ok {
|
|
||||||
// loaded from json case
|
|
||||||
// custom direction: [fromX, fromY, toX, toY]
|
|
||||||
sx, _ := builtin.Interface2Float64(d[0])
|
|
||||||
sy, _ := builtin.Interface2Float64(d[1])
|
|
||||||
ex, _ := builtin.Interface2Float64(d[2])
|
|
||||||
ey, _ := builtin.Interface2Float64(d[3])
|
|
||||||
if err := dExt.SwipeRelative(sx, sy, ex, ey, dataOptions...); err != nil {
|
|
||||||
log.Error().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) failed",
|
|
||||||
sx, sy, ex, ey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("invalid swipe params %v", swipeDirection)
|
return fmt.Errorf("invalid swipe params %v", swipeDirection)
|
||||||
}
|
}
|
||||||
@@ -146,28 +127,13 @@ func (dExt *DriverExt) prepareSwipeAction(action MobileAction) func(d *DriverExt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) swipeToTapTexts(texts []string, action MobileAction) error {
|
func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption) error {
|
||||||
if len(texts) == 0 {
|
if len(texts) == 0 {
|
||||||
return errors.New("no text to tap")
|
return errors.New("no text to tap")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(action.Scope) != 4 {
|
|
||||||
action.Scope = []float64{0, 0, 1, 1}
|
|
||||||
}
|
|
||||||
if len(action.Offset) != 2 {
|
|
||||||
action.Offset = []int{0, 0}
|
|
||||||
}
|
|
||||||
|
|
||||||
identifierOption := WithDataIdentifier(action.Identifier)
|
|
||||||
offsetOption := WithDataOffset(action.Offset[0], action.Offset[1])
|
|
||||||
indexOption := WithDataIndex(action.Index)
|
|
||||||
scopeOption := WithDataScope(dExt.getAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
|
|
||||||
// default to retry 10 times
|
// default to retry 10 times
|
||||||
if action.MaxRetryTimes == 0 {
|
options = append(options, WithMaxRetryTimes(10))
|
||||||
action.MaxRetryTimes = 10
|
|
||||||
}
|
|
||||||
maxRetryOption := WithDataMaxRetryTimes(action.MaxRetryTimes)
|
|
||||||
waitTimeOption := WithDataWaitTime(action.WaitTime)
|
|
||||||
|
|
||||||
var point PointF
|
var point PointF
|
||||||
findTexts := func(d *DriverExt) error {
|
findTexts := func(d *DriverExt) error {
|
||||||
@@ -176,7 +142,7 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, action MobileAction) erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
points, err := ocrTexts.FindTexts(texts, indexOption, scopeOption)
|
points, err := ocrTexts.FindTexts(texts, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -185,14 +151,14 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, action MobileAction) erro
|
|||||||
}
|
}
|
||||||
foundTextAction := func(d *DriverExt) error {
|
foundTextAction := func(d *DriverExt) error {
|
||||||
// tap text
|
// tap text
|
||||||
return d.TapAbsXY(point.X, point.Y, identifierOption, offsetOption)
|
return d.TapAbsXY(point.X, point.Y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
findAction := dExt.prepareSwipeAction(action)
|
findAction := dExt.prepareSwipeAction(options...)
|
||||||
return dExt.LoopUntil(findAction, findTexts, foundTextAction, maxRetryOption, waitTimeOption)
|
return dExt.LoopUntil(findAction, findTexts, foundTextAction, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) swipeToTapApp(appName string, action MobileAction) error {
|
func (dExt *DriverExt) swipeToTapApp(appName string, options ...ActionOption) error {
|
||||||
// go to home screen
|
// go to home screen
|
||||||
if err := dExt.Driver.Homescreen(); err != nil {
|
if err := dExt.Driver.Homescreen(); err != nil {
|
||||||
return errors.Wrap(err, "go to home screen failed")
|
return errors.Wrap(err, "go to home screen failed")
|
||||||
@@ -203,8 +169,8 @@ func (dExt *DriverExt) swipeToTapApp(appName string, action MobileAction) error
|
|||||||
dExt.SwipeRight()
|
dExt.SwipeRight()
|
||||||
}
|
}
|
||||||
|
|
||||||
action.Offset = []int{0, -25} // tap app icon above the text
|
options = append(options, WithOffset(0, -25)) // tap app icon above the text
|
||||||
action.Direction = "left"
|
options = append(options, WithDirection("left"))
|
||||||
|
|
||||||
return dExt.swipeToTapTexts([]string{appName}, action)
|
return dExt.swipeToTapTexts([]string{appName}, options...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,11 @@ import (
|
|||||||
func TestAndroidSwipeAction(t *testing.T) {
|
func TestAndroidSwipeAction(t *testing.T) {
|
||||||
setupAndroid(t)
|
setupAndroid(t)
|
||||||
|
|
||||||
action := MobileAction{
|
swipeAction := driverExt.prepareSwipeAction(WithDirection("up"))
|
||||||
Method: ACTION_Swipe,
|
|
||||||
Params: "up",
|
|
||||||
}
|
|
||||||
swipeAction := driverExt.prepareSwipeAction(action)
|
|
||||||
|
|
||||||
err := swipeAction(driverExt)
|
err := swipeAction(driverExt)
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
action = MobileAction{
|
swipeAction = driverExt.prepareSwipeAction(WithCustomDirection(0.5, 0.5, 0.5, 0.9))
|
||||||
Method: ACTION_Swipe,
|
|
||||||
Params: []float64{0.5, 0.5, 0.5, 0.9},
|
|
||||||
}
|
|
||||||
swipeAction = driverExt.prepareSwipeAction(action)
|
|
||||||
|
|
||||||
err = swipeAction(driverExt)
|
err = swipeAction(driverExt)
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
}
|
}
|
||||||
@@ -31,7 +21,7 @@ func TestAndroidSwipeAction(t *testing.T) {
|
|||||||
func TestAndroidSwipeToTapApp(t *testing.T) {
|
func TestAndroidSwipeToTapApp(t *testing.T) {
|
||||||
setupAndroid(t)
|
setupAndroid(t)
|
||||||
|
|
||||||
err := driverExt.swipeToTapApp("抖音", MobileAction{})
|
err := driverExt.swipeToTapApp("抖音")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +31,6 @@ func TestAndroidSwipeToTapTexts(t *testing.T) {
|
|||||||
err := driverExt.Driver.AppLaunch("com.ss.android.ugc.aweme")
|
err := driverExt.Driver.AppLaunch("com.ss.android.ugc.aweme")
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
action := MobileAction{
|
err = driverExt.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, WithDirection("up"))
|
||||||
Params: "up",
|
|
||||||
}
|
|
||||||
err = driverExt.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, action)
|
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...DataOption) error {
|
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
|
||||||
// tap on absolute coordinate [x, y]
|
// tap on absolute coordinate [x, y]
|
||||||
return dExt.Driver.TapFloat(x, y, options...)
|
return dExt.Driver.TapFloat(x, y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) TapXY(x, y float64, options ...DataOption) error {
|
func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error {
|
||||||
// tap on [x, y] percent of window size
|
// tap on [x, y] percent of window size
|
||||||
if x > 1 || y > 1 {
|
if x > 1 || y > 1 {
|
||||||
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
|
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
|
||||||
@@ -21,12 +21,12 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...DataOption) error {
|
|||||||
return dExt.TapAbsXY(x, y, options...)
|
return dExt.TapAbsXY(x, y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) TapByOCR(ocrText string, options ...DataOption) error {
|
func (dExt *DriverExt) TapByOCR(ocrText string, options ...ActionOption) error {
|
||||||
dataOptions := NewDataOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
point, err := dExt.FindScreenTextByOCR(ocrText, options...)
|
point, err := dExt.FindScreenTextByOCR(ocrText, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if dataOptions.IgnoreNotFoundError {
|
if actionOptions.IgnoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -35,12 +35,12 @@ func (dExt *DriverExt) TapByOCR(ocrText string, options ...DataOption) error {
|
|||||||
return dExt.TapAbsXY(point.X, point.Y, options...)
|
return dExt.TapAbsXY(point.X, point.Y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) TapByCV(imagePath string, options ...DataOption) error {
|
func (dExt *DriverExt) TapByCV(imagePath string, options ...ActionOption) error {
|
||||||
dataOptions := NewDataOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
point, err := dExt.FindImageRectInUIKit(imagePath, options...)
|
point, err := dExt.FindImageRectInUIKit(imagePath, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if dataOptions.IgnoreNotFoundError {
|
if actionOptions.IgnoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -49,16 +49,16 @@ func (dExt *DriverExt) TapByCV(imagePath string, options ...DataOption) error {
|
|||||||
return dExt.TapAbsXY(point.X, point.Y, options...)
|
return dExt.TapAbsXY(point.X, point.Y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) Tap(param string, options ...DataOption) error {
|
func (dExt *DriverExt) Tap(param string, options ...ActionOption) error {
|
||||||
return dExt.TapOffset(param, 0.5, 0.5, options...)
|
return dExt.TapOffset(param, 0.5, 0.5, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) TapOffset(param string, xOffset, yOffset float64, options ...DataOption) (err error) {
|
func (dExt *DriverExt) TapOffset(param string, xOffset, yOffset float64, options ...ActionOption) (err error) {
|
||||||
dataOptions := NewDataOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
point, err := dExt.FindUIRectInUIKit(param, options...)
|
point, err := dExt.FindUIRectInUIKit(param, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if dataOptions.IgnoreNotFoundError {
|
if actionOptions.IgnoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -69,12 +69,11 @@ func (s *StepMobile) Home() *StepMobile {
|
|||||||
// TapXY taps the point {X,Y}, X & Y is percentage of coordinates
|
// TapXY taps the point {X,Y}, X & Y is percentage of coordinates
|
||||||
func (s *StepMobile) TapXY(x, y float64, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) TapXY(x, y float64, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_TapXY,
|
Method: uixt.ACTION_TapXY,
|
||||||
Params: []float64{x, y},
|
Params: []float64{x, y},
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
@@ -82,12 +81,11 @@ func (s *StepMobile) TapXY(x, y float64, options ...uixt.ActionOption) *StepMobi
|
|||||||
// TapAbsXY taps the point {X,Y}, X & Y is absolute coordinates
|
// TapAbsXY taps the point {X,Y}, X & Y is absolute coordinates
|
||||||
func (s *StepMobile) TapAbsXY(x, y float64, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) TapAbsXY(x, y float64, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_TapAbsXY,
|
Method: uixt.ACTION_TapAbsXY,
|
||||||
Params: []float64{x, y},
|
Params: []float64{x, y},
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
@@ -95,12 +93,11 @@ func (s *StepMobile) TapAbsXY(x, y float64, options ...uixt.ActionOption) *StepM
|
|||||||
// Tap taps on the target element
|
// Tap taps on the target element
|
||||||
func (s *StepMobile) Tap(params string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) Tap(params string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Tap,
|
Method: uixt.ACTION_Tap,
|
||||||
Params: params,
|
Params: params,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
@@ -108,12 +105,11 @@ func (s *StepMobile) Tap(params string, options ...uixt.ActionOption) *StepMobil
|
|||||||
// Tap taps on the target element by OCR recognition
|
// Tap taps on the target element by OCR recognition
|
||||||
func (s *StepMobile) TapByOCR(ocrText string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) TapByOCR(ocrText string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_TapByOCR,
|
Method: uixt.ACTION_TapByOCR,
|
||||||
Params: ocrText,
|
Params: ocrText,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
@@ -121,153 +117,142 @@ func (s *StepMobile) TapByOCR(ocrText string, options ...uixt.ActionOption) *Ste
|
|||||||
// Tap taps on the target element by CV recognition
|
// Tap taps on the target element by CV recognition
|
||||||
func (s *StepMobile) TapByCV(imagePath string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) TapByCV(imagePath string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_TapByCV,
|
Method: uixt.ACTION_TapByCV,
|
||||||
Params: imagePath,
|
Params: imagePath,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoubleTapXY double taps the point {X,Y}, X & Y is percentage of coordinates
|
// DoubleTapXY double taps the point {X,Y}, X & Y is percentage of coordinates
|
||||||
func (s *StepMobile) DoubleTapXY(x, y float64) *StepMobile {
|
func (s *StepMobile) DoubleTapXY(x, y float64, options ...uixt.ActionOption) *StepMobile {
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, uixt.MobileAction{
|
s.mobileStep().Actions = append(s.mobileStep().Actions, uixt.MobileAction{
|
||||||
Method: uixt.ACTION_DoubleTapXY,
|
Method: uixt.ACTION_DoubleTapXY,
|
||||||
Params: []float64{x, y},
|
Params: []float64{x, y},
|
||||||
|
Options: uixt.NewActionOptions(options...),
|
||||||
})
|
})
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) DoubleTap(params string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) DoubleTap(params string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_DoubleTap,
|
Method: uixt.ACTION_DoubleTap,
|
||||||
Params: params,
|
Params: params,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) Back(options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) Back(options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Back,
|
Method: uixt.ACTION_Back,
|
||||||
Params: nil,
|
Params: nil,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
Params: []float64{sx, sy, ex, ey},
|
Params: []float64{sx, sy, ex, ey},
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeUp(options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) SwipeUp(options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
Params: "up",
|
Params: "up",
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeDown(options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) SwipeDown(options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
Params: "down",
|
Params: "down",
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeLeft(options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) SwipeLeft(options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
Params: "left",
|
Params: "left",
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeRight(options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) SwipeRight(options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
Params: "right",
|
Params: "right",
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeToTapApp(appName string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) SwipeToTapApp(appName string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_SwipeToTapApp,
|
Method: uixt.ACTION_SwipeToTapApp,
|
||||||
Params: appName,
|
Params: appName,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeToTapText(text string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) SwipeToTapText(text string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_SwipeToTapText,
|
Method: uixt.ACTION_SwipeToTapText,
|
||||||
Params: text,
|
Params: text,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) SwipeToTapTexts(texts interface{}, 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,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) Input(text string, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) Input(text string, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Input,
|
Method: uixt.ACTION_Input,
|
||||||
Params: text,
|
Params: text,
|
||||||
}
|
Options: uixt.NewActionOptions(options...),
|
||||||
for _, option := range options {
|
|
||||||
option(&action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user