mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 07:51:25 +08:00
refactor: rename IDevice, IWebDriver
This commit is contained in:
@@ -15,7 +15,7 @@ var rootCmd = &cobra.Command{
|
|||||||
Short: "Monitor FIFA World Cup Live",
|
Short: "Monitor FIFA World Cup Live",
|
||||||
Version: "2022.12.03.0018",
|
Version: "2022.12.03.0018",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
var device uixt.Device
|
var device uixt.IDevice
|
||||||
var bundleID string
|
var bundleID string
|
||||||
if iosApp != "" {
|
if iosApp != "" {
|
||||||
log.Info().Str("bundleID", iosApp).Msg("init ios device")
|
log.Info().Str("bundleID", iosApp).Msg("init ios device")
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func convertTimeToSeconds(timeStr string) (int, error) {
|
|||||||
return seconds, nil
|
return seconds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func initIOSDevice(uuid string) uixt.Device {
|
func initIOSDevice(uuid string) uixt.IDevice {
|
||||||
perfOptions := []uixt.IOSPerfOption{}
|
perfOptions := []uixt.IOSPerfOption{}
|
||||||
for _, p := range perf {
|
for _, p := range perf {
|
||||||
switch p {
|
switch p {
|
||||||
@@ -71,7 +71,7 @@ func initIOSDevice(uuid string) uixt.Device {
|
|||||||
return device
|
return device
|
||||||
}
|
}
|
||||||
|
|
||||||
func initAndroidDevice(uuid string) uixt.Device {
|
func initAndroidDevice(uuid string) uixt.IDevice {
|
||||||
device, err := uixt.NewAndroidDevice(uixt.WithSerialNumber(uuid))
|
device, err := uixt.NewAndroidDevice(uixt.WithSerialNumber(uuid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("failed to init android device")
|
log.Fatal().Err(err).Msg("failed to init android device")
|
||||||
@@ -101,7 +101,7 @@ type WorldCupLive struct {
|
|||||||
PerfFile string `json:"perf"`
|
PerfFile string `json:"perf"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWorldCupLive(device uixt.Device, matchName, bundleID string, duration, interval int) *WorldCupLive {
|
func NewWorldCupLive(device uixt.IDevice, matchName, bundleID string, duration, interval int) *WorldCupLive {
|
||||||
driverExt, err := device.NewDriver()
|
driverExt, err := device.NewDriver()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("failed to init driver")
|
log.Fatal().Err(err).Msg("failed to init driver")
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ func (dev *AndroidDevice) NewDriver(options ...DriverOption) (driverExt *DriverE
|
|||||||
option(driverOptions)
|
option(driverOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
var driver WebDriver
|
var driver IWebDriver
|
||||||
if dev.UIA2 || dev.LogOn {
|
if dev.UIA2 || dev.LogOn {
|
||||||
driver, err = dev.NewUSBDriver(driverOptions.capabilities)
|
driver, err = dev.NewUSBDriver(driverOptions.capabilities)
|
||||||
} else if dev.STUB {
|
} else if dev.STUB {
|
||||||
@@ -237,7 +237,7 @@ func (dev *AndroidDevice) NewDriver(options ...DriverOption) (driverExt *DriverE
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewUSBDriver creates new client via USB connected device, this will also start a new session.
|
// NewUSBDriver creates new client via USB connected device, this will also start a new session.
|
||||||
func (dev *AndroidDevice) NewUSBDriver(capabilities Capabilities) (driver WebDriver, err error) {
|
func (dev *AndroidDevice) NewUSBDriver(capabilities Capabilities) (driver IWebDriver, err error) {
|
||||||
localPort, err := dev.d.Forward(UIA2ServerPort)
|
localPort, err := dev.d.Forward(UIA2ServerPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(code.AndroidDeviceConnectionError,
|
return nil, errors.Wrap(code.AndroidDeviceConnectionError,
|
||||||
@@ -289,7 +289,7 @@ func (dev *AndroidDevice) NewStubDriver(capabilities Capabilities) (driver *stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPDriver creates new remote HTTP client, this will also start a new session.
|
// NewHTTPDriver creates new remote HTTP client, this will also start a new session.
|
||||||
func (dev *AndroidDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDriver, err error) {
|
func (dev *AndroidDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDriver, err error) {
|
||||||
rawURL := fmt.Sprintf("http://%s:%d/wd/hub", dev.UIA2IP, dev.UIA2Port)
|
rawURL := fmt.Sprintf("http://%s:%d/wd/hub", dev.UIA2IP, dev.UIA2Port)
|
||||||
uiaDriver, err := NewUIADriver(capabilities, rawURL)
|
uiaDriver, err := NewUIADriver(capabilities, rawURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -301,7 +301,7 @@ func (dev *AndroidDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDr
|
|||||||
return uiaDriver, nil
|
return uiaDriver, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) NewAdbDriver() (driver WebDriver, err error) {
|
func (dev *AndroidDevice) NewAdbDriver() (driver IWebDriver, err error) {
|
||||||
adbDriver := NewAdbDriver()
|
adbDriver := NewAdbDriver()
|
||||||
adbDriver.adbClient = dev.d
|
adbDriver.adbClient = dev.d
|
||||||
adbDriver.logcat = dev.logcat
|
adbDriver.logcat = dev.logcat
|
||||||
|
|||||||
@@ -25,16 +25,10 @@ type DriverSession struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverSession) addScreenResult(screenResult *ScreenResult) {
|
func (d *DriverSession) addScreenResult(screenResult *ScreenResult) {
|
||||||
if screenResult == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.screenResults[screenResult.imagePath] = screenResult
|
d.screenResults[screenResult.imagePath] = screenResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverSession) addRequestResult(driverResult *DriverResult) {
|
func (d *DriverSession) addRequestResult(driverResult *DriverResult) {
|
||||||
if driverResult == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.requests = append(d.requests, driverResult)
|
d.requests = append(d.requests, driverResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DriverExt struct {
|
type DriverExt struct {
|
||||||
Device Device
|
Device IDevice
|
||||||
Driver WebDriver
|
Driver IWebDriver
|
||||||
ImageService IImageService // used to extract image data
|
ImageService IImageService // used to extract image data
|
||||||
|
|
||||||
// funplugin
|
// funplugin
|
||||||
plugin funplugin.IPlugin
|
plugin funplugin.IPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDriverExt(device Device, driver WebDriver, options ...DriverOption) (dExt *DriverExt, err error) {
|
func newDriverExt(device IDevice, driver IWebDriver, options ...DriverOption) (dExt *DriverExt, err error) {
|
||||||
driverOptions := NewDriverOptions()
|
driverOptions := NewDriverOptions()
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
option(driverOptions)
|
option(driverOptions)
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption
|
|||||||
return opt
|
return opt
|
||||||
}
|
}
|
||||||
|
|
||||||
type Condition func(wd WebDriver) (bool, error)
|
type Condition func(wd IWebDriver) (bool, error)
|
||||||
|
|
||||||
type Direction string
|
type Direction string
|
||||||
|
|
||||||
@@ -475,7 +475,7 @@ func WithDriverPlugin(plugin funplugin.IPlugin) DriverOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// current implemeted device: IOSDevice, AndroidDevice
|
// current implemeted device: IOSDevice, AndroidDevice
|
||||||
type Device interface {
|
type IDevice interface {
|
||||||
Init() error // init android device
|
Init() error // init android device
|
||||||
UUID() string // ios udid or android serial
|
UUID() string // ios udid or android serial
|
||||||
LogEnabled() bool
|
LogEnabled() bool
|
||||||
@@ -497,8 +497,8 @@ type ForegroundApp struct {
|
|||||||
Activity string
|
Activity string
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebDriver defines methods supported by WebDriver drivers.
|
// IWebDriver defines methods supported by IWebDriver drivers.
|
||||||
type WebDriver interface {
|
type IWebDriver interface {
|
||||||
// NewSession starts a new session and returns the SessionInfo.
|
// NewSession starts a new session and returns the SessionInfo.
|
||||||
NewSession(capabilities Capabilities) (SessionInfo, error)
|
NewSession(capabilities Capabilities) (SessionInfo, error)
|
||||||
|
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ func (dev *IOSDevice) NewDriver(options ...DriverOption) (driverExt *DriverExt,
|
|||||||
capabilities.WithDefaultAlertAction(AlertActionAccept)
|
capabilities.WithDefaultAlertAction(AlertActionAccept)
|
||||||
}
|
}
|
||||||
|
|
||||||
var driver WebDriver
|
var driver IWebDriver
|
||||||
if env.WDA_USB_DRIVER == "" {
|
if env.WDA_USB_DRIVER == "" {
|
||||||
// default use http driver
|
// default use http driver
|
||||||
driver, err = dev.NewHTTPDriver(capabilities)
|
driver, err = dev.NewHTTPDriver(capabilities)
|
||||||
@@ -608,7 +608,7 @@ func (dev *IOSDevice) pcapOpitons() (pcapOptions []gidevice.PcapOption) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPDriver creates new remote HTTP client, this will also start a new session.
|
// NewHTTPDriver creates new remote HTTP client, this will also start a new session.
|
||||||
func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDriver, err error) {
|
func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDriver, err error) {
|
||||||
var localPort int
|
var localPort int
|
||||||
localPort, err = strconv.Atoi(env.WDA_LOCAL_PORT)
|
localPort, err = strconv.Atoi(env.WDA_LOCAL_PORT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -677,7 +677,7 @@ func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewUSBDriver creates new client via USB connected device, this will also start a new session.
|
// NewUSBDriver creates new client via USB connected device, this will also start a new session.
|
||||||
func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver WebDriver, err error) {
|
func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver IWebDriver, err error) {
|
||||||
log.Info().Interface("capabilities", capabilities).
|
log.Info().Interface("capabilities", capabilities).
|
||||||
Str("udid", dev.UDID).Msg("init WDA USB driver")
|
Str("udid", dev.UDID).Msg("init WDA USB driver")
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
bundleId = "com.apple.Preferences"
|
bundleId = "com.apple.Preferences"
|
||||||
driver WebDriver
|
driver IWebDriver
|
||||||
iOSDriverExt *DriverExt
|
iOSDriverExt *DriverExt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func initUIClient(serial, osType string) (client *uixt.DriverExt, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var device uixt.Device
|
var device uixt.IDevice
|
||||||
if osType == "ios" {
|
if osType == "ios" {
|
||||||
device, err = uixt.NewIOSDevice(uixt.WithUDID(serial))
|
device, err = uixt.NewIOSDevice(uixt.WithUDID(serial))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user