mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
refactor: rename options pkg to option
This commit is contained in:
451
pkg/uixt/option/action.go
Normal file
451
pkg/uixt/option/action.go
Normal file
@@ -0,0 +1,451 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||
)
|
||||
|
||||
// (x1, y1) is the top left corner, (x2, y2) is the bottom right corner
|
||||
// [x1, y1, x2, y2] in percentage of the screen
|
||||
type Scope []float64
|
||||
|
||||
// [x1, y1, x2, y2] in absolute pixels
|
||||
type AbsScope []int
|
||||
|
||||
func (s AbsScope) Option() ActionOption {
|
||||
return WithAbsScope(s[0], s[1], s[2], s[3])
|
||||
}
|
||||
|
||||
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
|
||||
Duration float64 `json:"duration,omitempty" yaml:"duration,omitempty"` // used to set duration of ios swipe action
|
||||
PressDuration float64 `json:"press_duration,omitempty" yaml:"press_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 Scope `json:"scope,omitempty" yaml:"scope,omitempty"`
|
||||
AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"`
|
||||
|
||||
Regex bool `json:"regex,omitempty" yaml:"regex,omitempty"` // use regex to match text
|
||||
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
||||
OffsetRandomRange []int `json:"offset_random_range,omitempty" yaml:"offset_random_range,omitempty"` // set random range [min, max] for tap/swipe points
|
||||
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element
|
||||
MatchOne bool `json:"match_one,omitempty" yaml:"match_one,omitempty"` // match one of the targets if existed
|
||||
|
||||
// set custiom options such as textview, id, description
|
||||
Custom map[string]interface{} `json:"custom,omitempty" yaml:"custom,omitempty"`
|
||||
|
||||
// screenshot related
|
||||
ScreenShotWithOCR bool `json:"screenshot_with_ocr,omitempty" yaml:"screenshot_with_ocr,omitempty"`
|
||||
ScreenShotWithUpload bool `json:"screenshot_with_upload,omitempty" yaml:"screenshot_with_upload,omitempty"`
|
||||
ScreenShotWithLiveType bool `json:"screenshot_with_live_type,omitempty" yaml:"screenshot_with_live_type,omitempty"`
|
||||
ScreenShotWithLivePopularity bool `json:"screenshot_with_live_popularity,omitempty" yaml:"screenshot_with_live_popularity,omitempty"`
|
||||
ScreenShotWithUITypes []string `json:"screenshot_with_ui_types,omitempty" yaml:"screenshot_with_ui_types,omitempty"`
|
||||
ScreenShotWithClosePopups bool `json:"screenshot_with_close_popups,omitempty" yaml:"screenshot_with_close_popups,omitempty"`
|
||||
ScreenShotWithOCRCluster string `json:"screenshot_with_ocr_cluster,omitempty" yaml:"screenshot_with_ocr_cluster,omitempty"`
|
||||
ScreenShotFileName string `json:"screenshot_file_name,omitempty" yaml:"screenshot_file_name,omitempty"`
|
||||
}
|
||||
|
||||
func (o *ActionOptions) Options() []ActionOption {
|
||||
options := make([]ActionOption, 0)
|
||||
|
||||
if o == nil {
|
||||
return options
|
||||
}
|
||||
|
||||
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.Duration != 0 {
|
||||
options = append(options, WithDuration(o.Duration))
|
||||
}
|
||||
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.AbsScope) == 4 {
|
||||
options = append(options, WithAbsScope(
|
||||
o.AbsScope[0], o.AbsScope[1], o.AbsScope[2], o.AbsScope[3]))
|
||||
} else if len(o.Scope) == 4 {
|
||||
options = append(options, WithScope(
|
||||
o.Scope[0], o.Scope[1], o.Scope[2], o.Scope[3]))
|
||||
}
|
||||
if len(o.Offset) == 2 {
|
||||
// for tap [x,y] offset
|
||||
options = append(options, WithTapOffset(o.Offset[0], o.Offset[1]))
|
||||
} else if len(o.Offset) == 4 {
|
||||
// for swipe [fromX, fromY, toX, toY] offset
|
||||
options = append(options, WithSwipeOffset(
|
||||
o.Offset[0], o.Offset[1], o.Offset[2], o.Offset[3]))
|
||||
}
|
||||
if len(o.OffsetRandomRange) == 2 {
|
||||
options = append(options, WithOffsetRandomRange(
|
||||
o.OffsetRandomRange[0], o.OffsetRandomRange[1]))
|
||||
}
|
||||
|
||||
if o.Regex {
|
||||
options = append(options, WithRegex(true))
|
||||
}
|
||||
if o.Index != 0 {
|
||||
options = append(options, WithIndex(o.Index))
|
||||
}
|
||||
if o.MatchOne {
|
||||
options = append(options, WithMatchOne(true))
|
||||
}
|
||||
|
||||
// custom options
|
||||
if o.Custom != nil {
|
||||
for k, v := range o.Custom {
|
||||
options = append(options, WithCustomOption(k, v))
|
||||
}
|
||||
}
|
||||
|
||||
// screenshot options
|
||||
if o.ScreenShotWithOCR {
|
||||
options = append(options, WithScreenShotOCR(true))
|
||||
}
|
||||
if o.ScreenShotWithUpload {
|
||||
options = append(options, WithScreenShotUpload(true))
|
||||
}
|
||||
if o.ScreenShotWithLiveType {
|
||||
options = append(options, WithScreenShotLiveType(true))
|
||||
}
|
||||
if o.ScreenShotWithLivePopularity {
|
||||
options = append(options, WithScreenShotLivePopularity(true))
|
||||
}
|
||||
if len(o.ScreenShotWithUITypes) > 0 {
|
||||
options = append(options, WithScreenShotUITypes(o.ScreenShotWithUITypes...))
|
||||
}
|
||||
if o.ScreenShotWithClosePopups {
|
||||
options = append(options, WithScreenShotClosePopups(true))
|
||||
}
|
||||
if o.ScreenShotWithOCRCluster != "" {
|
||||
options = append(options, WithScreenOCRCluster(o.ScreenShotWithOCRCluster))
|
||||
}
|
||||
if o.ScreenShotFileName != "" {
|
||||
options = append(options, WithScreenShotFileName(o.ScreenShotFileName))
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
func (o *ActionOptions) ScreenshotActions() []string {
|
||||
actions := []string{}
|
||||
if o.ScreenShotWithUpload {
|
||||
actions = append(actions, "upload")
|
||||
}
|
||||
if o.ScreenShotWithOCR {
|
||||
actions = append(actions, "ocr")
|
||||
}
|
||||
if o.ScreenShotWithLiveType {
|
||||
actions = append(actions, "liveType")
|
||||
}
|
||||
if o.ScreenShotWithLivePopularity {
|
||||
actions = append(actions, "livePopularity")
|
||||
}
|
||||
// UI detection
|
||||
if len(o.ScreenShotWithUITypes) > 0 {
|
||||
actions = append(actions, "ui")
|
||||
}
|
||||
if o.ScreenShotWithClosePopups {
|
||||
actions = append(actions, "close")
|
||||
}
|
||||
return actions
|
||||
}
|
||||
|
||||
func (o *ActionOptions) GetRandomOffset() float64 {
|
||||
if len(o.OffsetRandomRange) != 2 {
|
||||
// invalid offset random range, should be [min, max]
|
||||
return 0
|
||||
}
|
||||
|
||||
minOffset := o.OffsetRandomRange[0]
|
||||
maxOffset := o.OffsetRandomRange[1]
|
||||
return float64(builtin.GetRandomNumber(minOffset, maxOffset)) + rand.Float64()
|
||||
}
|
||||
|
||||
func (o *ActionOptions) UpdateData(data map[string]interface{}) {
|
||||
if o.Identifier != "" {
|
||||
data["log"] = map[string]interface{}{
|
||||
"enable": true,
|
||||
"data": o.Identifier,
|
||||
}
|
||||
}
|
||||
|
||||
if o.Steps > 0 {
|
||||
data["steps"] = o.Steps
|
||||
}
|
||||
if _, ok := data["steps"]; !ok {
|
||||
data["steps"] = 12 // default steps
|
||||
}
|
||||
|
||||
if o.Duration > 0 {
|
||||
data["duration"] = o.Duration
|
||||
}
|
||||
if _, ok := data["duration"]; !ok {
|
||||
data["duration"] = 0 // default duration
|
||||
}
|
||||
|
||||
if o.Frequency > 0 {
|
||||
data["frequency"] = o.Frequency
|
||||
}
|
||||
if _, ok := data["frequency"]; !ok {
|
||||
data["frequency"] = 10 // default frequency
|
||||
}
|
||||
|
||||
if _, ok := data["replace"]; !ok {
|
||||
data["replace"] = true // default true
|
||||
}
|
||||
|
||||
// custom options
|
||||
if o.Custom != nil {
|
||||
for k, v := range o.Custom {
|
||||
data[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewActionOptions(opts ...ActionOption) *ActionOptions {
|
||||
actionOptions := &ActionOptions{}
|
||||
for _, option := range opts {
|
||||
option(actionOptions)
|
||||
}
|
||||
return actionOptions
|
||||
}
|
||||
|
||||
type ActionOption func(o *ActionOptions)
|
||||
|
||||
func WithCustomOption(key string, value interface{}) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
if o.Custom == nil {
|
||||
o.Custom = make(map[string]interface{})
|
||||
}
|
||||
o.Custom[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
func WithIdentifier(identifier string) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Identifier = identifier
|
||||
}
|
||||
}
|
||||
|
||||
func WithIndex(index int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Index = index
|
||||
}
|
||||
}
|
||||
|
||||
// set alias for compatibility
|
||||
var WithWaitTime = WithInterval
|
||||
|
||||
func WithInterval(sec float64) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Interval = sec
|
||||
}
|
||||
}
|
||||
|
||||
func WithDuration(duration float64) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Duration = duration
|
||||
}
|
||||
}
|
||||
|
||||
func WithPressDuration(pressDuration float64) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.PressDuration = pressDuration
|
||||
}
|
||||
}
|
||||
|
||||
func WithSteps(steps int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Steps = steps
|
||||
}
|
||||
}
|
||||
|
||||
// WithDirection inputs direction (up, down, left, right)
|
||||
func WithDirection(direction string) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Direction = direction
|
||||
}
|
||||
}
|
||||
|
||||
// WithCustomDirection inputs sx, sy, ex, ey
|
||||
func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Direction = []float64{sx, sy, ex, ey}
|
||||
}
|
||||
}
|
||||
|
||||
// WithScope inputs area of [(x1,y1), (x2,y2)]
|
||||
// x1, y1, x2, y2 are all in [0, 1], which means the relative position of the screen
|
||||
func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Scope = Scope{x1, y1, x2, y2}
|
||||
}
|
||||
}
|
||||
|
||||
// WithAbsScope inputs area of [(x1,y1), (x2,y2)]
|
||||
// x1, y1, x2, y2 are all absolute position of the screen
|
||||
func WithAbsScope(x1, y1, x2, y2 int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.AbsScope = AbsScope{x1, y1, x2, y2}
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated: use WithTapOffset instead
|
||||
func WithOffset(offsetX, offsetY int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Offset = []int{offsetX, offsetY}
|
||||
}
|
||||
}
|
||||
|
||||
// tap [x, y] with offset [offsetX, offsetY]
|
||||
var WithTapOffset = WithOffset
|
||||
|
||||
// swipe [fromX, fromY, toX, toY] with offset [offsetFromX, offsetFromY, offsetToX, offsetToY]
|
||||
func WithSwipeOffset(offsetFromX, offsetFromY, offsetToX, offsetToY int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Offset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY}
|
||||
}
|
||||
}
|
||||
|
||||
func WithOffsetRandomRange(min, max int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.OffsetRandomRange = []int{min, max}
|
||||
}
|
||||
}
|
||||
|
||||
func WithRegex(regex bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Regex = regex
|
||||
}
|
||||
}
|
||||
|
||||
func WithMatchOne(matchOne bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.MatchOne = matchOne
|
||||
}
|
||||
}
|
||||
|
||||
func WithFrequency(frequency int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Frequency = frequency
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaxRetryTimes(maxRetryTimes int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.MaxRetryTimes = maxRetryTimes
|
||||
}
|
||||
}
|
||||
|
||||
func WithTimeout(timeout int) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.Timeout = timeout
|
||||
}
|
||||
}
|
||||
|
||||
func WithIgnoreNotFoundError(ignoreError bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.IgnoreNotFoundError = ignoreError
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotOCR(ocrOn bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithOCR = ocrOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotUpload(uploadOn bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithUpload = uploadOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotLiveType(liveTypeOn bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithLiveType = liveTypeOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotLivePopularity(livePopularityOn bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithLivePopularity = livePopularityOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotUITypes(uiTypes ...string) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithUITypes = uiTypes
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotClosePopups(closeOn bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithClosePopups = closeOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenOCRCluster(ocrCluster string) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotWithOCRCluster = ocrCluster
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenShotFileName(fileName string) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenShotFileName = fileName
|
||||
}
|
||||
}
|
||||
75
pkg/uixt/option/android.go
Normal file
75
pkg/uixt/option/android.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package option
|
||||
|
||||
type AndroidDeviceConfig struct {
|
||||
SerialNumber string `json:"serial,omitempty" yaml:"serial,omitempty"`
|
||||
STUB bool `json:"stub,omitempty" yaml:"stub,omitempty"` // use stub
|
||||
UIA2 bool `json:"uia2,omitempty" yaml:"uia2,omitempty"` // use uiautomator2
|
||||
UIA2IP string `json:"uia2_ip,omitempty" yaml:"uia2_ip,omitempty"` // uiautomator2 server ip
|
||||
UIA2Port int `json:"uia2_port,omitempty" yaml:"uia2_port,omitempty"` // uiautomator2 server port
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
}
|
||||
|
||||
func (dev *AndroidDeviceConfig) Options() (deviceOptions []AndroidDeviceOption) {
|
||||
if dev.SerialNumber != "" {
|
||||
deviceOptions = append(deviceOptions, WithSerialNumber(dev.SerialNumber))
|
||||
}
|
||||
if dev.UIA2 {
|
||||
deviceOptions = append(deviceOptions, WithUIA2(true))
|
||||
}
|
||||
if dev.UIA2IP != "" {
|
||||
deviceOptions = append(deviceOptions, WithUIA2IP(dev.UIA2IP))
|
||||
}
|
||||
if dev.UIA2Port != 0 {
|
||||
deviceOptions = append(deviceOptions, WithUIA2Port(dev.UIA2Port))
|
||||
}
|
||||
if dev.LogOn {
|
||||
deviceOptions = append(deviceOptions, WithAdbLogOn(true))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewAndroidDeviceConfig(opts ...AndroidDeviceOption) *AndroidDeviceConfig {
|
||||
config := &AndroidDeviceConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
type AndroidDeviceOption func(*AndroidDeviceConfig)
|
||||
|
||||
func WithSerialNumber(serial string) AndroidDeviceOption {
|
||||
return func(device *AndroidDeviceConfig) {
|
||||
device.SerialNumber = serial
|
||||
}
|
||||
}
|
||||
|
||||
func WithUIA2(uia2On bool) AndroidDeviceOption {
|
||||
return func(device *AndroidDeviceConfig) {
|
||||
device.UIA2 = uia2On
|
||||
}
|
||||
}
|
||||
|
||||
func WithStub(stubOn bool) AndroidDeviceOption {
|
||||
return func(device *AndroidDeviceConfig) {
|
||||
device.STUB = stubOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithUIA2IP(ip string) AndroidDeviceOption {
|
||||
return func(device *AndroidDeviceConfig) {
|
||||
device.UIA2IP = ip
|
||||
}
|
||||
}
|
||||
|
||||
func WithUIA2Port(port int) AndroidDeviceOption {
|
||||
return func(device *AndroidDeviceConfig) {
|
||||
device.UIA2Port = port
|
||||
}
|
||||
}
|
||||
|
||||
func WithAdbLogOn(logOn bool) AndroidDeviceOption {
|
||||
return func(device *AndroidDeviceConfig) {
|
||||
device.LogOn = logOn
|
||||
}
|
||||
}
|
||||
96
pkg/uixt/option/capabilities.go
Normal file
96
pkg/uixt/option/capabilities.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package option
|
||||
|
||||
type AlertAction string
|
||||
|
||||
const (
|
||||
AlertActionAccept AlertAction = "accept"
|
||||
AlertActionDismiss AlertAction = "dismiss"
|
||||
)
|
||||
|
||||
type Capabilities map[string]interface{}
|
||||
|
||||
func NewCapabilities() Capabilities {
|
||||
return make(Capabilities)
|
||||
}
|
||||
|
||||
// WithDefaultAlertAction
|
||||
func (caps Capabilities) WithDefaultAlertAction(alertAction AlertAction) Capabilities {
|
||||
caps["defaultAlertAction"] = alertAction
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithMaxTypingFrequency
|
||||
//
|
||||
// Defaults to `60`.
|
||||
func (caps Capabilities) WithMaxTypingFrequency(n int) Capabilities {
|
||||
if n <= 0 {
|
||||
n = 60
|
||||
}
|
||||
caps["maxTypingFrequency"] = n
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithWaitForIdleTimeout
|
||||
//
|
||||
// Defaults to `10`
|
||||
func (caps Capabilities) WithWaitForIdleTimeout(second float64) Capabilities {
|
||||
caps["waitForIdleTimeout"] = second
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithShouldUseTestManagerForVisibilityDetection If set to YES will ask TestManagerDaemon for element visibility
|
||||
//
|
||||
// Defaults to `false`
|
||||
func (caps Capabilities) WithShouldUseTestManagerForVisibilityDetection(b bool) Capabilities {
|
||||
caps["shouldUseTestManagerForVisibilityDetection"] = b
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithShouldUseCompactResponses If set to YES will use compact (standards-compliant) & faster responses
|
||||
//
|
||||
// Defaults to `true`
|
||||
func (caps Capabilities) WithShouldUseCompactResponses(b bool) Capabilities {
|
||||
caps["shouldUseCompactResponses"] = b
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithElementResponseAttributes If shouldUseCompactResponses == NO,
|
||||
// is the comma-separated list of fields to return with each element.
|
||||
//
|
||||
// Defaults to `type,label`.
|
||||
func (caps Capabilities) WithElementResponseAttributes(s string) Capabilities {
|
||||
caps["elementResponseAttributes"] = s
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithShouldUseSingletonTestManager
|
||||
//
|
||||
// Defaults to `true`
|
||||
func (caps Capabilities) WithShouldUseSingletonTestManager(b bool) Capabilities {
|
||||
caps["shouldUseSingletonTestManager"] = b
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithDisableAutomaticScreenshots
|
||||
//
|
||||
// Defaults to `true`
|
||||
func (caps Capabilities) WithDisableAutomaticScreenshots(b bool) Capabilities {
|
||||
caps["disableAutomaticScreenshots"] = b
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithShouldTerminateApp
|
||||
//
|
||||
// Defaults to `true`
|
||||
func (caps Capabilities) WithShouldTerminateApp(b bool) Capabilities {
|
||||
caps["shouldTerminateApp"] = b
|
||||
return caps
|
||||
}
|
||||
|
||||
// WithEventloopIdleDelaySec
|
||||
// Delays the invocation of '-[XCUIApplicationProcess setEventLoopHasIdled:]' by the timer interval passed.
|
||||
// which is skipped on setting it to zero.
|
||||
func (caps Capabilities) WithEventloopIdleDelaySec(second float64) Capabilities {
|
||||
caps["eventloopIdleDelaySec"] = second
|
||||
return caps
|
||||
}
|
||||
55
pkg/uixt/option/driver.go
Normal file
55
pkg/uixt/option/driver.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package option
|
||||
|
||||
import "github.com/httprunner/funplugin"
|
||||
|
||||
type DriverOptions struct {
|
||||
Capabilities Capabilities
|
||||
Plugin funplugin.IPlugin
|
||||
WithImageService bool
|
||||
WithResultFolder bool
|
||||
WithUIAction bool
|
||||
}
|
||||
|
||||
func NewDriverOptions(opts ...DriverOption) *DriverOptions {
|
||||
driverOptions := &DriverOptions{
|
||||
WithImageService: true,
|
||||
WithResultFolder: true,
|
||||
WithUIAction: true,
|
||||
}
|
||||
for _, option := range opts {
|
||||
option(driverOptions)
|
||||
}
|
||||
return driverOptions
|
||||
}
|
||||
|
||||
type DriverOption func(*DriverOptions)
|
||||
|
||||
func WithDriverCapabilities(capabilities Capabilities) DriverOption {
|
||||
return func(options *DriverOptions) {
|
||||
options.Capabilities = capabilities
|
||||
}
|
||||
}
|
||||
|
||||
func WithDriverImageService(withImageService bool) DriverOption {
|
||||
return func(options *DriverOptions) {
|
||||
options.WithImageService = withImageService
|
||||
}
|
||||
}
|
||||
|
||||
func WithDriverResultFolder(withResultFolder bool) DriverOption {
|
||||
return func(options *DriverOptions) {
|
||||
options.WithResultFolder = withResultFolder
|
||||
}
|
||||
}
|
||||
|
||||
func WithUIAction(withUIAction bool) DriverOption {
|
||||
return func(options *DriverOptions) {
|
||||
options.WithUIAction = withUIAction
|
||||
}
|
||||
}
|
||||
|
||||
func WithDriverPlugin(plugin funplugin.IPlugin) DriverOption {
|
||||
return func(options *DriverOptions) {
|
||||
options.Plugin = plugin
|
||||
}
|
||||
}
|
||||
38
pkg/uixt/option/harmony.go
Normal file
38
pkg/uixt/option/harmony.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package option
|
||||
|
||||
type HarmonyDeviceConfig struct {
|
||||
ConnectKey string `json:"connect_key,omitempty" yaml:"connect_key,omitempty"`
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
}
|
||||
|
||||
func (dev *HarmonyDeviceConfig) Options() (deviceOptions []HarmonyDeviceOption) {
|
||||
if dev.ConnectKey != "" {
|
||||
deviceOptions = append(deviceOptions, WithConnectKey(dev.ConnectKey))
|
||||
}
|
||||
if dev.LogOn {
|
||||
deviceOptions = append(deviceOptions, WithLogOn(true))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewHarmonyDeviceConfig(opts ...HarmonyDeviceOption) (device *HarmonyDeviceConfig) {
|
||||
device = &HarmonyDeviceConfig{}
|
||||
for _, option := range opts {
|
||||
option(device)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type HarmonyDeviceOption func(*HarmonyDeviceConfig)
|
||||
|
||||
func WithConnectKey(connectKey string) HarmonyDeviceOption {
|
||||
return func(device *HarmonyDeviceConfig) {
|
||||
device.ConnectKey = connectKey
|
||||
}
|
||||
}
|
||||
|
||||
func WithLogOn(logOn bool) HarmonyDeviceOption {
|
||||
return func(device *HarmonyDeviceConfig) {
|
||||
device.LogOn = logOn
|
||||
}
|
||||
}
|
||||
42
pkg/uixt/option/install.go
Normal file
42
pkg/uixt/option/install.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package option
|
||||
|
||||
type InstallOptions struct {
|
||||
Reinstall bool
|
||||
GrantPermission bool
|
||||
Downgrade bool
|
||||
RetryTimes int
|
||||
}
|
||||
|
||||
type InstallOption func(o *InstallOptions)
|
||||
|
||||
func NewInstallOptions(opts ...InstallOption) *InstallOptions {
|
||||
installOptions := &InstallOptions{}
|
||||
for _, option := range opts {
|
||||
option(installOptions)
|
||||
}
|
||||
return installOptions
|
||||
}
|
||||
|
||||
func WithReinstall(reinstall bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.Reinstall = reinstall
|
||||
}
|
||||
}
|
||||
|
||||
func WithGrantPermission(grantPermission bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.GrantPermission = grantPermission
|
||||
}
|
||||
}
|
||||
|
||||
func WithDowngrade(downgrade bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.Downgrade = downgrade
|
||||
}
|
||||
}
|
||||
|
||||
func WithRetryTimes(retryTimes int) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.RetryTimes = retryTimes
|
||||
}
|
||||
}
|
||||
112
pkg/uixt/option/ios.go
Normal file
112
pkg/uixt/option/ios.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package option
|
||||
|
||||
type IOSDeviceConfig struct {
|
||||
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
||||
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||
STUB bool `json:"stub,omitempty" yaml:"stub,omitempty"` // use stub
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
|
||||
// switch to iOS springboard before init WDA session
|
||||
ResetHomeOnStartup bool `json:"reset_home_on_startup,omitempty" yaml:"reset_home_on_startup,omitempty"`
|
||||
|
||||
// config appium settings
|
||||
SnapshotMaxDepth int `json:"snapshot_max_depth,omitempty" yaml:"snapshot_max_depth,omitempty"`
|
||||
AcceptAlertButtonSelector string `json:"accept_alert_button_selector,omitempty" yaml:"accept_alert_button_selector,omitempty"`
|
||||
DismissAlertButtonSelector string `json:"dismiss_alert_button_selector,omitempty" yaml:"dismiss_alert_button_selector,omitempty"`
|
||||
}
|
||||
|
||||
func (dev *IOSDeviceConfig) Options() (deviceOptions []IOSDeviceOption) {
|
||||
if dev.UDID != "" {
|
||||
deviceOptions = append(deviceOptions, WithUDID(dev.UDID))
|
||||
}
|
||||
if dev.Port != 0 {
|
||||
deviceOptions = append(deviceOptions, WithWDAPort(dev.Port))
|
||||
}
|
||||
if dev.MjpegPort != 0 {
|
||||
deviceOptions = append(deviceOptions, WithWDAMjpegPort(dev.MjpegPort))
|
||||
}
|
||||
if dev.STUB {
|
||||
deviceOptions = append(deviceOptions, WithIOSStub(true))
|
||||
}
|
||||
if dev.LogOn {
|
||||
deviceOptions = append(deviceOptions, WithWDALogOn(true))
|
||||
}
|
||||
if dev.ResetHomeOnStartup {
|
||||
deviceOptions = append(deviceOptions, WithResetHomeOnStartup(true))
|
||||
}
|
||||
if dev.SnapshotMaxDepth != 0 {
|
||||
deviceOptions = append(deviceOptions, WithSnapshotMaxDepth(dev.SnapshotMaxDepth))
|
||||
}
|
||||
if dev.AcceptAlertButtonSelector != "" {
|
||||
deviceOptions = append(deviceOptions, WithAcceptAlertButtonSelector(dev.AcceptAlertButtonSelector))
|
||||
}
|
||||
if dev.DismissAlertButtonSelector != "" {
|
||||
deviceOptions = append(deviceOptions, WithDismissAlertButtonSelector(dev.DismissAlertButtonSelector))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewIOSDeviceConfig(opts ...IOSDeviceOption) *IOSDeviceConfig {
|
||||
config := &IOSDeviceConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
type IOSDeviceOption func(*IOSDeviceConfig)
|
||||
|
||||
func WithUDID(udid string) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.UDID = udid
|
||||
}
|
||||
}
|
||||
|
||||
func WithWDAPort(port int) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.Port = port
|
||||
}
|
||||
}
|
||||
|
||||
func WithWDAMjpegPort(port int) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.MjpegPort = port
|
||||
}
|
||||
}
|
||||
|
||||
func WithWDALogOn(logOn bool) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.LogOn = logOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithIOSStub(stub bool) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.STUB = stub
|
||||
}
|
||||
}
|
||||
|
||||
func WithResetHomeOnStartup(reset bool) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.ResetHomeOnStartup = reset
|
||||
}
|
||||
}
|
||||
|
||||
func WithSnapshotMaxDepth(depth int) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.SnapshotMaxDepth = depth
|
||||
}
|
||||
}
|
||||
|
||||
func WithAcceptAlertButtonSelector(selector string) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.AcceptAlertButtonSelector = selector
|
||||
}
|
||||
}
|
||||
|
||||
func WithDismissAlertButtonSelector(selector string) IOSDeviceOption {
|
||||
return func(device *IOSDeviceConfig) {
|
||||
device.DismissAlertButtonSelector = selector
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user