From 94d3cb785c71632ba0ca94b1586e024a7b8892e5 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 6 Feb 2025 20:08:51 +0800 Subject: [PATCH] refactor: move files --- internal/version/VERSION | 2 +- pkg/uixt/android_device.go | 2 +- pkg/uixt/android_driver_adb.go | 4 +- pkg/uixt/android_driver_stub.go | 2 +- pkg/uixt/android_driver_uia2.go | 4 +- pkg/uixt/device.go | 311 -------------------------------- pkg/uixt/driver.go | 2 +- pkg/uixt/driver_action.go | 2 +- pkg/uixt/harmony_driver_hdc.go | 2 +- pkg/uixt/ios_driver_stub.go | 2 +- pkg/uixt/ios_driver_wda.go | 2 +- pkg/uixt/option/source.go | 54 ++++++ pkg/uixt/types.go | 260 ++++++++++++++++++++++++++ server/source.go | 3 +- 14 files changed, 327 insertions(+), 325 deletions(-) create mode 100644 pkg/uixt/option/source.go create mode 100644 pkg/uixt/types.go diff --git a/internal/version/VERSION b/internal/version/VERSION index 524673de..7c7ca148 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502061953 +v5.0.0+2502062008 diff --git a/pkg/uixt/android_device.go b/pkg/uixt/android_device.go index 37838bdb..5c60a063 100644 --- a/pkg/uixt/android_device.go +++ b/pkg/uixt/android_device.go @@ -79,7 +79,7 @@ func NewAndroidDevice(opts ...option.AndroidDeviceOption) (device *AndroidDevice device = &AndroidDevice{ AndroidDeviceConfig: androidOptions, d: dev, - logcat: NewAdbLogcat(androidOptions.SerialNumber), + logcat: NewAdbLogcat(device.SerialNumber), } evalToolRaw, err := evalite.ReadFile("evalite") diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index 9b33dba9..af7bc717 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -656,7 +656,7 @@ func (ad *adbDriver) Screenshot() (raw *bytes.Buffer, err error) { return bytes.NewBuffer([]byte(resp)), nil } -func (ad *adbDriver) Source(srcOpt ...SourceOption) (source string, err error) { +func (ad *adbDriver) Source(srcOpt ...option.SourceOption) (source string, err error) { _, err = ad.runShellCommand("rm", "-rf", "/sdcard/window_dump.xml") if err != nil { return @@ -681,7 +681,7 @@ func (ad *adbDriver) LogoutNoneUI(packageName string) error { return errDriverNotImplemented } -func (ad *adbDriver) sourceTree(srcOpt ...SourceOption) (sourceTree *Hierarchy, err error) { +func (ad *adbDriver) sourceTree(srcOpt ...option.SourceOption) (sourceTree *Hierarchy, err error) { source, err := ad.Source() if err != nil { return diff --git a/pkg/uixt/android_driver_stub.go b/pkg/uixt/android_driver_stub.go index 88cfb329..eb564966 100644 --- a/pkg/uixt/android_driver_stub.go +++ b/pkg/uixt/android_driver_stub.go @@ -163,7 +163,7 @@ func (sad *stubAndroidDriver) Status() (DeviceStatus, error) { return DeviceStatus{}, nil } -func (sad *stubAndroidDriver) Source(srcOpt ...SourceOption) (source string, err error) { +func (sad *stubAndroidDriver) Source(srcOpt ...option.SourceOption) (source string, err error) { app, err := sad.GetForegroundApp() if err != nil { return "", err diff --git a/pkg/uixt/android_driver_uia2.go b/pkg/uixt/android_driver_uia2.go index a3181ae4..591c12be 100644 --- a/pkg/uixt/android_driver_uia2.go +++ b/pkg/uixt/android_driver_uia2.go @@ -597,7 +597,7 @@ func (ud *uiaDriver) Screenshot() (raw *bytes.Buffer, err error) { return ud.adbDriver.Screenshot() } -func (ud *uiaDriver) Source(srcOpt ...SourceOption) (source string, err error) { +func (ud *uiaDriver) Source(srcOpt ...option.SourceOption) (source string, err error) { // register(getHandler, new Source("/wd/hub/session/:sessionId/source")) var rawResp rawResponse if rawResp, err = ud.httpGET("/session", ud.session.ID, "source"); err != nil { @@ -612,7 +612,7 @@ func (ud *uiaDriver) Source(srcOpt ...SourceOption) (source string, err error) { return } -func (ud *uiaDriver) sourceTree(srcOpt ...SourceOption) (sourceTree *Hierarchy, err error) { +func (ud *uiaDriver) sourceTree(srcOpt ...option.SourceOption) (sourceTree *Hierarchy, err error) { source, err := ud.Source() if err != nil { return diff --git a/pkg/uixt/device.go b/pkg/uixt/device.go index 279af1eb..33a11d0f 100644 --- a/pkg/uixt/device.go +++ b/pkg/uixt/device.go @@ -1,320 +1,9 @@ package uixt import ( - "math" - "strings" - "github.com/httprunner/httprunner/v5/pkg/uixt/option" ) -type DeviceStatus struct { - Message string `json:"message"` - State string `json:"state"` - OS struct { - TestmanagerdVersion int `json:"testmanagerdVersion"` - Name string `json:"name"` - SdkVersion string `json:"sdkVersion"` - Version string `json:"version"` - } `json:"os"` - IOS struct { - IP string `json:"ip"` - SimulatorVersion string `json:"simulatorVersion"` - } `json:"ios"` - Ready bool `json:"ready"` - Build struct { - Time string `json:"time"` - ProductBundleIdentifier string `json:"productBundleIdentifier"` - } `json:"build"` -} - -type DeviceInfo struct { - TimeZone string `json:"timeZone"` - CurrentLocale string `json:"currentLocale"` - Model string `json:"model"` - UUID string `json:"uuid"` - UserInterfaceIdiom int `json:"userInterfaceIdiom"` - UserInterfaceStyle string `json:"userInterfaceStyle"` - Name string `json:"name"` - IsSimulator bool `json:"isSimulator"` - ThermalState int `json:"thermalState"` - // ANDROID_ID A 64-bit number (as a hex string) that is uniquely generated when the user - // first sets up the device and should remain constant for the lifetime of the user's device. The value - // may change if a factory reset is performed on the device. - AndroidID string `json:"androidId"` - // Build.MANUFACTURER value - Manufacturer string `json:"manufacturer"` - // Build.BRAND value - Brand string `json:"brand"` - // Current running OS's API VERSION - APIVersion string `json:"apiVersion"` - // The current version string, for example "1.0" or "3.4b5" - PlatformVersion string `json:"platformVersion"` - // the name of the current celluar network carrier - CarrierName string `json:"carrierName"` - // the real size of the default display - RealDisplaySize string `json:"realDisplaySize"` - // The logical density of the display in Density Independent Pixel units. - DisplayDensity int `json:"displayDensity"` - // available networks - Networks []networkInfo `json:"networks"` - // current system locale - Locale string `json:"locale"` - Bluetooth struct { - State string `json:"state"` - } `json:"bluetooth"` -} - -type networkCapabilities struct { - TransportTypes string `json:"transportTypes"` - NetworkCapabilities string `json:"networkCapabilities"` - LinkUpstreamBandwidthKbps int `json:"linkUpstreamBandwidthKbps"` - LinkDownBandwidthKbps int `json:"linkDownBandwidthKbps"` - SignalStrength int `json:"signalStrength"` - SSID string `json:"SSID"` -} - -type networkInfo struct { - Type int `json:"type"` - TypeName string `json:"typeName"` - Subtype int `json:"subtype"` - SubtypeName string `json:"subtypeName"` - IsConnected bool `json:"isConnected"` - DetailedState string `json:"detailedState"` - State string `json:"state"` - ExtraInfo string `json:"extraInfo"` - IsAvailable bool `json:"isAvailable"` - IsRoaming bool `json:"isRoaming"` - IsFailover bool `json:"isFailover"` - Capabilities networkCapabilities `json:"capabilities"` -} - -type Location struct { - AuthorizationStatus int `json:"authorizationStatus"` - Longitude float64 `json:"longitude"` - Latitude float64 `json:"latitude"` - Altitude float64 `json:"altitude"` -} - -type BatteryInfo struct { - // Battery level in range [0.0, 1.0], where 1.0 means 100% charge. - Level float64 `json:"level"` - - // Battery state ( 1: on battery, discharging; 2: plugged in, less than 100%, 3: plugged in, at 100% ) - State BatteryState `json:"state"` - - Status BatteryStatus `json:"status"` -} - -type BatteryState int - -const ( - _ = iota - BatteryStateUnplugged BatteryState = iota // on battery, discharging - BatteryStateCharging // plugged in, less than 100% - BatteryStateFull // plugged in, at 100% -) - -func (v BatteryState) String() string { - switch v { - case BatteryStateUnplugged: - return "On battery, discharging" - case BatteryStateCharging: - return "Plugged in, less than 100%" - case BatteryStateFull: - return "Plugged in, at 100%" - default: - return "UNKNOWN" - } -} - -type Size struct { - Width int `json:"width"` - Height int `json:"height"` -} - -func (s Size) IsNil() bool { - return s.Width == 0 && s.Height == 0 -} - -type Screen struct { - StatusBarSize Size `json:"statusBarSize"` - Scale float64 `json:"scale"` -} - -type AppInfo struct { - Name string `json:"name,omitempty"` - AppBaseInfo -} - -type WindowInfo struct { - PackageName string `json:"packageName,omitempty"` - Activity string `json:"activity,omitempty"` -} - -type AppBaseInfo struct { - Pid int `json:"pid,omitempty"` - BundleId string `json:"bundleId,omitempty"` // ios package name - ViewController string `json:"viewController,omitempty"` // ios view controller - PackageName string `json:"packageName,omitempty"` // android package name - Activity string `json:"activity,omitempty"` // android activity - VersionName string `json:"versionName,omitempty"` - VersionCode interface{} `json:"versionCode,omitempty"` // int or string - AppName string `json:"appName,omitempty"` - AppPath string `json:"appPath,omitempty"` - AppMD5 string `json:"appMD5,omitempty"` - // AppIcon string `json:"appIcon,omitempty"` -} - -type AppState int - -const ( - AppStateNotRunning AppState = 1 << iota - AppStateRunningBack - AppStateRunningFront -) - -func (v AppState) String() string { - switch v { - case AppStateNotRunning: - return "Not Running" - case AppStateRunningBack: - return "Running (Back)" - case AppStateRunningFront: - return "Running (Front)" - default: - return "UNKNOWN" - } -} - -// PasteboardType The type of the item on the pasteboard. -type PasteboardType string - -const ( - PasteboardTypePlaintext PasteboardType = "plaintext" - PasteboardTypeImage PasteboardType = "image" - PasteboardTypeUrl PasteboardType = "url" -) - -const ( - TextBackspace string = "\u0008" - TextDelete string = "\u007F" -) - -// DeviceButton A physical button on an iOS device. -type DeviceButton string - -const ( - DeviceButtonHome DeviceButton = "home" - DeviceButtonVolumeUp DeviceButton = "volumeUp" - DeviceButtonVolumeDown DeviceButton = "volumeDown" -) - -type NotificationType string - -const ( - NotificationTypePlain NotificationType = "plain" - NotificationTypeDarwin NotificationType = "darwin" -) - -type Orientation string - -const ( - // OrientationPortrait Device oriented vertically, home button on the bottom - OrientationPortrait Orientation = "PORTRAIT" - - // OrientationPortraitUpsideDown Device oriented vertically, home button on the top - OrientationPortraitUpsideDown Orientation = "UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN" - - // OrientationLandscapeLeft Device oriented horizontally, home button on the right - OrientationLandscapeLeft Orientation = "LANDSCAPE" - - // OrientationLandscapeRight Device oriented horizontally, home button on the left - OrientationLandscapeRight Orientation = "UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT" -) - -type Rotation struct { - X int `json:"x"` - Y int `json:"y"` - Z int `json:"z"` -} - -// SourceOption Configure the format or attribute of the Source -type SourceOption map[string]interface{} - -func NewSourceOption() SourceOption { - return make(SourceOption) -} - -// WithFormatAsJson Application elements tree in form of json string -func (opt SourceOption) WithFormatAsJson() SourceOption { - opt["format"] = "json" - return opt -} - -func (opt SourceOption) WithProcessName(processName string) SourceOption { - opt["processName"] = processName - return opt -} - -// WithFormatAsXml Application elements tree in form of xml string -func (opt SourceOption) WithFormatAsXml() SourceOption { - opt["format"] = "xml" - return opt -} - -// WithFormatAsDescription Application elements tree in form of internal XCTest debugDescription string -func (opt SourceOption) WithFormatAsDescription() SourceOption { - opt["format"] = "description" - return opt -} - -// WithScope Allows to provide XML scope. -// -// only `xml` is supported. -func (opt SourceOption) WithScope(scope string) SourceOption { - if vFormat, ok := opt["format"]; ok && vFormat != "xml" { - return opt - } - opt["scope"] = scope - return opt -} - -// WithExcludedAttributes Excludes the given attribute names. -// only `xml` is supported. -func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption { - if vFormat, ok := opt["format"]; ok && vFormat != "xml" { - return opt - } - opt["excluded_attributes"] = strings.Join(attributes, ",") - return opt -} - -type Condition func(wd IWebDriver) (bool, error) - -type Direction string - -const ( - DirectionUp Direction = "up" - DirectionDown Direction = "down" - DirectionLeft Direction = "left" - DirectionRight Direction = "right" -) - -type Point struct { - X int `json:"x"` // upper left X coordinate of selected element - Y int `json:"y"` // upper left Y coordinate of selected element -} - -type PointF struct { - X float64 `json:"x"` - Y float64 `json:"y"` -} - -func (p PointF) IsIdentical(p2 PointF) bool { - // set the coordinate precision to 1 pixel - return math.Abs(p.X-p2.X) < 1 && math.Abs(p.Y-p2.Y) < 1 -} - // current implemeted device: IOSDevice, AndroidDevice, HarmonyDevice type IDevice interface { Init() error // init android device diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index d8f9d480..ebe18cda 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -137,7 +137,7 @@ type IWebDriver interface { Screenshot() (*bytes.Buffer, error) // Source Return application elements tree - Source(srcOpt ...SourceOption) (string, error) + Source(srcOpt ...option.SourceOption) (string, error) LoginNoneUI(packageName, phoneNumber string, captcha, password string) (info AppLoginInfo, err error) LogoutNoneUI(packageName string) error diff --git a/pkg/uixt/driver_action.go b/pkg/uixt/driver_action.go index 0ed8aed1..6d5a9aad 100644 --- a/pkg/uixt/driver_action.go +++ b/pkg/uixt/driver_action.go @@ -220,7 +220,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) { } case ACTION_GetSource: if packageName, ok := action.Params.(string); ok { - source := NewSourceOption().WithProcessName(packageName) + source := option.NewSourceOption().WithProcessName(packageName) _, err = dExt.Driver.Source(source) if err != nil { return errors.Wrap(err, "failed to set ime") diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 521781a7..0755eae6 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -274,7 +274,7 @@ func (hd *hdcDriver) Screenshot() (*bytes.Buffer, error) { return bytes.NewBuffer(raw), nil } -func (hd *hdcDriver) Source(srcOpt ...SourceOption) (string, error) { +func (hd *hdcDriver) Source(srcOpt ...option.SourceOption) (string, error) { return "", nil } diff --git a/pkg/uixt/ios_driver_stub.go b/pkg/uixt/ios_driver_stub.go index 1d69de46..327933b9 100644 --- a/pkg/uixt/ios_driver_stub.go +++ b/pkg/uixt/ios_driver_stub.go @@ -450,7 +450,7 @@ func (s *stubIOSDriver) GetDriverResults() []*DriverResult { return s.wdaDriver.GetDriverResults() } -func (s *stubIOSDriver) Source(srcOpt ...SourceOption) (string, error) { +func (s *stubIOSDriver) Source(srcOpt ...option.SourceOption) (string, error) { resp, err := s.DriverClient.Request(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{}) if err != nil { return "", err diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index db74b763..b664ab84 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -792,7 +792,7 @@ func (wd *wdaDriver) Screenshot() (raw *bytes.Buffer, err error) { return } -func (wd *wdaDriver) Source(srcOpt ...SourceOption) (source string, err error) { +func (wd *wdaDriver) Source(srcOpt ...option.SourceOption) (source string, err error) { // [[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)] // [[FBRoute GET:@"/source"].withoutSession tmp, _ := url.Parse(wd.concatURL(nil, "/session", wd.session.ID)) diff --git a/pkg/uixt/option/source.go b/pkg/uixt/option/source.go new file mode 100644 index 00000000..0cc79515 --- /dev/null +++ b/pkg/uixt/option/source.go @@ -0,0 +1,54 @@ +package option + +import "strings" + +// SourceOption Configure the format or attribute of the Source +type SourceOption map[string]interface{} + +func NewSourceOption() SourceOption { + return make(SourceOption) +} + +// WithFormatAsJson Application elements tree in form of json string +func (opt SourceOption) WithFormatAsJson() SourceOption { + opt["format"] = "json" + return opt +} + +func (opt SourceOption) WithProcessName(processName string) SourceOption { + opt["processName"] = processName + return opt +} + +// WithFormatAsXml Application elements tree in form of xml string +func (opt SourceOption) WithFormatAsXml() SourceOption { + opt["format"] = "xml" + return opt +} + +// WithFormatAsDescription Application elements tree in form of internal XCTest debugDescription string +func (opt SourceOption) WithFormatAsDescription() SourceOption { + opt["format"] = "description" + return opt +} + +// WithScope Allows to provide XML scope. +// +// only `xml` is supported. +func (opt SourceOption) WithScope(scope string) SourceOption { + if vFormat, ok := opt["format"]; ok && vFormat != "xml" { + return opt + } + opt["scope"] = scope + return opt +} + +// WithExcludedAttributes Excludes the given attribute names. +// only `xml` is supported. +func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption { + if vFormat, ok := opt["format"]; ok && vFormat != "xml" { + return opt + } + opt["excluded_attributes"] = strings.Join(attributes, ",") + return opt +} diff --git a/pkg/uixt/types.go b/pkg/uixt/types.go new file mode 100644 index 00000000..4db580dd --- /dev/null +++ b/pkg/uixt/types.go @@ -0,0 +1,260 @@ +package uixt + +import "math" + +type DeviceStatus struct { + Message string `json:"message"` + State string `json:"state"` + OS struct { + TestmanagerdVersion int `json:"testmanagerdVersion"` + Name string `json:"name"` + SdkVersion string `json:"sdkVersion"` + Version string `json:"version"` + } `json:"os"` + IOS struct { + IP string `json:"ip"` + SimulatorVersion string `json:"simulatorVersion"` + } `json:"ios"` + Ready bool `json:"ready"` + Build struct { + Time string `json:"time"` + ProductBundleIdentifier string `json:"productBundleIdentifier"` + } `json:"build"` +} + +type DeviceInfo struct { + TimeZone string `json:"timeZone"` + CurrentLocale string `json:"currentLocale"` + Model string `json:"model"` + UUID string `json:"uuid"` + UserInterfaceIdiom int `json:"userInterfaceIdiom"` + UserInterfaceStyle string `json:"userInterfaceStyle"` + Name string `json:"name"` + IsSimulator bool `json:"isSimulator"` + ThermalState int `json:"thermalState"` + // ANDROID_ID A 64-bit number (as a hex string) that is uniquely generated when the user + // first sets up the device and should remain constant for the lifetime of the user's device. The value + // may change if a factory reset is performed on the device. + AndroidID string `json:"androidId"` + // Build.MANUFACTURER value + Manufacturer string `json:"manufacturer"` + // Build.BRAND value + Brand string `json:"brand"` + // Current running OS's API VERSION + APIVersion string `json:"apiVersion"` + // The current version string, for example "1.0" or "3.4b5" + PlatformVersion string `json:"platformVersion"` + // the name of the current celluar network carrier + CarrierName string `json:"carrierName"` + // the real size of the default display + RealDisplaySize string `json:"realDisplaySize"` + // The logical density of the display in Density Independent Pixel units. + DisplayDensity int `json:"displayDensity"` + // available networks + Networks []networkInfo `json:"networks"` + // current system locale + Locale string `json:"locale"` + Bluetooth struct { + State string `json:"state"` + } `json:"bluetooth"` +} + +type networkCapabilities struct { + TransportTypes string `json:"transportTypes"` + NetworkCapabilities string `json:"networkCapabilities"` + LinkUpstreamBandwidthKbps int `json:"linkUpstreamBandwidthKbps"` + LinkDownBandwidthKbps int `json:"linkDownBandwidthKbps"` + SignalStrength int `json:"signalStrength"` + SSID string `json:"SSID"` +} + +type networkInfo struct { + Type int `json:"type"` + TypeName string `json:"typeName"` + Subtype int `json:"subtype"` + SubtypeName string `json:"subtypeName"` + IsConnected bool `json:"isConnected"` + DetailedState string `json:"detailedState"` + State string `json:"state"` + ExtraInfo string `json:"extraInfo"` + IsAvailable bool `json:"isAvailable"` + IsRoaming bool `json:"isRoaming"` + IsFailover bool `json:"isFailover"` + Capabilities networkCapabilities `json:"capabilities"` +} + +type Location struct { + AuthorizationStatus int `json:"authorizationStatus"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + Altitude float64 `json:"altitude"` +} + +type BatteryInfo struct { + // Battery level in range [0.0, 1.0], where 1.0 means 100% charge. + Level float64 `json:"level"` + + // Battery state ( 1: on battery, discharging; 2: plugged in, less than 100%, 3: plugged in, at 100% ) + State BatteryState `json:"state"` + + Status BatteryStatus `json:"status"` +} + +type BatteryState int + +const ( + _ = iota + BatteryStateUnplugged BatteryState = iota // on battery, discharging + BatteryStateCharging // plugged in, less than 100% + BatteryStateFull // plugged in, at 100% +) + +func (v BatteryState) String() string { + switch v { + case BatteryStateUnplugged: + return "On battery, discharging" + case BatteryStateCharging: + return "Plugged in, less than 100%" + case BatteryStateFull: + return "Plugged in, at 100%" + default: + return "UNKNOWN" + } +} + +type Size struct { + Width int `json:"width"` + Height int `json:"height"` +} + +func (s Size) IsNil() bool { + return s.Width == 0 && s.Height == 0 +} + +type Screen struct { + StatusBarSize Size `json:"statusBarSize"` + Scale float64 `json:"scale"` +} + +type AppInfo struct { + Name string `json:"name,omitempty"` + AppBaseInfo +} + +type WindowInfo struct { + PackageName string `json:"packageName,omitempty"` + Activity string `json:"activity,omitempty"` +} + +type AppBaseInfo struct { + Pid int `json:"pid,omitempty"` + BundleId string `json:"bundleId,omitempty"` // ios package name + ViewController string `json:"viewController,omitempty"` // ios view controller + PackageName string `json:"packageName,omitempty"` // android package name + Activity string `json:"activity,omitempty"` // android activity + VersionName string `json:"versionName,omitempty"` + VersionCode interface{} `json:"versionCode,omitempty"` // int or string + AppName string `json:"appName,omitempty"` + AppPath string `json:"appPath,omitempty"` + AppMD5 string `json:"appMD5,omitempty"` + // AppIcon string `json:"appIcon,omitempty"` +} + +type AppState int + +const ( + AppStateNotRunning AppState = 1 << iota + AppStateRunningBack + AppStateRunningFront +) + +func (v AppState) String() string { + switch v { + case AppStateNotRunning: + return "Not Running" + case AppStateRunningBack: + return "Running (Back)" + case AppStateRunningFront: + return "Running (Front)" + default: + return "UNKNOWN" + } +} + +// PasteboardType The type of the item on the pasteboard. +type PasteboardType string + +const ( + PasteboardTypePlaintext PasteboardType = "plaintext" + PasteboardTypeImage PasteboardType = "image" + PasteboardTypeUrl PasteboardType = "url" +) + +const ( + TextBackspace string = "\u0008" + TextDelete string = "\u007F" +) + +// DeviceButton A physical button on an iOS device. +type DeviceButton string + +const ( + DeviceButtonHome DeviceButton = "home" + DeviceButtonVolumeUp DeviceButton = "volumeUp" + DeviceButtonVolumeDown DeviceButton = "volumeDown" +) + +type NotificationType string + +const ( + NotificationTypePlain NotificationType = "plain" + NotificationTypeDarwin NotificationType = "darwin" +) + +type Orientation string + +const ( + // OrientationPortrait Device oriented vertically, home button on the bottom + OrientationPortrait Orientation = "PORTRAIT" + + // OrientationPortraitUpsideDown Device oriented vertically, home button on the top + OrientationPortraitUpsideDown Orientation = "UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN" + + // OrientationLandscapeLeft Device oriented horizontally, home button on the right + OrientationLandscapeLeft Orientation = "LANDSCAPE" + + // OrientationLandscapeRight Device oriented horizontally, home button on the left + OrientationLandscapeRight Orientation = "UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT" +) + +type Rotation struct { + X int `json:"x"` + Y int `json:"y"` + Z int `json:"z"` +} + +type Condition func(wd IWebDriver) (bool, error) + +type Direction string + +const ( + DirectionUp Direction = "up" + DirectionDown Direction = "down" + DirectionLeft Direction = "left" + DirectionRight Direction = "right" +) + +type Point struct { + X int `json:"x"` // upper left X coordinate of selected element + Y int `json:"y"` // upper left Y coordinate of selected element +} + +type PointF struct { + X float64 `json:"x"` + Y float64 `json:"y"` +} + +func (p PointF) IsIdentical(p2 PointF) bool { + // set the coordinate precision to 1 pixel + return math.Abs(p.X-p2.X) < 1 && math.Abs(p.Y-p2.Y) < 1 +} diff --git a/server/source.go b/server/source.go index 67159b95..bd9e02ef 100644 --- a/server/source.go +++ b/server/source.go @@ -9,7 +9,6 @@ import ( "github.com/rs/zerolog/log" "github.com/httprunner/httprunner/v5/code" - "github.com/httprunner/httprunner/v5/pkg/uixt" "github.com/httprunner/httprunner/v5/pkg/uixt/option" ) @@ -97,7 +96,7 @@ func sourceHandler(c *gin.Context) { c.Abort() return } - source, err := dExt.Driver.Source(uixt.NewSourceOption().WithProcessName(app.PackageName)) + source, err := dExt.Driver.Source(option.NewSourceOption().WithProcessName(app.PackageName)) if err != nil { log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get source %s", c.HandlerName(), app.PackageName)) c.JSON(http.StatusInternalServerError,