mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
refactor: device Install interface
This commit is contained in:
+21
-11
@@ -15,7 +15,7 @@ type InstallOptions struct {
|
||||
Reinstall bool
|
||||
GrantPermission bool
|
||||
Downgrade bool
|
||||
RetryTime int
|
||||
RetryTimes int
|
||||
}
|
||||
|
||||
type InstallOption func(o *InstallOptions)
|
||||
@@ -46,9 +46,9 @@ func WithDowngrade(downgrade bool) InstallOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithRetryTime(retryTime int) InstallOption {
|
||||
func WithRetryTimes(retryTimes int) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.RetryTime = retryTime
|
||||
o.RetryTimes = retryTimes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ type InstallResult struct {
|
||||
ErrorMsg string `json:"errorMsg"`
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) InstallByUrl(url string, opts *InstallOptions) error {
|
||||
func (dExt *DriverExt) InstallByUrl(url string, options ...InstallOption) error {
|
||||
// 获取当前目录
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -73,7 +73,7 @@ func (dExt *DriverExt) InstallByUrl(url string, opts *InstallOptions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dExt.Install(appPath, opts)
|
||||
err = dExt.Install(appPath, options...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("install app failed")
|
||||
return err
|
||||
@@ -81,7 +81,7 @@ func (dExt *DriverExt) InstallByUrl(url string, opts *InstallOptions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Install(filePath string, opts *InstallOptions) error {
|
||||
func (dExt *DriverExt) Install(filePath string, options ...InstallOption) error {
|
||||
if _, ok := dExt.Device.(*AndroidDevice); ok {
|
||||
stopChan := make(chan struct{})
|
||||
go func() {
|
||||
@@ -92,13 +92,23 @@ func (dExt *DriverExt) Install(filePath string, opts *InstallOptions) error {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
actions := []TapTextAction{
|
||||
{Text: "^.*无视风险安装$", Options: []ActionOption{WithTapOffset(100, 0), WithRegex(true), WithIgnoreNotFoundError(true)}},
|
||||
{Text: "^已了解此应用未经检测.*", Options: []ActionOption{WithTapOffset(-450, 0), WithRegex(true), WithIgnoreNotFoundError(true)}},
|
||||
{
|
||||
Text: "^.*无视风险安装$",
|
||||
Options: []ActionOption{WithTapOffset(100, 0), WithRegex(true), WithIgnoreNotFoundError(true)},
|
||||
},
|
||||
{
|
||||
Text: "^已了解此应用未经检测.*",
|
||||
Options: []ActionOption{WithTapOffset(-450, 0), WithRegex(true), WithIgnoreNotFoundError(true)},
|
||||
},
|
||||
}
|
||||
_ = dExt.Driver.TapByTexts(actions...)
|
||||
_ = dExt.TapByOCR("^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|安装|授权本次安装|继续安装|重新安装)$", WithRegex(true), WithIgnoreNotFoundError(true))
|
||||
|
||||
_ = dExt.TapByOCR(
|
||||
"^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|安装|授权本次安装|继续安装|重新安装)$",
|
||||
WithRegex(true), WithIgnoreNotFoundError(true),
|
||||
)
|
||||
case <-stopChan:
|
||||
fmt.Println("Ticker stopped")
|
||||
log.Info().Msg("Ticker stopped")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -108,7 +118,7 @@ func (dExt *DriverExt) Install(filePath string, opts *InstallOptions) error {
|
||||
}()
|
||||
}
|
||||
|
||||
return dExt.Device.Install(filePath, opts)
|
||||
return dExt.Device.Install(filePath, options...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Uninstall(packageName string, options ...ActionOption) error {
|
||||
|
||||
Reference in New Issue
Block a user