From 91df2906c4abfc605fabf190d1c820145487b279 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Fri, 7 Feb 2025 16:54:25 +0800 Subject: [PATCH] refactor: DriverSession --- internal/version/VERSION | 2 +- pkg/uixt/android_device.go | 2 +- pkg/uixt/android_driver_adb.go | 38 ++++++------- pkg/uixt/android_driver_stub.go | 2 +- pkg/uixt/android_driver_uia2.go | 69 +++++++++++------------ pkg/uixt/driver.go | 60 +++++++++----------- pkg/uixt/harmony_driver_hdc.go | 8 +-- pkg/uixt/ios_device.go | 2 +- pkg/uixt/ios_driver_stub.go | 16 +++--- pkg/uixt/ios_driver_wda.go | 98 ++++++++++++++++----------------- pkg/uixt/option/android.go | 3 + 11 files changed, 141 insertions(+), 159 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index 52dafb47..04624403 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502071622 +v5.0.0+2502071738 diff --git a/pkg/uixt/android_device.go b/pkg/uixt/android_device.go index 4cee7380..87d426ef 100644 --- a/pkg/uixt/android_device.go +++ b/pkg/uixt/android_device.go @@ -93,7 +93,7 @@ type AndroidDevice struct { } func (dev *AndroidDevice) Setup() error { - dev.RunShellCommand("ime", "enable", UnicodeImePackageName) + dev.RunShellCommand("ime", "enable", option.UnicodeImePackageName) dev.RunShellCommand("rm", "-r", config.DeviceActionLogFilePath) // setup evalite diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index 357f8698..ee48b93d 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -26,27 +26,23 @@ import ( "github.com/httprunner/httprunner/v5/pkg/uixt/option" ) -const ( - AdbKeyBoardPackageName = "com.android.adbkeyboard/.AdbIME" - UnicodeImePackageName = "io.appium.settings/.UnicodeIME" -) - func NewADBDriver(device *AndroidDevice) (*ADBDriver, error) { log.Info().Interface("device", device).Msg("init android adb driver") - driver := &ADBDriver{} + driver := &ADBDriver{ + AndroidDevice: device, + DriverSession: &DriverSession{}, + } driver.NewSession(nil) - driver.Device = device.Device - driver.Logcat = device.Logcat return driver, nil } type ADBDriver struct { *AndroidDevice - *DriverClient + *DriverSession } func (ad *ADBDriver) runShellCommand(cmd string, args ...string) (output string, err error) { - driverResult := &DriverResult{ + driverResult := &DriverRequests{ RequestMethod: "adb", RequestUrl: cmd, RequestBody: strings.Join(args, " "), @@ -60,7 +56,7 @@ func (ad *ADBDriver) runShellCommand(cmd string, args ...string) (output string, } else { driverResult.Success = true } - ad.session.addRequestResult(driverResult) + ad.addRequestResult(driverResult) }() // adb shell screencap -p @@ -79,7 +75,7 @@ func (ad *ADBDriver) runShellCommand(cmd string, args ...string) (output string, } func (ad *ADBDriver) NewSession(capabilities option.Capabilities) (sessionInfo SessionInfo, err error) { - ad.DriverClient.session.Reset() + ad.Reset() err = errDriverNotImplemented return } @@ -542,11 +538,11 @@ func (ad *ADBDriver) SendUnicodeKeys(text string, opts ...option.ActionOption) ( if err != nil { return } - if currentIme != UnicodeImePackageName { + if currentIme != option.UnicodeImePackageName { defer func() { _ = ad.SetIme(currentIme) }() - err = ad.SetIme(UnicodeImePackageName) + err = ad.SetIme(option.UnicodeImePackageName) if err != nil { log.Warn().Err(err).Msgf("set Unicode Ime failed") return @@ -566,7 +562,7 @@ func (ad *ADBDriver) IsAdbKeyBoardInstalled() bool { if err != nil { return false } - return strings.Contains(output, AdbKeyBoardPackageName) + return strings.Contains(output, option.AdbKeyBoardPackageName) } func (ad *ADBDriver) IsUnicodeIMEInstalled() bool { @@ -574,7 +570,7 @@ func (ad *ADBDriver) IsUnicodeIMEInstalled() bool { if err != nil { return false } - return strings.Contains(output, UnicodeImePackageName) + return strings.Contains(output, option.UnicodeImePackageName) } func (ad *ADBDriver) ListIme() []string { @@ -594,12 +590,12 @@ func (ad *ADBDriver) SendKeysByAdbKeyBoard(text string) (err error) { }() // Enable ADBKeyBoard from adb - if _, err = ad.runShellCommand("ime", "enable", AdbKeyBoardPackageName); err != nil { + if _, err = ad.runShellCommand("ime", "enable", option.AdbKeyBoardPackageName); err != nil { log.Error().Err(err).Msg("failed to enable adbKeyBoard") return } // Switch to ADBKeyBoard from adb - if _, err = ad.runShellCommand("ime", "set", AdbKeyBoardPackageName); err != nil { + if _, err = ad.runShellCommand("ime", "set", option.AdbKeyBoardPackageName); err != nil { log.Error().Err(err).Msg("failed to set adbKeyBoard") return } @@ -862,10 +858,10 @@ func (ad *ADBDriver) StopCaptureLog() (result interface{}, err error) { } func (ad *ADBDriver) GetSession() *DriverSession { - return &ad.DriverClient.session + return ad.DriverSession } -func (ad *ADBDriver) GetDriverResults() []*DriverResult { +func (ad *ADBDriver) GetDriverResults() []*DriverRequests { return nil } @@ -910,7 +906,7 @@ func (ad *ADBDriver) SetIme(imeRegx string) error { if strings.TrimSpace(pid) == "" { appInfo, err := ad.GetForegroundApp() _ = ad.AppLaunch(packageName) - if err == nil && packageName != UnicodeImePackageName { + if err == nil && packageName != option.UnicodeImePackageName { time.Sleep(10 * time.Second) nextAppInfo, err := ad.GetForegroundApp() log.Info().Str("beforeFocusedPackage", appInfo.PackageName).Str("afterFocusedPackage", nextAppInfo.PackageName).Msg("") diff --git a/pkg/uixt/android_driver_stub.go b/pkg/uixt/android_driver_stub.go index 33d45fac..8db89f8c 100644 --- a/pkg/uixt/android_driver_stub.go +++ b/pkg/uixt/android_driver_stub.go @@ -118,7 +118,7 @@ func (sad *StubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (ra } func (sad *StubAndroidDriver) NewSession(capabilities option.Capabilities) (SessionInfo, error) { - sad.DriverClient.session.Reset() + sad.Reset() return SessionInfo{}, errDriverNotImplemented } diff --git a/pkg/uixt/android_driver_uia2.go b/pkg/uixt/android_driver_uia2.go index 2115ceca..4656b445 100644 --- a/pkg/uixt/android_driver_uia2.go +++ b/pkg/uixt/android_driver_uia2.go @@ -56,26 +56,26 @@ func (ud *UIA2Driver) resetDriver() error { if err != nil { return err } - ud.session.ID = session.SessionId + ud.SessionID = session.SessionId return nil } func (ud *UIA2Driver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { for retryCount := 1; retryCount <= 5; retryCount++ { - rawResp, err = ud.DriverClient.Request(method, rawURL, rawBody) + rawResp, err = ud.Request(method, rawURL, rawBody) if err == nil { return } // wait for UIA2 server to resume automatically time.Sleep(3 * time.Second) - oldSessionID := ud.session.ID + oldSessionID := ud.SessionID if err2 := ud.resetDriver(); err2 != nil { log.Err(err2).Msgf("failed to reset uia2 driver, retry count: %v", retryCount) continue } - log.Debug().Str("new session", ud.session.ID).Str("old session", oldSessionID).Msgf("successful to reset uia2 driver, retry count: %v", retryCount) + log.Debug().Str("new session", ud.SessionID).Str("old session", oldSessionID).Msgf("successful to reset uia2 driver, retry count: %v", retryCount) if oldSessionID != "" { - rawURL = strings.Replace(rawURL, oldSessionID, ud.session.ID, 1) + rawURL = strings.Replace(rawURL, oldSessionID, ud.SessionID, 1) } } return @@ -108,7 +108,7 @@ func (ud *UIA2Driver) NewSession(capabilities option.Capabilities) (sessionInfo } else { data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities} } - if rawResp, err = ud.DriverClient.POST(data, "/session"); err != nil { + if rawResp, err = ud.POST(data, "/session"); err != nil { return SessionInfo{SessionId: ""}, err } reply := new(struct{ Value struct{ SessionId string } }) @@ -116,18 +116,18 @@ func (ud *UIA2Driver) NewSession(capabilities option.Capabilities) (sessionInfo return SessionInfo{SessionId: ""}, err } sessionID := reply.Value.SessionId - ud.DriverClient.session.Reset() - ud.DriverClient.session.ID = sessionID + ud.Reset() + ud.SessionID = sessionID // d.sessionIdCache[sessionID] = true return SessionInfo{SessionId: sessionID}, nil } func (ud *UIA2Driver) DeleteSession() (err error) { - if ud.session.ID == "" { + if ud.SessionID == "" { return nil } - if _, err = ud.httpDELETE("/session", ud.session.ID); err == nil { - ud.session.ID = "" + if _, err = ud.httpDELETE("/session", ud.SessionID); err == nil { + ud.SessionID = "" } return err @@ -137,7 +137,7 @@ func (ud *UIA2Driver) Status() (deviceStatus DeviceStatus, err error) { // register(getHandler, new Status("/wd/hub/status")) var rawResp rawResponse // Notice: use Driver.GET instead of httpGET to avoid loop calling - if rawResp, err = ud.DriverClient.GET("/status"); err != nil { + if rawResp, err = ud.GET("/status"); err != nil { return DeviceStatus{Ready: false}, err } reply := new(struct { @@ -155,7 +155,7 @@ func (ud *UIA2Driver) Status() (deviceStatus DeviceStatus, err error) { func (ud *UIA2Driver) DeviceInfo() (deviceInfo DeviceInfo, err error) { // register(getHandler, new GetDeviceInfo("/wd/hub/session/:sessionId/appium/device/info")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.session.ID, "appium/device/info"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.SessionID, "appium/device/info"); err != nil { return DeviceInfo{}, err } reply := new(struct{ Value struct{ DeviceInfo } }) @@ -169,7 +169,7 @@ func (ud *UIA2Driver) DeviceInfo() (deviceInfo DeviceInfo, err error) { func (ud *UIA2Driver) BatteryInfo() (batteryInfo BatteryInfo, err error) { // register(getHandler, new GetBatteryInfo("/wd/hub/session/:sessionId/appium/device/battery_info")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.session.ID, "appium/device/battery_info"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.SessionID, "appium/device/battery_info"); err != nil { return BatteryInfo{}, err } reply := new(struct{ Value struct{ BatteryInfo } }) @@ -191,7 +191,7 @@ func (ud *UIA2Driver) WindowSize() (size Size, err error) { } var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.session.ID, "window/:windowHandle/size"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.SessionID, "window/:windowHandle/size"); err != nil { return Size{}, errors.Wrap(err, "get window size failed by UIA2 request") } reply := new(struct{ Value struct{ Size } }) @@ -217,7 +217,7 @@ func (ud *UIA2Driver) WindowSize() (size Size, err error) { // PressBack simulates a short press on the BACK button. func (ud *UIA2Driver) PressBack(opts ...option.ActionOption) (err error) { // register(postHandler, new PressBack("/wd/hub/session/:sessionId/back")) - _, err = ud.httpPOST(nil, "/session", ud.session.ID, "back") + _, err = ud.httpPOST(nil, "/session", ud.SessionID, "back") return } @@ -240,14 +240,14 @@ func (ud *UIA2Driver) PressKeyCodes(keyCode KeyCode, metaState KeyMeta, flags .. if len(flags) != 0 { data["flags"] = flags[0] } - _, err = ud.httpPOST(data, "/session", ud.session.ID, "appium/device/press_keycode") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "appium/device/press_keycode") return } func (ud *UIA2Driver) Orientation() (orientation Orientation, err error) { // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.session.ID, "/orientation"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.SessionID, "/orientation"); err != nil { return "", err } reply := new(struct{ Value Orientation }) @@ -280,7 +280,7 @@ func (ud *UIA2Driver) DoubleFloatTap(x, y float64) error { }, } - _, err := ud.httpPOST(data, "/session", ud.session.ID, "actions/tap") + _, err := ud.httpPOST(data, "/session", ud.SessionID, "actions/tap") return err } @@ -318,7 +318,7 @@ func (ud *UIA2Driver) Tap(x, y float64, opts ...option.ActionOption) (err error) // update data options in post data for extra uiautomator configurations actionOptions.UpdateData(data) - _, err = ud.httpPOST(data, "/session", ud.session.ID, "actions/tap") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "actions/tap") return err } @@ -336,7 +336,7 @@ func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (e "duration": int(duration * 1000), }, } - _, err = ud.httpPOST(data, "/session", ud.session.ID, "touch/longclick") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "touch/longclick") return } @@ -368,7 +368,7 @@ func (ud *UIA2Driver) Drag(fromX, fromY, toX, toY float64, opts ...option.Action actionOptions.UpdateData(data) // register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag")) - _, err = ud.httpPOST(data, "/session", ud.session.ID, "touch/drag") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "touch/drag") return } @@ -414,7 +414,7 @@ func (ud *UIA2Driver) Swipe(fromX, fromY, toX, toY float64, opts ...option.Actio // update data options in post data for extra uiautomator configurations actionOptions.UpdateData(data) - _, err := ud.httpPOST(data, "/session", ud.session.ID, "actions/swipe") + _, err := ud.httpPOST(data, "/session", ud.SessionID, "actions/swipe") return err } @@ -432,7 +432,7 @@ func (ud *UIA2Driver) SetPasteboard(contentType PasteboardType, content string) "content": base64.StdEncoding.EncodeToString([]byte(content)), } // register(postHandler, new SetClipboard("/wd/hub/session/:sessionId/appium/device/set_clipboard")) - _, err = ud.httpPOST(data, "/session", ud.session.ID, "appium/device/set_clipboard") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "appium/device/set_clipboard") return } @@ -445,7 +445,7 @@ func (ud *UIA2Driver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buff "contentType": contentType[0], } var rawResp rawResponse - if rawResp, err = ud.httpPOST(data, "/session", ud.session.ID, "appium/device/get_clipboard"); err != nil { + if rawResp, err = ud.httpPOST(data, "/session", ud.SessionID, "appium/device/get_clipboard"); err != nil { return } reply := new(struct{ Value string }) @@ -475,7 +475,7 @@ func (ud *UIA2Driver) SendKeys(text string, opts ...option.ActionOption) (err er // new data options in post data for extra uiautomator configurations actionOptions.UpdateData(data) - _, err = ud.httpPOST(data, "/session", ud.session.ID, "/keys") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "/keys") } return } @@ -491,11 +491,11 @@ func (ud *UIA2Driver) SendUnicodeKeys(text string, opts ...option.ActionOption) if err != nil { return } - if currentIme != UnicodeImePackageName { + if currentIme != option.UnicodeImePackageName { defer func() { _ = ud.ADBDriver.SetIme(currentIme) }() - err = ud.ADBDriver.SetIme(UnicodeImePackageName) + err = ud.ADBDriver.SetIme(option.UnicodeImePackageName) if err != nil { log.Warn().Err(err).Msgf("set Unicode Ime failed") return @@ -533,7 +533,7 @@ func (ud *UIA2Driver) SendActionKey(text string, opts ...option.ActionOption) (e // new data options in post data for extra uiautomator configurations actionOptions.UpdateData(data) - _, err = ud.httpPOST(data, "/session", ud.session.ID, "/actions/keys") + _, err = ud.httpPOST(data, "/session", ud.SessionID, "/actions/keys") return } @@ -544,7 +544,7 @@ func (ud *UIA2Driver) Input(text string, opts ...option.ActionOption) (err error func (ud *UIA2Driver) Rotation() (rotation Rotation, err error) { // register(getHandler, new GetRotation("/wd/hub/session/:sessionId/rotation")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.session.ID, "rotation"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.SessionID, "rotation"); err != nil { return Rotation{}, err } reply := new(struct{ Value Rotation }) @@ -565,7 +565,7 @@ func (ud *UIA2Driver) Screenshot() (raw *bytes.Buffer, err error) { func (ud *UIA2Driver) 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 { + if rawResp, err = ud.httpGET("/session", ud.SessionID, "source"); err != nil { return "", err } reply := new(struct{ Value string }) @@ -612,10 +612,3 @@ func (ud *UIA2Driver) TapByTexts(actions ...TapTextAction) error { } return nil } - -func (ud *UIA2Driver) GetDriverResults() []*DriverResult { - defer func() { - ud.DriverClient.driverResults = nil - }() - return ud.DriverClient.driverResults -} diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index cc4b9ce0..60f02804 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -15,7 +15,6 @@ import ( "strings" "time" - "github.com/httprunner/funplugin" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -165,7 +164,7 @@ type IDriver interface { StartCaptureLog(identifier ...string) (err error) StopCaptureLog() (result interface{}, err error) - GetDriverResults() []*DriverResult + GetDriverResults() []*DriverRequests RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) TearDown() error @@ -182,11 +181,19 @@ type SessionInfo struct { } type DriverSession struct { - ID string + // ctx context.Context + SessionID string + urlPrefix *url.URL + Client *http.Client + + // cache to avoid repeated query + scale float64 + windowSize Size + // cache uia2/wda request and response - requests []*DriverResult + requests []*DriverRequests // cache screenshot ocr results - screenResults []*ScreenResult // list of actions + screenResults []*ScreenResult // cache e2e delay e2eDelay []timeLog } @@ -195,13 +202,13 @@ func (d *DriverSession) addScreenResult(screenResult *ScreenResult) { d.screenResults = append(d.screenResults, screenResult) } -func (d *DriverSession) addRequestResult(driverResult *DriverResult) { +func (d *DriverSession) addRequestResult(driverResult *DriverRequests) { d.requests = append(d.requests, driverResult) } func (d *DriverSession) Reset() { d.screenResults = make([]*ScreenResult, 0) - d.requests = make([]*DriverResult, 0) + d.requests = make([]*DriverRequests, 0) d.e2eDelay = nil } @@ -223,33 +230,21 @@ func (d *DriverSession) Get(withReset bool) Attachments { return data } -type DriverResult struct { +type DriverRequests struct { RequestMethod string `json:"request_method"` RequestUrl string `json:"request_url"` RequestBody string `json:"request_body,omitempty"` RequestTime time.Time `json:"request_time"` - Success bool `json:"success"` ResponseStatus int `json:"response_status"` ResponseDuration int64 `json:"response_duration(ms)"` // ms ResponseBody string `json:"response_body"` - Error string `json:"error,omitempty"` + + Success bool `json:"success"` + Error string `json:"error,omitempty"` } -type DriverClient struct { - urlPrefix *url.URL - Client *http.Client - - // cache to avoid repeated query - scale float64 - windowSize Size - driverResults []*DriverResult - - // cache session data - session DriverSession -} - -func (wd *DriverClient) concatURL(u *url.URL, elem ...string) string { +func (wd *DriverSession) concatURL(u *url.URL, elem ...string) string { var tmp *url.URL if u == nil { u = wd.urlPrefix @@ -259,11 +254,11 @@ func (wd *DriverClient) concatURL(u *url.URL, elem ...string) string { return tmp.String() } -func (wd *DriverClient) GET(pathElem ...string) (rawResp rawResponse, err error) { +func (wd *DriverSession) GET(pathElem ...string) (rawResp rawResponse, err error) { return wd.Request(http.MethodGet, wd.concatURL(nil, pathElem...), nil) } -func (wd *DriverClient) POST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) { +func (wd *DriverSession) POST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) { var bsJSON []byte = nil if data != nil { if bsJSON, err = json.Marshal(data); err != nil { @@ -273,19 +268,19 @@ func (wd *DriverClient) POST(data interface{}, pathElem ...string) (rawResp rawR return wd.Request(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON) } -func (wd *DriverClient) DELETE(pathElem ...string) (rawResp rawResponse, err error) { +func (wd *DriverSession) DELETE(pathElem ...string) (rawResp rawResponse, err error) { return wd.Request(http.MethodDelete, wd.concatURL(nil, pathElem...), nil) } -func (wd *DriverClient) Request(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { - driverResult := &DriverResult{ +func (wd *DriverSession) Request(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { + driverResult := &DriverRequests{ RequestMethod: method, RequestUrl: rawURL, RequestBody: string(rawBody), } defer func() { - wd.session.addRequestResult(driverResult) + wd.addRequestResult(driverResult) var logger *zerolog.Event if err != nil { @@ -369,13 +364,9 @@ func convertToHTTPClient(conn net.Conn) *http.Client { } type DriverExt struct { - Ctx context.Context Device IDevice Driver IDriver ImageService IImageService // used to extract image data - - // funplugin - plugin funplugin.IPlugin } func newDriverExt(device IDevice, driver IDriver, opts ...option.DriverOption) (dExt *DriverExt, err error) { @@ -384,7 +375,6 @@ func newDriverExt(device IDevice, driver IDriver, opts ...option.DriverOption) ( dExt = &DriverExt{ Device: device, Driver: driver, - plugin: options.Plugin, } if options.WithImageService { diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index f50158cc..bb01b7e8 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -15,7 +15,7 @@ import ( type hdcDriver struct { *HarmonyDevice - *DriverClient + *DriverSession points []ExportPoint uiDriver *ghdc.UIDriver } @@ -42,7 +42,7 @@ func newHarmonyDriver(device *ghdc.Device) (driver *hdcDriver, err error) { } func (hd *hdcDriver) NewSession(capabilities option.Capabilities) (SessionInfo, error) { - hd.DriverClient.session.Reset() + hd.Reset() hd.Unlock() return SessionInfo{}, errDriverNotImplemented } @@ -52,7 +52,7 @@ func (hd *hdcDriver) DeleteSession() error { } func (hd *hdcDriver) GetSession() *DriverSession { - return &hd.DriverClient.session + return hd.DriverSession } func (hd *hdcDriver) Status() (DeviceStatus, error) { @@ -324,7 +324,7 @@ func (hd *hdcDriver) StopCaptureLog() (result interface{}, err error) { return hd.points, nil } -func (hd *hdcDriver) GetDriverResults() []*DriverResult { +func (hd *hdcDriver) GetDriverResults() []*DriverRequests { return nil } diff --git a/pkg/uixt/ios_device.go b/pkg/uixt/ios_device.go index 70c501dd..7af15020 100644 --- a/pkg/uixt/ios_device.go +++ b/pkg/uixt/ios_device.go @@ -581,7 +581,7 @@ func (dev *IOSDevice) NewHTTPDriver(capabilities option.Capabilities) (driver ID if sessionInfo, err = wd.NewSession(capabilities); err != nil { return nil, errors.Wrap(code.DeviceHTTPDriverError, err.Error()) } - wd.session.ID = sessionInfo.SessionId + wd.SessionID = sessionInfo.SessionId if wd.mjpegHTTPConn, err = net.Dial( "tcp", diff --git a/pkg/uixt/ios_driver_stub.go b/pkg/uixt/ios_driver_stub.go index 612bac98..9b73564c 100644 --- a/pkg/uixt/ios_driver_stub.go +++ b/pkg/uixt/ios_driver_stub.go @@ -31,7 +31,7 @@ func newStubIOSDriver(bightInsightAddr, serverAddr string, dev *IOSDevice, readT driver.bightInsightPrefix = bightInsightAddr driver.serverPrefix = serverAddr driver.timeout = timeout - driver.DriverClient.Client = &http.Client{ + driver.Client = &http.Client{ Timeout: time.Second * 10, // 设置超时时间为 10 秒 } return driver, nil @@ -441,7 +441,7 @@ func (s *stubIOSDriver) StopCaptureLog() (result interface{}, err error) { return s.wdaDriver.StopCaptureLog() } -func (s *stubIOSDriver) GetDriverResults() []*DriverResult { +func (s *stubIOSDriver) GetDriverResults() []*DriverRequests { err := s.setUpWda() if err != nil { return nil @@ -450,7 +450,7 @@ func (s *stubIOSDriver) GetDriverResults() []*DriverResult { } 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{}) + resp, err := s.Request(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{}) if err != nil { return "", err } @@ -472,7 +472,7 @@ func (s *stubIOSDriver) LoginNoneUI(packageName, phoneNumber string, captcha, pa if err != nil { return info, err } - resp, err := s.DriverClient.Request(http.MethodPost, fmt.Sprintf("%s/host/login/account/", s.serverPrefix), bsJSON) + resp, err := s.Request(http.MethodPost, fmt.Sprintf("%s/host/login/account/", s.serverPrefix), bsJSON) if err != nil { return info, err } @@ -496,7 +496,7 @@ func (s *stubIOSDriver) LoginNoneUI(packageName, phoneNumber string, captcha, pa } func (s *stubIOSDriver) LogoutNoneUI(packageName string) error { - resp, err := s.DriverClient.Request(http.MethodGet, fmt.Sprintf("%s/host/loginout/", s.serverPrefix), []byte{}) + resp, err := s.Request(http.MethodGet, fmt.Sprintf("%s/host/loginout/", s.serverPrefix), []byte{}) if err != nil { return err } @@ -515,12 +515,12 @@ func (s *stubIOSDriver) LogoutNoneUI(packageName string) error { } func (s *stubIOSDriver) TearDown() error { - s.DriverClient.Client.CloseIdleConnections() + s.Client.CloseIdleConnections() return nil } func (s *stubIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo, err error) { - resp, err := s.DriverClient.Request(http.MethodGet, fmt.Sprintf("%s/host/app/info/", s.serverPrefix), []byte{}) + resp, err := s.Request(http.MethodGet, fmt.Sprintf("%s/host/app/info/", s.serverPrefix), []byte{}) if err != nil { return info, err } @@ -542,5 +542,5 @@ func (s *stubIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo, } func (s *stubIOSDriver) GetSession() *DriverSession { - return &s.DriverClient.session + return s.DriverSession } diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index d4a6bb53..fe59e3be 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -29,7 +29,7 @@ import ( type wdaDriver struct { *IOSDevice - *DriverClient + *DriverSession udid string mjpegHTTPConn net.Conn // via HTTP mjpegClient *http.Client @@ -47,7 +47,7 @@ func (wd *wdaDriver) resetSession() error { } // Notice: use Driver.POST instead of httpPOST to avoid loop calling - rawResp, err := wd.DriverClient.POST(data, "/session") + rawResp, err := wd.DriverSession.POST(data, "/session") if err != nil { return err } @@ -56,14 +56,14 @@ func (wd *wdaDriver) resetSession() error { return err } // update session ID - wd.session.ID = sessionInfo.SessionId + wd.SessionID = sessionInfo.SessionId return nil } func (wd *wdaDriver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { retryInterval := 3 * time.Second for retryCount := 1; retryCount <= 3; retryCount++ { - rawResp, err = wd.DriverClient.Request(method, rawURL, rawBody) + rawResp, err = wd.Request(method, rawURL, rawBody) if err == nil { return } @@ -80,15 +80,15 @@ func (wd *wdaDriver) httpRequest(method string, rawURL string, rawBody []byte) ( retryInterval = retryInterval * 2 time.Sleep(retryInterval) - oldSessionID := wd.session.ID + oldSessionID := wd.SessionID if err2 := wd.resetSession(); err2 != nil { log.Err(err2).Msgf("failed to reset wda driver session, retry count: %v", retryCount) continue } - log.Debug().Str("new session", wd.session.ID).Str("old session", oldSessionID). + log.Debug().Str("new session", wd.SessionID).Str("old session", oldSessionID). Msgf("reset wda driver session successfully, retry count: %v", retryCount) if oldSessionID != "" { - rawURL = strings.Replace(rawURL, oldSessionID, wd.session.ID, 1) + rawURL = strings.Replace(rawURL, oldSessionID, wd.SessionID, 1) } } return @@ -146,7 +146,7 @@ func (wd *wdaDriver) DeleteSession() (err error) { } // [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)] - _, err = wd.httpDELETE("/session", wd.session.ID) + _, err = wd.httpDELETE("/session", wd.SessionID) return } @@ -154,7 +154,7 @@ func (wd *wdaDriver) Status() (deviceStatus DeviceStatus, err error) { // [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)] var rawResp rawResponse // Notice: use Driver.GET instead of httpGET to avoid loop calling - if rawResp, err = wd.DriverClient.GET("/status"); err != nil { + if rawResp, err = wd.GET("/status"); err != nil { return DeviceStatus{}, err } reply := new(struct{ Value struct{ DeviceStatus } }) @@ -169,7 +169,7 @@ func (wd *wdaDriver) DeviceInfo() (deviceInfo DeviceInfo, err error) { // [[FBRoute GET:@"/wda/device/info"] respondWithTarget:self action:@selector(handleGetDeviceInfo:)] // [[FBRoute GET:@"/wda/device/info"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/device/info"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/device/info"); err != nil { return DeviceInfo{}, err } reply := new(struct{ Value struct{ DeviceInfo } }) @@ -184,7 +184,7 @@ func (wd *wdaDriver) Location() (location Location, err error) { // [[FBRoute GET:@"/wda/device/location"] respondWithTarget:self action:@selector(handleGetLocation:)] // [[FBRoute GET:@"/wda/device/location"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/device/location"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/device/location"); err != nil { return Location{}, err } reply := new(struct{ Value struct{ Location } }) @@ -198,7 +198,7 @@ func (wd *wdaDriver) Location() (location Location, err error) { func (wd *wdaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) { // [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/batteryInfo"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/batteryInfo"); err != nil { return BatteryInfo{}, err } reply := new(struct{ Value struct{ BatteryInfo } }) @@ -217,7 +217,7 @@ func (wd *wdaDriver) WindowSize() (size Size, err error) { } var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/window/size"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/window/size"); err != nil { return Size{}, errors.Wrap(err, "get window size failed by WDA request") } reply := new(struct{ Value struct{ Size } }) @@ -239,7 +239,7 @@ func (wd *wdaDriver) WindowSize() (size Size, err error) { func (wd *wdaDriver) Screen() (screen Screen, err error) { // [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/screen"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/screen"); err != nil { return Screen{}, err } reply := new(struct{ Value struct{ Screen } }) @@ -275,7 +275,7 @@ func (wd *wdaDriver) ActiveAppInfo() (info AppInfo, err error) { // [[FBRoute GET:@"/wda/activeAppInfo"] respondWithTarget:self action:@selector(handleActiveAppInfo:)] // [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/activeAppInfo"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/activeAppInfo"); err != nil { return AppInfo{}, err } reply := new(struct{ Value struct{ AppInfo } }) @@ -289,7 +289,7 @@ func (wd *wdaDriver) ActiveAppInfo() (info AppInfo, err error) { func (wd *wdaDriver) ActiveAppsList() (appsList []AppBaseInfo, err error) { // [[FBRoute GET:@"/wda/apps/list"] respondWithTarget:self action:@selector(handleGetActiveAppsList:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/apps/list"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/apps/list"); err != nil { return nil, err } reply := new(struct{ Value []AppBaseInfo }) @@ -304,7 +304,7 @@ func (wd *wdaDriver) AppState(bundleId string) (runState AppState, err error) { // [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)] data := map[string]interface{}{"bundleId": bundleId} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/state"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/apps/state"); err != nil { return 0, err } reply := new(struct{ Value AppState }) @@ -320,7 +320,7 @@ func (wd *wdaDriver) IsLocked() (locked bool, err error) { // [[FBRoute GET:@"/wda/locked"] respondWithTarget:self action:@selector(handleIsLocked:)] // [[FBRoute GET:@"/wda/locked"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/locked"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/locked"); err != nil { return false, err } if locked, err = rawResp.valueConvertToBool(); err != nil { @@ -332,14 +332,14 @@ func (wd *wdaDriver) IsLocked() (locked bool, err error) { func (wd *wdaDriver) Unlock() (err error) { // [[FBRoute POST:@"/wda/unlock"] respondWithTarget:self action:@selector(handleUnlock:)] // [[FBRoute POST:@"/wda/unlock"].withoutSession - _, err = wd.httpPOST(nil, "/session", wd.session.ID, "/wda/unlock") + _, err = wd.httpPOST(nil, "/session", wd.SessionID, "/wda/unlock") return } func (wd *wdaDriver) Lock() (err error) { // [[FBRoute POST:@"/wda/lock"] respondWithTarget:self action:@selector(handleLock:)] // [[FBRoute POST:@"/wda/lock"].withoutSession - _, err = wd.httpPOST(nil, "/session", wd.session.ID, "/wda/lock") + _, err = wd.httpPOST(nil, "/session", wd.SessionID, "/wda/lock") return } @@ -353,7 +353,7 @@ func (wd *wdaDriver) AlertText() (text string, err error) { // [[FBRoute GET:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertGetTextCommand:)] // [[FBRoute GET:@"/alert/text"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/alert/text"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/alert/text"); err != nil { return "", err } if text, err = rawResp.valueConvertToString(); err != nil { @@ -365,7 +365,7 @@ func (wd *wdaDriver) AlertText() (text string, err error) { func (wd *wdaDriver) AlertButtons() (btnLabels []string, err error) { // [[FBRoute GET:@"/wda/alert/buttons"] respondWithTarget:self action:@selector(handleGetAlertButtonsCommand:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/alert/buttons"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/alert/buttons"); err != nil { return nil, err } reply := new(struct{ Value []string }) @@ -401,7 +401,7 @@ func (wd *wdaDriver) AlertDismiss(label ...string) (err error) { func (wd *wdaDriver) AlertSendKeys(text string) (err error) { // [[FBRoute POST:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertSetTextCommand:)] data := map[string]interface{}{"value": strings.Split(text, "")} - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/alert/text") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/alert/text") return } @@ -412,7 +412,7 @@ func (wd *wdaDriver) AppLaunch(bundleId string) (err error) { data["environment"] = map[string]interface{}{ "SHOW_EXPLORER": "NO", } - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/launch") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/apps/launch") if err != nil { return errors.Wrap(code.MobileUILaunchAppError, fmt.Sprintf("wda launch failed: %v", err)) @@ -435,7 +435,7 @@ func (wd *wdaDriver) AppTerminate(bundleId string) (successful bool, err error) // [[FBRoute POST:@"/wda/apps/terminate"] respondWithTarget:self action:@selector(handleSessionAppTerminate:)] data := map[string]interface{}{"bundleId": bundleId} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/terminate"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/apps/terminate"); err != nil { return false, err } if successful, err = rawResp.valueConvertToBool(); err != nil { @@ -447,7 +447,7 @@ func (wd *wdaDriver) AppTerminate(bundleId string) (successful bool, err error) func (wd *wdaDriver) AppActivate(bundleId string) (err error) { // [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)] data := map[string]interface{}{"bundleId": bundleId} - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/activate") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/apps/activate") return } @@ -457,7 +457,7 @@ func (wd *wdaDriver) AppDeactivate(second float64) (err error) { second = 3.0 } data := map[string]interface{}{"duration": second} - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/deactivateApp") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/deactivateApp") return } @@ -528,7 +528,7 @@ func (wd *wdaDriver) Tap(x, y float64, opts ...option.ActionOption) (err error) // update data options in post data for extra WDA configurations actionOptions.UpdateData(data) - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/tap/0") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/tap/0") return } @@ -548,7 +548,7 @@ func (wd *wdaDriver) DoubleTap(x, y float64, opts ...option.ActionOption) (err e "x": x, "y": y, } - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/doubleTap") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/doubleTap") return } @@ -592,8 +592,8 @@ func (wd *wdaDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO // update data options in post data for extra WDA configurations actionOptions.UpdateData(data) // wda 43 version - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/dragfromtoforduration") - // _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/drag") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/dragfromtoforduration") + // _, err = wd.httpPOST(data, "/session", wd.ID, "/wda/drag") return } @@ -607,7 +607,7 @@ func (wd *wdaDriver) SetPasteboard(contentType PasteboardType, content string) ( "contentType": contentType, "content": base64.StdEncoding.EncodeToString([]byte(content)), } - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/setPasteboard") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/setPasteboard") return } @@ -615,7 +615,7 @@ func (wd *wdaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe // [[FBRoute POST:@"/wda/getPasteboard"] respondWithTarget:self action:@selector(handleGetPasteboard:)] data := map[string]interface{}{"contentType": contentType} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/getPasteboard"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/getPasteboard"); err != nil { return nil, err } if raw, err = rawResp.valueDecodeAsBase64(); err != nil { @@ -640,7 +640,7 @@ func (wd *wdaDriver) SendKeys(text string, opts ...option.ActionOption) (err err // new data options in post data for extra WDA configurations actionOptions.UpdateData(data) - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/keys") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/keys") return } @@ -699,14 +699,14 @@ func (wd *wdaDriver) PressBack(opts ...option.ActionOption) (err error) { // update data options in post data for extra WDA configurations actionOptions.UpdateData(data) - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/dragfromtoforduration") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/dragfromtoforduration") return } func (wd *wdaDriver) PressButton(devBtn DeviceButton) (err error) { // [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)] data := map[string]interface{}{"name": devBtn} - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/pressButton") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/wda/pressButton") return } @@ -738,7 +738,7 @@ func (wd *wdaDriver) StopCamera() (err error) { func (wd *wdaDriver) Orientation() (orientation Orientation, err error) { // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/orientation"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/orientation"); err != nil { return "", err } reply := new(struct{ Value Orientation }) @@ -752,14 +752,14 @@ func (wd *wdaDriver) Orientation() (orientation Orientation, err error) { func (wd *wdaDriver) SetOrientation(orientation Orientation) (err error) { // [[FBRoute POST:@"/orientation"] respondWithTarget:self action:@selector(handleSetOrientation:)] data := map[string]interface{}{"orientation": orientation} - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/orientation") + _, err = wd.httpPOST(data, "/session", wd.SessionID, "/orientation") return } func (wd *wdaDriver) Rotation() (rotation Rotation, err error) { // [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/rotation"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/rotation"); err != nil { return Rotation{}, err } reply := new(struct{ Value Rotation }) @@ -772,7 +772,7 @@ func (wd *wdaDriver) Rotation() (rotation Rotation, err error) { func (wd *wdaDriver) SetRotation(rotation Rotation) (err error) { // [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)] - _, err = wd.httpPOST(rotation, "/session", wd.session.ID, "/rotation") + _, err = wd.httpPOST(rotation, "/session", wd.SessionID, "/rotation") return } @@ -780,7 +780,7 @@ func (wd *wdaDriver) Screenshot() (raw *bytes.Buffer, err error) { // [[FBRoute GET:@"/screenshot"] respondWithTarget:self action:@selector(handleGetScreenshot:)] // [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/screenshot"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/screenshot"); err != nil { return nil, errors.Wrap(code.DeviceScreenShotError, fmt.Sprintf("get WDA screenshot data failed: %v", err)) } @@ -795,7 +795,7 @@ func (wd *wdaDriver) Screenshot() (raw *bytes.Buffer, 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)) + tmp, _ := url.Parse(wd.concatURL(nil, "/session", wd.SessionID)) toJsonRaw := false if len(srcOpt) != 0 { q := tmp.Query() @@ -838,7 +838,7 @@ func (wd *wdaDriver) AccessibleSource() (source string, err error) { // [[FBRoute GET:@"/wda/accessibleSource"] respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)] // [[FBRoute GET:@"/wda/accessibleSource"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/accessibleSource"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/wda/accessibleSource"); err != nil { return "", err } var jr builtinJSON.RawMessage @@ -858,7 +858,7 @@ func (wd *wdaDriver) HealthCheck() (err error) { func (wd *wdaDriver) GetAppiumSettings() (settings map[string]interface{}, err error) { // [[FBRoute GET:@"/appium/settings"] respondWithTarget:self action:@selector(handleGetSettings:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.session.ID, "/appium/settings"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.SessionID, "/appium/settings"); err != nil { return nil, err } reply := new(struct{ Value map[string]interface{} }) @@ -873,7 +873,7 @@ func (wd *wdaDriver) SetAppiumSettings(settings map[string]interface{}) (ret map // [[FBRoute POST:@"/appium/settings"] respondWithTarget:self action:@selector(handleSetSettings:)] data := map[string]interface{}{"settings": settings} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/appium/settings"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.SessionID, "/appium/settings"); err != nil { return nil, err } reply := new(struct{ Value map[string]interface{} }) @@ -1009,14 +1009,14 @@ func (wd *wdaDriver) StopCaptureLog() (result interface{}, err error) { } func (wd *wdaDriver) GetSession() *DriverSession { - return &wd.DriverClient.session + return wd.DriverSession } -func (wd *wdaDriver) GetDriverResults() []*DriverResult { +func (wd *wdaDriver) GetDriverResults() []*DriverRequests { defer func() { - wd.DriverClient.driverResults = nil + wd.requests = nil }() - return wd.DriverClient.driverResults + return wd.requests } func (wd *wdaDriver) TearDown() error { diff --git a/pkg/uixt/option/android.go b/pkg/uixt/option/android.go index e55da8e8..edf7022e 100644 --- a/pkg/uixt/option/android.go +++ b/pkg/uixt/option/android.go @@ -51,6 +51,9 @@ const ( defaultUIA2ServerPort = 6790 defaultUIA2ServerPackageName = "io.appium.uiautomator2.server" defaultUIA2ServerTestPackageName = "io.appium.uiautomator2.server.test" + + AdbKeyBoardPackageName = "com.android.adbkeyboard/.AdbIME" + UnicodeImePackageName = "io.appium.settings/.UnicodeIME" ) func NewAndroidDeviceOptions(opts ...AndroidDeviceOption) *AndroidDeviceOptions {