feat: double/long click on name or xpath

This commit is contained in:
debugtalk
2022-07-27 21:57:51 +08:00
parent 087743bd9c
commit c59703cbf2
+36 -18
View File
@@ -355,20 +355,7 @@ func (w *wdaClient) doAction(action MobileAction) error {
} }
// click on name or xpath // click on name or xpath
if param, ok := action.Params.(string); ok { if param, ok := action.Params.(string); ok {
var selector gwda.BySelector ele, err := w.findElement(param)
if strings.HasPrefix(param, "/") {
// xpath
selector = gwda.BySelector{
XPath: param,
}
} else {
// name
selector = gwda.BySelector{
Name: param,
}
}
ele, err := w.Driver.FindElement(selector)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to find element") return errors.Wrap(err, "failed to find element")
} }
@@ -376,11 +363,25 @@ func (w *wdaClient) doAction(action MobileAction) error {
} }
return fmt.Errorf("invalid click params: %v", action.Params) return fmt.Errorf("invalid click params: %v", action.Params)
case uiDoubleClick: case uiDoubleClick:
// TODO // double click on name or xpath
return errActionNotImplemented if param, ok := action.Params.(string); ok {
ele, err := w.findElement(param)
if err != nil {
return errors.Wrap(err, "failed to find element")
}
return ele.DoubleTap()
}
return fmt.Errorf("invalid click params: %v", action.Params)
case uiLongClick: case uiLongClick:
// TODO // long click 2s on name or xpath
return errActionNotImplemented if param, ok := action.Params.(string); ok {
ele, err := w.findElement(param)
if err != nil {
return errors.Wrap(err, "failed to find element")
}
return ele.TouchAndHold(2)
}
return fmt.Errorf("invalid click params: %v", action.Params)
case uiSwipe: case uiSwipe:
width := w.WindowSize.Width width := w.WindowSize.Width
height := w.WindowSize.Height height := w.WindowSize.Height
@@ -472,6 +473,23 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
return return
} }
func (w *wdaClient) findElement(param string) (ele gwda.WebElement, err error) {
var selector gwda.BySelector
if strings.HasPrefix(param, "/") {
// xpath
selector = gwda.BySelector{
XPath: param,
}
} else {
// name
selector = gwda.BySelector{
Name: param,
}
}
return w.Driver.FindElement(selector)
}
func (w *wdaClient) assertName(name string, exists bool) bool { func (w *wdaClient) assertName(name string, exists bool) bool {
selector := gwda.BySelector{ selector := gwda.BySelector{
Name: name, Name: name,