mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-10 17:43:00 +08:00
refactor: move install options to pkg/uixt/options/install
This commit is contained in:
@@ -48,9 +48,9 @@ var installCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
err = driverExt.Install(args[0],
|
||||
uixt.WithReinstall(replace),
|
||||
uixt.WithDowngrade(downgrade),
|
||||
uixt.WithGrantPermission(grant),
|
||||
options.WithReinstall(replace),
|
||||
options.WithDowngrade(downgrade),
|
||||
options.WithGrantPermission(grant),
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
@@ -144,7 +144,8 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
||||
switch action.Method {
|
||||
case ACTION_AppInstall:
|
||||
if appUrl, ok := action.Params.(string); ok {
|
||||
if err = dExt.InstallByUrl(appUrl, WithRetryTimes(action.MaxRetryTimes)); err != nil {
|
||||
if err = dExt.InstallByUrl(appUrl,
|
||||
options.WithRetryTimes(action.MaxRetryTimes)); err != nil {
|
||||
return errors.Wrap(err, "failed to install app")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,8 +301,8 @@ func (dev *AndroidDevice) Uninstall(packageName string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (dev *AndroidDevice) Install(apkPath string, opts ...InstallOption) error {
|
||||
installOpts := NewInstallOptions(opts...)
|
||||
func (dev *AndroidDevice) Install(apkPath string, opts ...options.InstallOption) error {
|
||||
installOpts := options.NewInstallOptions(opts...)
|
||||
brand, err := dev.d.Brand()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -120,7 +120,7 @@ func (dev *HarmonyDevice) NewUSBDriver(opts ...options.DriverOption) (driver IWe
|
||||
return harmonyDriver, nil
|
||||
}
|
||||
|
||||
func (dev *HarmonyDevice) Install(appPath string, opts ...InstallOption) error {
|
||||
func (dev *HarmonyDevice) Install(appPath string, opts ...options.InstallOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,54 +12,13 @@ import (
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
|
||||
)
|
||||
|
||||
type InstallOptions struct {
|
||||
Reinstall bool
|
||||
GrantPermission bool
|
||||
Downgrade bool
|
||||
RetryTimes int
|
||||
}
|
||||
|
||||
type InstallOption func(o *InstallOptions)
|
||||
|
||||
func NewInstallOptions(opts ...InstallOption) *InstallOptions {
|
||||
installOptions := &InstallOptions{}
|
||||
for _, option := range opts {
|
||||
option(installOptions)
|
||||
}
|
||||
return installOptions
|
||||
}
|
||||
|
||||
func WithReinstall(reinstall bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.Reinstall = reinstall
|
||||
}
|
||||
}
|
||||
|
||||
func WithGrantPermission(grantPermission bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.GrantPermission = grantPermission
|
||||
}
|
||||
}
|
||||
|
||||
func WithDowngrade(downgrade bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.Downgrade = downgrade
|
||||
}
|
||||
}
|
||||
|
||||
func WithRetryTimes(retryTimes int) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.RetryTimes = retryTimes
|
||||
}
|
||||
}
|
||||
|
||||
type InstallResult struct {
|
||||
Result int `json:"result"`
|
||||
ErrorCode int `json:"errorCode"`
|
||||
ErrorMsg string `json:"errorMsg"`
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) InstallByUrl(url string, opts ...InstallOption) error {
|
||||
func (dExt *DriverExt) InstallByUrl(url string, opts ...options.InstallOption) error {
|
||||
// 获取当前目录
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -82,7 +41,7 @@ func (dExt *DriverExt) InstallByUrl(url string, opts ...InstallOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Install(filePath string, opts ...InstallOption) error {
|
||||
func (dExt *DriverExt) Install(filePath string, opts ...options.InstallOption) error {
|
||||
if _, ok := dExt.Device.(*AndroidDevice); ok {
|
||||
stopChan := make(chan struct{})
|
||||
go func() {
|
||||
|
||||
@@ -359,7 +359,7 @@ type IDevice interface {
|
||||
// TODO: add ctx to NewDriver
|
||||
NewDriver(...options.DriverOption) (driverExt *DriverExt, err error)
|
||||
|
||||
Install(appPath string, opts ...InstallOption) error
|
||||
Install(appPath string, opts ...options.InstallOption) error
|
||||
Uninstall(packageName string) error
|
||||
|
||||
GetPackageInfo(packageName string) (AppInfo, error)
|
||||
|
||||
@@ -323,8 +323,8 @@ func (dev *IOSDevice) NewDriver(opts ...options.DriverOption) (driverExt *Driver
|
||||
return driverExt, nil
|
||||
}
|
||||
|
||||
func (dev *IOSDevice) Install(appPath string, opts ...InstallOption) (err error) {
|
||||
installOpts := NewInstallOptions(opts...)
|
||||
func (dev *IOSDevice) Install(appPath string, opts ...options.InstallOption) (err error) {
|
||||
installOpts := options.NewInstallOptions(opts...)
|
||||
for i := 0; i <= installOpts.RetryTimes; i++ {
|
||||
var conn *zipconduit.Connection
|
||||
conn, err = zipconduit.New(dev.d)
|
||||
@@ -343,7 +343,7 @@ func (dev *IOSDevice) Install(appPath string, opts ...InstallOption) (err error)
|
||||
return err
|
||||
}
|
||||
|
||||
func (dev *IOSDevice) InstallByUrl(url string, opts ...InstallOption) (err error) {
|
||||
func (dev *IOSDevice) InstallByUrl(url string, opts ...options.InstallOption) (err error) {
|
||||
appPath, err := builtin.DownloadFileByUrl(url)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -45,7 +45,8 @@ func TestViaUSB(t *testing.T) {
|
||||
|
||||
func TestInstall(t *testing.T) {
|
||||
setup(t)
|
||||
err := iOSDriverExt.Install("/Users/bytedance/Downloads/com.yueyou.cyreader_1387717110_7.54.20.ipa", WithRetryTimes(5))
|
||||
err := iOSDriverExt.Install("xxx.ipa",
|
||||
options.WithRetryTimes(5))
|
||||
log.Error().Err(err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
42
pkg/uixt/options/install.go
Normal file
42
pkg/uixt/options/install.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package options
|
||||
|
||||
type InstallOptions struct {
|
||||
Reinstall bool
|
||||
GrantPermission bool
|
||||
Downgrade bool
|
||||
RetryTimes int
|
||||
}
|
||||
|
||||
type InstallOption func(o *InstallOptions)
|
||||
|
||||
func NewInstallOptions(opts ...InstallOption) *InstallOptions {
|
||||
installOptions := &InstallOptions{}
|
||||
for _, option := range opts {
|
||||
option(installOptions)
|
||||
}
|
||||
return installOptions
|
||||
}
|
||||
|
||||
func WithReinstall(reinstall bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.Reinstall = reinstall
|
||||
}
|
||||
}
|
||||
|
||||
func WithGrantPermission(grantPermission bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.GrantPermission = grantPermission
|
||||
}
|
||||
}
|
||||
|
||||
func WithDowngrade(downgrade bool) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.Downgrade = downgrade
|
||||
}
|
||||
}
|
||||
|
||||
func WithRetryTimes(retryTimes int) InstallOption {
|
||||
return func(o *InstallOptions) {
|
||||
o.RetryTimes = retryTimes
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user