mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-02 06:19:34 +08:00
refactor: move action options to pkg/uixt/options/action
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
|
||||
)
|
||||
|
||||
type InstallOptions struct {
|
||||
@@ -20,9 +21,9 @@ type InstallOptions struct {
|
||||
|
||||
type InstallOption func(o *InstallOptions)
|
||||
|
||||
func NewInstallOptions(options ...InstallOption) *InstallOptions {
|
||||
func NewInstallOptions(opts ...InstallOption) *InstallOptions {
|
||||
installOptions := &InstallOptions{}
|
||||
for _, option := range options {
|
||||
for _, option := range opts {
|
||||
option(installOptions)
|
||||
}
|
||||
return installOptions
|
||||
@@ -58,7 +59,7 @@ type InstallResult struct {
|
||||
ErrorMsg string `json:"errorMsg"`
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) InstallByUrl(url string, options ...InstallOption) error {
|
||||
func (dExt *DriverExt) InstallByUrl(url string, opts ...InstallOption) error {
|
||||
// 获取当前目录
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -73,7 +74,7 @@ func (dExt *DriverExt) InstallByUrl(url string, options ...InstallOption) error
|
||||
return err
|
||||
}
|
||||
|
||||
err = dExt.Install(appPath, options...)
|
||||
err = dExt.Install(appPath, opts...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("install app failed")
|
||||
return err
|
||||
@@ -81,7 +82,7 @@ func (dExt *DriverExt) InstallByUrl(url string, options ...InstallOption) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Install(filePath string, options ...InstallOption) error {
|
||||
func (dExt *DriverExt) Install(filePath string, opts ...InstallOption) error {
|
||||
if _, ok := dExt.Device.(*AndroidDevice); ok {
|
||||
stopChan := make(chan struct{})
|
||||
go func() {
|
||||
@@ -93,19 +94,28 @@ func (dExt *DriverExt) Install(filePath string, options ...InstallOption) error
|
||||
case <-ticker.C:
|
||||
actions := []TapTextAction{
|
||||
{
|
||||
Text: "^.*无视风险安装$",
|
||||
Options: []ActionOption{WithTapOffset(100, 0), WithRegex(true), WithIgnoreNotFoundError(true)},
|
||||
Text: "^.*无视风险安装$",
|
||||
Options: []options.ActionOption{
|
||||
options.WithTapOffset(100, 0),
|
||||
options.WithRegex(true),
|
||||
options.WithIgnoreNotFoundError(true),
|
||||
},
|
||||
},
|
||||
{
|
||||
Text: "^已了解此应用未经检测.*",
|
||||
Options: []ActionOption{WithTapOffset(-450, 0), WithRegex(true), WithIgnoreNotFoundError(true)},
|
||||
Text: "^已了解此应用未经检测.*",
|
||||
Options: []options.ActionOption{
|
||||
options.WithTapOffset(-450, 0),
|
||||
options.WithRegex(true),
|
||||
options.WithIgnoreNotFoundError(true),
|
||||
},
|
||||
},
|
||||
}
|
||||
_ = dExt.Driver.TapByTexts(actions...)
|
||||
|
||||
_ = dExt.TapByOCR(
|
||||
"^(.*无视风险安装|确定|继续|完成|点击继续安装|继续安装旧版本|替换|授权本次安装|稍后提醒|继续安装|重新安装|安装)$",
|
||||
WithRegex(true), WithIgnoreNotFoundError(true),
|
||||
options.WithRegex(true),
|
||||
options.WithIgnoreNotFoundError(true),
|
||||
)
|
||||
case <-stopChan:
|
||||
log.Info().Msg("Ticker stopped")
|
||||
@@ -118,11 +128,11 @@ func (dExt *DriverExt) Install(filePath string, options ...InstallOption) error
|
||||
}()
|
||||
}
|
||||
|
||||
return dExt.Device.Install(filePath, options...)
|
||||
return dExt.Device.Install(filePath, opts...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Uninstall(packageName string, options ...ActionOption) error {
|
||||
actionOptions := NewActionOptions(options...)
|
||||
func (dExt *DriverExt) Uninstall(packageName string, opts ...options.ActionOption) error {
|
||||
actionOptions := options.NewActionOptions(opts...)
|
||||
err := dExt.Device.Uninstall(packageName)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("failed to uninstall")
|
||||
|
||||
Reference in New Issue
Block a user