mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-26 01:51:29 +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",
|
||||
Version: "2022.12.03.0018",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var device uixt.Device
|
||||
var device uixt.IDevice
|
||||
var bundleID string
|
||||
if iosApp != "" {
|
||||
log.Info().Str("bundleID", iosApp).Msg("init ios device")
|
||||
|
||||
@@ -36,7 +36,7 @@ func convertTimeToSeconds(timeStr string) (int, error) {
|
||||
return seconds, nil
|
||||
}
|
||||
|
||||
func initIOSDevice(uuid string) uixt.Device {
|
||||
func initIOSDevice(uuid string) uixt.IDevice {
|
||||
perfOptions := []uixt.IOSPerfOption{}
|
||||
for _, p := range perf {
|
||||
switch p {
|
||||
@@ -71,7 +71,7 @@ func initIOSDevice(uuid string) uixt.Device {
|
||||
return device
|
||||
}
|
||||
|
||||
func initAndroidDevice(uuid string) uixt.Device {
|
||||
func initAndroidDevice(uuid string) uixt.IDevice {
|
||||
device, err := uixt.NewAndroidDevice(uixt.WithSerialNumber(uuid))
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to init android device")
|
||||
@@ -101,7 +101,7 @@ type WorldCupLive struct {
|
||||
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()
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to init driver")
|
||||
|
||||
@@ -209,7 +209,7 @@ func (dev *AndroidDevice) NewDriver(options ...DriverOption) (driverExt *DriverE
|
||||
option(driverOptions)
|
||||
}
|
||||
|
||||
var driver WebDriver
|
||||
var driver IWebDriver
|
||||
if dev.UIA2 || dev.LogOn {
|
||||
driver, err = dev.NewUSBDriver(driverOptions.capabilities)
|
||||
} 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.
|
||||
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)
|
||||
if err != nil {
|
||||
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.
|
||||
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)
|
||||
uiaDriver, err := NewUIADriver(capabilities, rawURL)
|
||||
if err != nil {
|
||||
@@ -301,7 +301,7 @@ func (dev *AndroidDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDr
|
||||
return uiaDriver, nil
|
||||
}
|
||||
|
||||
func (dev *AndroidDevice) NewAdbDriver() (driver WebDriver, err error) {
|
||||
func (dev *AndroidDevice) NewAdbDriver() (driver IWebDriver, err error) {
|
||||
adbDriver := NewAdbDriver()
|
||||
adbDriver.adbClient = dev.d
|
||||
adbDriver.logcat = dev.logcat
|
||||
|
||||
@@ -25,16 +25,10 @@ type DriverSession struct {
|
||||
}
|
||||
|
||||
func (d *DriverSession) addScreenResult(screenResult *ScreenResult) {
|
||||
if screenResult == nil {
|
||||
return
|
||||
}
|
||||
d.screenResults[screenResult.imagePath] = screenResult
|
||||
}
|
||||
|
||||
func (d *DriverSession) addRequestResult(driverResult *DriverResult) {
|
||||
if driverResult == nil {
|
||||
return
|
||||
}
|
||||
d.requests = append(d.requests, driverResult)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,15 @@ import (
|
||||
)
|
||||
|
||||
type DriverExt struct {
|
||||
Device Device
|
||||
Driver WebDriver
|
||||
Device IDevice
|
||||
Driver IWebDriver
|
||||
ImageService IImageService // used to extract image data
|
||||
|
||||
// funplugin
|
||||
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()
|
||||
for _, option := range options {
|
||||
option(driverOptions)
|
||||
|
||||
@@ -396,7 +396,7 @@ func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption
|
||||
return opt
|
||||
}
|
||||
|
||||
type Condition func(wd WebDriver) (bool, error)
|
||||
type Condition func(wd IWebDriver) (bool, error)
|
||||
|
||||
type Direction string
|
||||
|
||||
@@ -475,7 +475,7 @@ func WithDriverPlugin(plugin funplugin.IPlugin) DriverOption {
|
||||
}
|
||||
|
||||
// current implemeted device: IOSDevice, AndroidDevice
|
||||
type Device interface {
|
||||
type IDevice interface {
|
||||
Init() error // init android device
|
||||
UUID() string // ios udid or android serial
|
||||
LogEnabled() bool
|
||||
@@ -497,8 +497,8 @@ type ForegroundApp struct {
|
||||
Activity string
|
||||
}
|
||||
|
||||
// WebDriver defines methods supported by WebDriver drivers.
|
||||
type WebDriver interface {
|
||||
// IWebDriver defines methods supported by IWebDriver drivers.
|
||||
type IWebDriver interface {
|
||||
// NewSession starts a new session and returns the SessionInfo.
|
||||
NewSession(capabilities Capabilities) (SessionInfo, error)
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ func (dev *IOSDevice) NewDriver(options ...DriverOption) (driverExt *DriverExt,
|
||||
capabilities.WithDefaultAlertAction(AlertActionAccept)
|
||||
}
|
||||
|
||||
var driver WebDriver
|
||||
var driver IWebDriver
|
||||
if env.WDA_USB_DRIVER == "" {
|
||||
// default use http driver
|
||||
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.
|
||||
func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDriver, err error) {
|
||||
func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDriver, err error) {
|
||||
var localPort int
|
||||
localPort, err = strconv.Atoi(env.WDA_LOCAL_PORT)
|
||||
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.
|
||||
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).
|
||||
Str("udid", dev.UDID).Msg("init WDA USB driver")
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
var (
|
||||
bundleId = "com.apple.Preferences"
|
||||
driver WebDriver
|
||||
driver IWebDriver
|
||||
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" {
|
||||
device, err = uixt.NewIOSDevice(uixt.WithUDID(serial))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user