Merge branch 'dev-v4.3' of https://github.com/httprunner/httprunner into dev-v4.3

This commit is contained in:
debugtalk
2022-10-10 18:09:22 +08:00
3 changed files with 58 additions and 5 deletions

View File

@@ -684,13 +684,31 @@ func (ud *uiaDriver) SendKeys(text string, options ...DataOption) (err error) {
}
func (ud *uiaDriver) Input(text string, options ...DataOption) (err error) {
element, err := ud.FindElement(BySelector{ClassName: ElementType{EditText: true}})
data := map[string]interface{}{
"view": text,
}
// append options in post data for extra uiautomator configurations
for _, option := range options {
option(data)
}
var element WebElement
if valuetext, ok := data["text"]; ok {
element, err = ud.FindElement(BySelector{UiAutomator: NewUiSelectorHelper().TextContains(fmt.Sprintf("%v", valuetext)).String()})
} else if valueid, ok := data["id"]; ok {
element, err = ud.FindElement(BySelector{ResourceIdID: fmt.Sprintf("%v", valueid)})
} else if valuedesc, ok := data["description"]; ok {
element, err = ud.FindElement(BySelector{UiAutomator: NewUiSelectorHelper().Description(fmt.Sprintf("%v", valuedesc)).String()})
} else {
element, err = ud.FindElement(BySelector{ClassName: ElementType{EditText: true}})
}
if err != nil {
return err
}
return element.SendKeys(text, options...)
}
func (ud *uiaDriver) KeyboardDismiss(keyNames ...string) (err error) {
// TODO
return errDriverNotImplemented

View File

@@ -68,6 +68,9 @@ type MobileAction struct {
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)
@@ -84,6 +87,26 @@ func WithIndex(index int) ActionOption {
}
}
func WithText(text string) ActionOption {
return func(o *MobileAction) {
o.Text = text
}
}
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 {
return func(o *MobileAction) {
o.MaxRetryTimes = maxRetryTimes
@@ -474,14 +497,23 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
// append \n to send text with enter
// send \b\b\b to delete 3 chars
param := fmt.Sprintf("%v", action.Params)
options := []DataOption{}
if action.Text != "" {
options = append(options, WithCustomOption("text", 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 != "" {
option := WithCustomOption("log", map[string]interface{}{
options = append(options,WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": action.Identifier,
})
return dExt.Driver.Input(param, option)
}))
}
return dExt.Driver.Input(param)
return dExt.Driver.Input(param, options...)
case CtlSleep:
if param, ok := action.Params.(json.Number); ok {
seconds, _ := param.Float64()

View File

@@ -26,6 +26,9 @@ var (
WithIndex = uixt.WithIndex
WithTimeout = uixt.WithTimeout
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
WithText = uixt.WithText
WithID = uixt.WithID
WithDescription = uixt.WithDescription
)
var (