mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
refactor: move install options to pkg/uixt/options/install
This commit is contained in:
+3
-3
@@ -48,9 +48,9 @@ var installCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = driverExt.Install(args[0],
|
err = driverExt.Install(args[0],
|
||||||
uixt.WithReinstall(replace),
|
options.WithReinstall(replace),
|
||||||
uixt.WithDowngrade(downgrade),
|
options.WithDowngrade(downgrade),
|
||||||
uixt.WithGrantPermission(grant),
|
options.WithGrantPermission(grant),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
+2
-1
@@ -144,7 +144,8 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
|||||||
switch action.Method {
|
switch action.Method {
|
||||||
case ACTION_AppInstall:
|
case ACTION_AppInstall:
|
||||||
if appUrl, ok := action.Params.(string); ok {
|
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")
|
return errors.Wrap(err, "failed to install app")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,8 +301,8 @@ func (dev *AndroidDevice) Uninstall(packageName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) Install(apkPath string, opts ...InstallOption) error {
|
func (dev *AndroidDevice) Install(apkPath string, opts ...options.InstallOption) error {
|
||||||
installOpts := NewInstallOptions(opts...)
|
installOpts := options.NewInstallOptions(opts...)
|
||||||
brand, err := dev.d.Brand()
|
brand, err := dev.d.Brand()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ func (dev *HarmonyDevice) NewUSBDriver(opts ...options.DriverOption) (driver IWe
|
|||||||
return harmonyDriver, nil
|
return harmonyDriver, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dev *HarmonyDevice) Install(appPath string, opts ...InstallOption) error {
|
func (dev *HarmonyDevice) Install(appPath string, opts ...options.InstallOption) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-43
@@ -12,54 +12,13 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
|
"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 {
|
type InstallResult struct {
|
||||||
Result int `json:"result"`
|
Result int `json:"result"`
|
||||||
ErrorCode int `json:"errorCode"`
|
ErrorCode int `json:"errorCode"`
|
||||||
ErrorMsg string `json:"errorMsg"`
|
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()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,7 +41,7 @@ func (dExt *DriverExt) InstallByUrl(url string, opts ...InstallOption) error {
|
|||||||
return nil
|
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 {
|
if _, ok := dExt.Device.(*AndroidDevice); ok {
|
||||||
stopChan := make(chan struct{})
|
stopChan := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ type IDevice interface {
|
|||||||
// TODO: add ctx to NewDriver
|
// TODO: add ctx to NewDriver
|
||||||
NewDriver(...options.DriverOption) (driverExt *DriverExt, err error)
|
NewDriver(...options.DriverOption) (driverExt *DriverExt, err error)
|
||||||
|
|
||||||
Install(appPath string, opts ...InstallOption) error
|
Install(appPath string, opts ...options.InstallOption) error
|
||||||
Uninstall(packageName string) error
|
Uninstall(packageName string) error
|
||||||
|
|
||||||
GetPackageInfo(packageName string) (AppInfo, error)
|
GetPackageInfo(packageName string) (AppInfo, error)
|
||||||
|
|||||||
@@ -323,8 +323,8 @@ func (dev *IOSDevice) NewDriver(opts ...options.DriverOption) (driverExt *Driver
|
|||||||
return driverExt, nil
|
return driverExt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dev *IOSDevice) Install(appPath string, opts ...InstallOption) (err error) {
|
func (dev *IOSDevice) Install(appPath string, opts ...options.InstallOption) (err error) {
|
||||||
installOpts := NewInstallOptions(opts...)
|
installOpts := options.NewInstallOptions(opts...)
|
||||||
for i := 0; i <= installOpts.RetryTimes; i++ {
|
for i := 0; i <= installOpts.RetryTimes; i++ {
|
||||||
var conn *zipconduit.Connection
|
var conn *zipconduit.Connection
|
||||||
conn, err = zipconduit.New(dev.d)
|
conn, err = zipconduit.New(dev.d)
|
||||||
@@ -343,7 +343,7 @@ func (dev *IOSDevice) Install(appPath string, opts ...InstallOption) (err error)
|
|||||||
return err
|
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)
|
appPath, err := builtin.DownloadFileByUrl(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ func TestViaUSB(t *testing.T) {
|
|||||||
|
|
||||||
func TestInstall(t *testing.T) {
|
func TestInstall(t *testing.T) {
|
||||||
setup(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)
|
log.Error().Err(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -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