fix: WDA tests

This commit is contained in:
lilong.129
2025-02-17 22:02:12 +08:00
parent 3ae314d0ba
commit e985697227
12 changed files with 298 additions and 327 deletions

View File

@@ -13,9 +13,9 @@ type ActionOptions struct {
// control related
MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times
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
Duration float64 `json:"duration,omitempty" yaml:"duration,omitempty"` // used to set duration in seconds
PressDuration float64 `json:"press_duration,omitempty" yaml:"press_duration,omitempty"` // used to set press duration in seconds
Steps int `json:"steps,omitempty" yaml:"steps,omitempty"` // used to set steps of 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"`
@@ -142,7 +142,8 @@ func (o *ActionOptions) GetRandomOffset() float64 {
return float64(builtin.GetRandomNumber(minOffset, maxOffset)) + rand.Float64()
}
func (o *ActionOptions) UpdateData(data map[string]interface{}) {
func MergeOptions(data map[string]interface{}, opts ...ActionOption) {
o := NewActionOptions(opts...)
if o.Identifier != "" {
data["log"] = map[string]interface{}{
"enable": true,
@@ -164,6 +165,10 @@ func (o *ActionOptions) UpdateData(data map[string]interface{}) {
data["duration"] = 0 // default duration
}
if o.PressDuration > 0 {
data["pressDuration"] = o.PressDuration
}
if o.Frequency > 0 {
data["frequency"] = o.Frequency
}

View File

@@ -2,53 +2,74 @@ package option
import "strings"
// SourceOption Configure the format or attribute of the Source
type SourceOption map[string]interface{}
func NewSourceOption() SourceOption {
return make(SourceOption)
}
// WithFormatAsJson Application elements tree in form of json string
func (opt SourceOption) WithFormatAsJson() SourceOption {
opt["format"] = "json"
return opt
}
func (opt SourceOption) WithProcessName(processName string) SourceOption {
opt["processName"] = processName
return opt
}
// WithFormatAsXml Application elements tree in form of xml string
func (opt SourceOption) WithFormatAsXml() SourceOption {
opt["format"] = "xml"
return opt
}
// WithFormatAsDescription Application elements tree in form of internal XCTest debugDescription string
func (opt SourceOption) WithFormatAsDescription() SourceOption {
opt["format"] = "description"
return opt
}
// WithScope Allows to provide XML scope.
//
// only `xml` is supported.
func (opt SourceOption) WithScope(scope string) SourceOption {
if vFormat, ok := opt["format"]; ok && vFormat != "xml" {
return opt
func NewSourceOptions(opts ...SourceOption) *SourceOptions {
options := &SourceOptions{}
for _, option := range opts {
option(options)
}
return options
}
type SourceOptions struct {
Format SourceFormat `json:"format,omitempty"`
ProcessName string `json:"processName,omitempty"`
Scope string `json:"scope,omitempty"`
ExcludedAttributes string `json:"excluded_attributes,omitempty"`
}
func (o *SourceOptions) Query() string {
query := []string{}
if o.Format != "" {
query = append(query, "format="+string(o.Format))
}
if o.ProcessName != "" {
query = append(query, "processName="+o.ProcessName)
}
if o.Scope != "" {
query = append(query, "scope="+o.Scope)
}
if o.ExcludedAttributes != "" {
query = append(query, "excluded_attributes="+o.ExcludedAttributes)
}
return strings.Join(query, "&")
}
type SourceOption func(o *SourceOptions)
type SourceFormat string
const (
SourceFormatJSON SourceFormat = "json"
SourceFormatXML SourceFormat = "xml"
SourceFormatDescription SourceFormat = "description"
)
// WithFormat specify Application elements tree format
// `json` or `xml` or `description`
func WithFormat(format SourceFormat) SourceOption {
return func(o *SourceOptions) {
o.Format = format
}
}
func WithProcessName(name string) SourceOption {
return func(o *SourceOptions) {
o.ProcessName = name
}
}
// WithSourceScope Allows to provide XML scope.
// only `xml` is supported.
func WithSourceScope(scope string) SourceOption {
return func(o *SourceOptions) {
o.Scope = scope
}
opt["scope"] = scope
return opt
}
// WithExcludedAttributes Excludes the given attribute names.
// only `xml` is supported.
func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption {
if vFormat, ok := opt["format"]; ok && vFormat != "xml" {
return opt
func WithExcludedAttributes(attributes []string) SourceOption {
return func(o *SourceOptions) {
o.ExcludedAttributes = strings.Join(attributes, ",")
}
opt["excluded_attributes"] = strings.Join(attributes, ",")
return opt
}