mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:29:48 +08:00
fix: failed to input on android device
This commit is contained in:
@@ -676,6 +676,14 @@ func (ud *uiaDriver) SendKeys(text string, options ...DataOption) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ud *uiaDriver) Input(text string, options ...DataOption) (err error) {
|
||||
element, err := ud.FindElement(BySelector{ClassName: ElementType{EditText: true}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return element.SendKeys(text)
|
||||
}
|
||||
|
||||
func (ud *uiaDriver) KeyboardDismiss(keyNames ...string) (err error) {
|
||||
// TODO
|
||||
return errDriverNotImplemented
|
||||
|
||||
@@ -301,45 +301,6 @@ func (dExt *DriverExt) IsImageExist(text string) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) StartLogRecording(identifier string) error {
|
||||
if _, ok := dExt.Driver.(*wdaDriver); ok {
|
||||
log.Info().Msg("start WDA log recording")
|
||||
data := map[string]interface{}{"action": "start", "type": 2, "identifier": identifier}
|
||||
_, err := dExt.triggerWDALog(data)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to start WDA log recording")
|
||||
}
|
||||
} else {
|
||||
log.Info().Msg("start adb log recording")
|
||||
err := dExt.Driver.(*uiaDriver).logcat.CatchLogcat()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to start adb log recording")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) GetLogs() (interface{}, error) {
|
||||
if _, ok := dExt.Driver.(*wdaDriver); ok {
|
||||
log.Info().Msg("stop WDA log recording")
|
||||
data := map[string]interface{}{"action": "stop"}
|
||||
reply, err := dExt.triggerWDALog(data)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to get WDA logs")
|
||||
}
|
||||
return reply.Value, nil
|
||||
} else {
|
||||
log.Info().Msg("stop adb log recording")
|
||||
err := dExt.Driver.(*uiaDriver).logcat.Stop()
|
||||
if err != nil {
|
||||
println("failed to get adb log recording")
|
||||
//return "", errors.Wrap(err, "failed to get adb log recording")
|
||||
}
|
||||
content := dExt.Driver.(*uiaDriver).logcat.logBuffer.String()
|
||||
return ConvertPoints(content), err
|
||||
}
|
||||
}
|
||||
|
||||
var errActionNotImplemented = errors.New("UI action not implemented")
|
||||
|
||||
func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
@@ -508,9 +469,9 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
"enable": true,
|
||||
"data": action.Identifier,
|
||||
})
|
||||
return dExt.Driver.SendKeys(param, option)
|
||||
return dExt.Driver.Input(param, option)
|
||||
}
|
||||
return dExt.Driver.SendKeys(param)
|
||||
return dExt.Driver.Input(param)
|
||||
case CtlSleep:
|
||||
if param, ok := action.Params.(json.Number); ok {
|
||||
seconds, _ := param.Float64()
|
||||
|
||||
@@ -715,6 +715,7 @@ type ElementType struct {
|
||||
Tab bool `json:"XCUIElementTypeTab"`
|
||||
TouchBar bool `json:"XCUIElementTypeTouchBar"`
|
||||
StatusItem bool `json:"XCUIElementTypeStatusItem"`
|
||||
EditText bool `json:"android.widget.EditText"`
|
||||
}
|
||||
|
||||
// ProtectedResource A system resource that requires user authorization to access.
|
||||
@@ -927,6 +928,9 @@ type WebDriver interface {
|
||||
// WithFrequency option can be used to set frequency of typing (letters per sec). The default value is 60
|
||||
SendKeys(text string, options ...DataOption) error
|
||||
|
||||
// Input works like SendKeys
|
||||
Input(text string, options ...DataOption) error
|
||||
|
||||
// KeyboardDismiss Tries to dismiss the on-screen keyboard
|
||||
KeyboardDismiss(keyNames ...string) error
|
||||
|
||||
|
||||
@@ -527,6 +527,10 @@ func (wd *wdaDriver) SendKeys(text string, options ...DataOption) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) Input(text string, options ...DataOption) (err error) {
|
||||
return wd.SendKeys(text, options...)
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) KeyboardDismiss(keyNames ...string) (err error) {
|
||||
// [[FBRoute POST:@"/wda/keyboard/dismiss"] respondWithTarget:self action:@selector(handleDismissKeyboardCommand:)]
|
||||
if len(keyNames) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user