change: TapByHierarchy

This commit is contained in:
lilong.129
2025-02-11 22:05:11 +08:00
parent e02e889a8e
commit be95cecdfb
6 changed files with 188 additions and 209 deletions

View File

@@ -548,6 +548,14 @@ func (ad *ADBDriver) ScreenShot(opts ...option.ActionOption) (raw *bytes.Buffer,
return raw, nil
}
func (ad *ADBDriver) TapByHierarchy(text string, opts ...option.ActionOption) error {
sourceTree, err := ad.sourceTree()
if err != nil {
return err
}
return ad.tapByTextUsingHierarchy(sourceTree, text, opts...)
}
func (ad *ADBDriver) Source(srcOpt ...option.SourceOption) (source string, err error) {
_, err = ad.runShellCommand("rm", "-rf", "/sdcard/window_dump.xml")
if err != nil {
@@ -566,7 +574,7 @@ func (ad *ADBDriver) Source(srcOpt ...option.SourceOption) (source string, err e
}
func (ad *ADBDriver) sourceTree(srcOpt ...option.SourceOption) (sourceTree *Hierarchy, err error) {
source, err := ad.Source()
source, err := ad.Source(srcOpt...)
if err != nil {
return
}
@@ -578,14 +586,6 @@ func (ad *ADBDriver) sourceTree(srcOpt ...option.SourceOption) (sourceTree *Hier
return
}
func (ad *ADBDriver) TapByText(text string, opts ...option.ActionOption) error {
sourceTree, err := ad.sourceTree()
if err != nil {
return err
}
return ad.tapByTextUsingHierarchy(sourceTree, text, opts...)
}
func (ad *ADBDriver) tapByTextUsingHierarchy(hierarchy *Hierarchy, text string, opts ...option.ActionOption) error {
bounds := ad.searchNodes(hierarchy.Layout, text, opts...)
actionOptions := option.NewActionOptions(opts...)
@@ -606,21 +606,6 @@ func (ad *ADBDriver) tapByTextUsingHierarchy(hierarchy *Hierarchy, text string,
return nil
}
func (ad *ADBDriver) TapByTexts(actions ...TapTextAction) error {
sourceTree, err := ad.sourceTree()
if err != nil {
return err
}
for _, action := range actions {
err := ad.tapByTextUsingHierarchy(sourceTree, action.Text, action.Options...)
if err != nil {
return err
}
}
return nil
}
func (ad *ADBDriver) searchNodes(nodes []Layout, text string, opts ...option.ActionOption) []Bounds {
actionOptions := option.NewActionOptions(opts...)
var results []Bounds