mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: failed to send keys in android ui automation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -464,14 +487,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()
|
||||
|
||||
@@ -22,6 +22,9 @@ var (
|
||||
WithIndex = uixt.WithIndex
|
||||
WithTimeout = uixt.WithTimeout
|
||||
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
|
||||
WithText = uixt.WithText
|
||||
WithID = uixt.WithID
|
||||
WithDescription = uixt.WithDescription
|
||||
)
|
||||
|
||||
type StepResult struct {
|
||||
|
||||
Reference in New Issue
Block a user