diff --git a/internal/builtin/utils.go b/internal/builtin/utils.go index 045492d6..e4accadc 100644 --- a/internal/builtin/utils.go +++ b/internal/builtin/utils.go @@ -15,7 +15,6 @@ import ( "math/rand" "net" "net/http" - "net/url" "os" "os/exec" "path/filepath" @@ -383,57 +382,6 @@ func GetCurrentDay() string { return formattedDate } -func DownloadFile(filePath string, fileUrl string) error { - log.Info().Str("filePath", filePath).Str("url", fileUrl).Msg("download file") - parsedURL, err := url.Parse(fileUrl) - if err != nil { - return err - } - - out, err := os.Create(filePath) - if err != nil { - return err - } - defer out.Close() - - // 创建一个新的 HTTP 请求 - req, err := http.NewRequest("GET", fileUrl, nil) - if err != nil { - return err - } - - // TODO: rename token - eapiToken := os.Getenv("EAPI_TOKEN") - if eapiToken != "" { - if parsedURL.Host != "gtf-eapi-cn.bytedance.com" && parsedURL.Host != "gtf-eapi-cn.bytedance.net" { - return errors.New("invalid domain: must be gtf-eapi-cn.bytedance.com") - } - // 添加自定义头部 - req.Header.Add("accessKey", "ies.vedem.video") - req.Header.Add("token", eapiToken) - } - - // 创建一个 HTTP 客户端并发送请求 - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("bad status: %s, download failed", resp.Status) - } - - // 将响应主体写入文件 - _, err = io.Copy(out, resp.Body) - if err != nil { - return err - } - - return nil -} - func fileExists(filepath string) bool { _, err := os.Stat(filepath) if os.IsNotExist(err) { diff --git a/internal/version/VERSION b/internal/version/VERSION index da3d907e..3bd8feab 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502112106 +v5.0.0+2502112149 diff --git a/pkg/uixt/android_device.go b/pkg/uixt/android_device.go index 1931f8fd..7e38caf9 100644 --- a/pkg/uixt/android_device.go +++ b/pkg/uixt/android_device.go @@ -287,6 +287,12 @@ func (dev *AndroidDevice) installViaInstaller(apkPath string, args ...string) er } } +type InstallResult struct { + Result int `json:"result"` + ErrorCode int `json:"errorCode"` + ErrorMsg string `json:"errorMsg"` +} + func (dev *AndroidDevice) installCommon(apkPath string, args ...string) error { _, err := dev.Device.InstallAPK(apkPath, args...) return err diff --git a/pkg/uixt/android_driver_uia2.go b/pkg/uixt/android_driver_uia2.go index 757af8ed..f63cb610 100644 --- a/pkg/uixt/android_driver_uia2.go +++ b/pkg/uixt/android_driver_uia2.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/base64" "encoding/json" - "encoding/xml" "fmt" "net/http" "strings" @@ -546,39 +545,3 @@ func (ud *UIA2Driver) Source(srcOpt ...option.SourceOption) (source string, err source = reply.Value return } - -func (ud *UIA2Driver) sourceTree(srcOpt ...option.SourceOption) (sourceTree *Hierarchy, err error) { - source, err := ud.Source() - if err != nil { - return - } - sourceTree = new(Hierarchy) - err = xml.Unmarshal([]byte(source), sourceTree) - if err != nil { - return - } - return -} - -func (ud *UIA2Driver) TapByText(text string, opts ...option.ActionOption) error { - sourceTree, err := ud.sourceTree() - if err != nil { - return err - } - return ud.tapByTextUsingHierarchy(sourceTree, text, opts...) -} - -func (ud *UIA2Driver) TapByTexts(actions ...TapTextAction) error { - sourceTree, err := ud.sourceTree() - if err != nil { - return err - } - - for _, action := range actions { - err := ud.tapByTextUsingHierarchy(sourceTree, action.Text, action.Options...) - if err != nil { - return err - } - } - return nil -} diff --git a/pkg/uixt/android_test.go b/pkg/uixt/android_test.go index a7b50a66..68e3ffa8 100644 --- a/pkg/uixt/android_test.go +++ b/pkg/uixt/android_test.go @@ -105,13 +105,6 @@ func TestDriver_Source(t *testing.T) { t.Log(source) } -func TestDriver_TapByText(t *testing.T) { - err := driver.TapByText("安装") - if err != nil { - t.Fatal(err) - } -} - func TestDriver_BatteryInfo(t *testing.T) { batteryInfo, err := driver.BatteryInfo() if err != nil { @@ -342,39 +335,6 @@ func TestDriver_ShellInputUnicode(t *testing.T) { t.Log(os.WriteFile("s1.png", raw.Bytes(), 0o600)) } -func TestTapTexts(t *testing.T) { - setupAndroidUIA2Driver(t) - actions := []TapTextAction{ - { - Text: "^.*无视风险安装$", - Options: []option.ActionOption{ - option.WithTapOffset(100, 0), - option.WithRegex(true), - option.WithIgnoreNotFoundError(true), - }, - }, - { - Text: "已了解此应用未经检测.*", - Options: []option.ActionOption{ - option.WithTapOffset(-450, 0), - option.WithRegex(true), - option.WithIgnoreNotFoundError(true), - }, - }, - { - Text: "^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|安装|授权本次安装|继续安装|重新安装)$", - Options: []option.ActionOption{ - option.WithRegex(true), - option.WithIgnoreNotFoundError(true), - }, - }, - } - err := driverExt.TapByTexts(actions...) - if err != nil { - t.Fatal(err) - } -} - func TestRecordVideo(t *testing.T) { setupAndroidAdbDriver(t) path, err := driverExt.ScreenRecord(5 * time.Second) diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index 15b6ed58..577c1bea 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -62,8 +62,6 @@ type IDriver interface { TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate DoubleTapXY(x, y float64, opts ...option.ActionOption) error // by percentage TouchAndHold(x, y float64, opts ...option.ActionOption) error - TapByText(text string, opts ...option.ActionOption) error // TODO: remove - TapByTexts(actions ...TapTextAction) error // TODO: remove // swipe Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error // by percentage @@ -104,9 +102,6 @@ type IDriverExt interface { CheckPopup() (popup *PopupInfo, err error) ClosePopupsHandler() error - - DoAction(action MobileAction) error - DoValidation(check, assert, expected string, message ...string) error } type XTDriver struct { diff --git a/pkg/uixt/driver_action.go b/pkg/uixt/driver_action.go index 3e4e2b5a..d4d5956e 100644 --- a/pkg/uixt/driver_action.go +++ b/pkg/uixt/driver_action.go @@ -137,15 +137,15 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) { switch action.Method { case ACTION_AppInstall: - if appUrl, ok := action.Params.(string); ok { - if err = dExt.InstallByUrl(appUrl, + if app, ok := action.Params.(string); ok { + if err = dExt.GetDevice().Install(app, option.WithRetryTimes(action.MaxRetryTimes)); err != nil { return errors.Wrap(err, "failed to install app") } } case ACTION_AppUninstall: if packageName, ok := action.Params.(string); ok { - if err = dExt.Uninstall(packageName, action.GetOptions()...); err != nil { + if err = dExt.GetDevice().Uninstall(packageName); err != nil { return errors.Wrap(err, "failed to uninstall app") } } diff --git a/pkg/uixt/driver_install.go b/pkg/uixt/driver_install.go deleted file mode 100644 index 26820df0..00000000 --- a/pkg/uixt/driver_install.go +++ /dev/null @@ -1,103 +0,0 @@ -package uixt - -import ( - "fmt" - "os" - "path/filepath" - "time" - - "github.com/rs/zerolog/log" - - "github.com/httprunner/httprunner/v5/internal/builtin" - "github.com/httprunner/httprunner/v5/pkg/uixt/option" -) - -type InstallResult struct { - Result int `json:"result"` - ErrorCode int `json:"errorCode"` - ErrorMsg string `json:"errorMsg"` -} - -func (dExt *XTDriver) InstallByUrl(url string, opts ...option.InstallOption) error { - // 获取当前目录 - cwd, err := os.Getwd() - if err != nil { - return err - } - - // 将文件保存到当前目录 - appPath := filepath.Join(cwd, fmt.Sprint(time.Now().UnixNano())) // 替换为你想保存的文件名 - err = builtin.DownloadFile(appPath, url) - if err != nil { - log.Error().Err(err).Msg("download file failed") - return err - } - - err = dExt.Install(appPath, opts...) - if err != nil { - log.Error().Err(err).Msg("install app failed") - return err - } - return nil -} - -func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) error { - if _, ok := dExt.GetDevice().(*AndroidDevice); ok { - stopChan := make(chan struct{}) - go func() { - ticker := time.NewTicker(5 * time.Second) - defer ticker.Stop() - - for { - select { - case <-ticker.C: - actions := []TapTextAction{ - { - Text: "^.*无视风险安装$", - Options: []option.ActionOption{ - option.WithTapOffset(100, 0), - option.WithRegex(true), - option.WithIgnoreNotFoundError(true), - }, - }, - { - Text: "^已了解此应用未经检测.*", - Options: []option.ActionOption{ - option.WithTapOffset(-450, 0), - option.WithRegex(true), - option.WithIgnoreNotFoundError(true), - }, - }, - } - _ = dExt.TapByTexts(actions...) - - _ = dExt.TapByOCR( - "^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|授权本次安装|稍后提醒|继续安装|重新安装|安装)$", - option.WithRegex(true), - option.WithIgnoreNotFoundError(true), - ) - case <-stopChan: - log.Info().Msg("Ticker stopped") - return - } - } - }() - defer func() { - close(stopChan) - }() - } - - return dExt.GetDevice().Install(filePath, opts...) -} - -func (dExt *XTDriver) Uninstall(packageName string, opts ...option.ActionOption) error { - actionOptions := option.NewActionOptions(opts...) - err := dExt.GetDevice().Uninstall(packageName) - if err != nil { - log.Warn().Err(err).Msg("failed to uninstall") - } - if actionOptions.IgnoreNotFoundError { - return nil - } - return err -} diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 4b7c5c62..ce6e278b 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -255,14 +255,6 @@ func (hd *HDCDriver) Source(srcOpt ...option.SourceOption) (string, error) { return "", nil } -func (hd *HDCDriver) TapByText(text string, opts ...option.ActionOption) error { - return types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) TapByTexts(actions ...TapTextAction) error { - return types.ErrDriverNotImplemented -} - func (hd *HDCDriver) StartCaptureLog(identifier ...string) (err error) { return types.ErrDriverNotImplemented } diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index 2b0dde45..8655d28b 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -770,14 +770,6 @@ func (wd *WDADriver) Source(srcOpt ...option.SourceOption) (source string, err e return } -func (wd *WDADriver) TapByText(text string, opts ...option.ActionOption) error { - return types.ErrDriverNotImplemented -} - -func (wd *WDADriver) TapByTexts(actions ...TapTextAction) error { - return types.ErrDriverNotImplemented -} - func (wd *WDADriver) AccessibleSource() (source string, err error) { // [[FBRoute GET:@"/wda/accessibleSource"] respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)] // [[FBRoute GET:@"/wda/accessibleSource"].withoutSession