mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 23:11:21 +08:00
Merge branch 'dev-v4.3' of https://github.com/httprunner/httprunner into dev-v4.3
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) {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return element.SendKeys(text, options...)
|
return element.SendKeys(text, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (ud *uiaDriver) KeyboardDismiss(keyNames ...string) (err error) {
|
func (ud *uiaDriver) KeyboardDismiss(keyNames ...string) (err error) {
|
||||||
// TODO
|
// TODO
|
||||||
return errDriverNotImplemented
|
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
|
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
|
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
|
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)
|
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 {
|
func WithMaxRetryTimes(maxRetryTimes int) ActionOption {
|
||||||
return func(o *MobileAction) {
|
return func(o *MobileAction) {
|
||||||
o.MaxRetryTimes = maxRetryTimes
|
o.MaxRetryTimes = maxRetryTimes
|
||||||
@@ -474,14 +497,23 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
// append \n to send text with enter
|
// append \n to send text with enter
|
||||||
// send \b\b\b to delete 3 chars
|
// send \b\b\b to delete 3 chars
|
||||||
param := fmt.Sprintf("%v", action.Params)
|
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 != "" {
|
if action.Identifier != "" {
|
||||||
option := WithCustomOption("log", map[string]interface{}{
|
options = append(options,WithCustomOption("log", map[string]interface{}{
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"data": action.Identifier,
|
"data": action.Identifier,
|
||||||
})
|
}))
|
||||||
return dExt.Driver.Input(param, option)
|
|
||||||
}
|
}
|
||||||
return dExt.Driver.Input(param)
|
return dExt.Driver.Input(param, options...)
|
||||||
case CtlSleep:
|
case CtlSleep:
|
||||||
if param, ok := action.Params.(json.Number); ok {
|
if param, ok := action.Params.(json.Number); ok {
|
||||||
seconds, _ := param.Float64()
|
seconds, _ := param.Float64()
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ var (
|
|||||||
WithIndex = uixt.WithIndex
|
WithIndex = uixt.WithIndex
|
||||||
WithTimeout = uixt.WithTimeout
|
WithTimeout = uixt.WithTimeout
|
||||||
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
|
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
|
||||||
|
WithText = uixt.WithText
|
||||||
|
WithID = uixt.WithID
|
||||||
|
WithDescription = uixt.WithDescription
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in New Issue
Block a user