mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-07 14:43:33 +08:00
fix: WDA tests
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user