feat: add PushImage/ClearImages in IDriver

This commit is contained in:
lilong.129
2025-02-18 19:33:57 +08:00
parent 7b052f0d98
commit 5d91b69603
7 changed files with 104 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import (
"io/fs"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
@@ -423,7 +424,11 @@ func (ad *ADBDriver) Input(text string, opts ...option.ActionOption) error {
return nil
}
// adb shell input text <text>
_, err = ad.runShellCommand("input", "text", text)
return ad.input(text, opts...)
}
func (ad *ADBDriver) input(text string, _ ...option.ActionOption) error {
_, err := ad.runShellCommand("input", "text", text)
if err != nil {
return errors.Wrap(err, "send keys failed")
}
@@ -456,7 +461,7 @@ func (ad *ADBDriver) SendUnicodeKeys(text string, opts ...option.ActionOption) (
log.Warn().Err(err).Msgf("encode text with modified utf7 failed")
return
}
err = ad.Input("\""+strings.ReplaceAll(encodedStr, "\"", "\\\"")+"\"", opts...)
err = ad.input("\""+strings.ReplaceAll(encodedStr, "\"", "\\\"")+"\"", opts...)
return
}
@@ -850,6 +855,29 @@ func (ad *ADBDriver) TearDown() error {
return nil
}
func (ad *ADBDriver) OpenUrl(url string) (err error) {
_, err = ad.runShellCommand(
"am", "start", "-W", "-a", "android.intent.action.VIEW",
"-d", fmt.Sprintf("'%s'", url))
return
}
func (ad *ADBDriver) PushImage(localPath string) error {
remotePath := path.Join("/sdcard/DCIM/Camera/", path.Base(localPath))
if err := ad.Device.PushFile(localPath, remotePath); err != nil {
return err
}
_, _ = ad.Device.RunShellCommand("am", "broadcast",
"-a", "android.intent.action.MEDIA_SCANNER_SCAN_FILE",
"-d", fmt.Sprintf("file://%s", remotePath))
return nil
}
func (ad *ADBDriver) ClearImages() error {
_, _ = ad.Device.RunShellCommand("rm", "-rf", "/sdcard/DCIM/Camera/*")
return nil
}
type ExportPoint struct {
Start int `json:"start" yaml:"start"`
End int `json:"end" yaml:"end"`