diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index db1d1b71..832b83a0 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2412131956 +v5.0.0+2412161739 diff --git a/hrp/pkg/uixt/android_stub_driver.go b/hrp/pkg/uixt/android_stub_driver.go index c37cac66..d3a3156c 100644 --- a/hrp/pkg/uixt/android_stub_driver.go +++ b/hrp/pkg/uixt/android_stub_driver.go @@ -72,7 +72,7 @@ func (sad *stubAndroidDriver) httpGET(pathElem ...string) (rawResp rawResponse, return nil, fmt.Errorf("adb forward: %w", err) } sad.client = convertToHTTPClient(conn) - return sad.httpRequest(http.MethodGet, sad.concatURL(nil, pathElem...), nil) + return sad.Request(http.MethodGet, sad.concatURL(nil, pathElem...), nil) } func (sad *stubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) { @@ -97,7 +97,7 @@ func (sad *stubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (ra return nil, err } } - return sad.httpRequest(http.MethodPost, sad.concatURL(nil, pathElem...), bsJSON) + return sad.Request(http.MethodPost, sad.concatURL(nil, pathElem...), bsJSON) } func (sad *stubAndroidDriver) NewSession(capabilities Capabilities) (SessionInfo, error) { diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index b66bc20e..e340e95f 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -94,11 +94,10 @@ func (ud *uiaDriver) resetDriver() error { return nil } -func (ud *uiaDriver) httpRequest(method string, rawURL string, rawBody []byte, disableRetry ...bool) (rawResp rawResponse, err error) { - disableRetryBool := len(disableRetry) > 0 && disableRetry[0] +func (ud *uiaDriver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { for retryCount := 1; retryCount <= 5; retryCount++ { - rawResp, err = ud.Driver.httpRequest(method, rawURL, rawBody) - if err == nil || disableRetryBool { + rawResp, err = ud.Driver.Request(method, rawURL, rawBody) + if err == nil { return } // wait for UIA2 server to resume automatically @@ -120,10 +119,6 @@ func (ud *uiaDriver) httpGET(pathElem ...string) (rawResp rawResponse, err error return ud.httpRequest(http.MethodGet, ud.concatURL(nil, pathElem...), nil) } -func (ud *uiaDriver) httpGETWithRetry(pathElem ...string) (rawResp rawResponse, err error) { - return ud.httpRequest(http.MethodGet, ud.concatURL(nil, pathElem...), nil, true) -} - func (ud *uiaDriver) httpPOST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) { var bsJSON []byte = nil if data != nil { @@ -147,7 +142,7 @@ func (ud *uiaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI } else { data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities} } - if rawResp, err = ud.Driver.httpPOST(data, "/session"); err != nil { + if rawResp, err = ud.Driver.POST(data, "/session"); err != nil { return SessionInfo{SessionId: ""}, err } reply := new(struct{ Value struct{ SessionId string } }) @@ -175,7 +170,8 @@ func (ud *uiaDriver) DeleteSession() (err error) { func (ud *uiaDriver) Status() (deviceStatus DeviceStatus, err error) { // register(getHandler, new Status("/wd/hub/status")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/status"); err != nil { + // Notice: use Driver.GET instead of httpGET to avoid loop calling + if rawResp, err = ud.Driver.GET("/status"); err != nil { return DeviceStatus{Ready: false}, err } reply := new(struct { diff --git a/hrp/pkg/uixt/client.go b/hrp/pkg/uixt/client.go index 5fd2fe16..bad3b723 100644 --- a/hrp/pkg/uixt/client.go +++ b/hrp/pkg/uixt/client.go @@ -94,25 +94,25 @@ func (wd *Driver) concatURL(u *url.URL, elem ...string) string { return tmp.String() } -func (wd *Driver) httpGET(pathElem ...string) (rawResp rawResponse, err error) { - return wd.httpRequest(http.MethodGet, wd.concatURL(nil, pathElem...), nil) +func (wd *Driver) GET(pathElem ...string) (rawResp rawResponse, err error) { + return wd.Request(http.MethodGet, wd.concatURL(nil, pathElem...), nil) } -func (wd *Driver) httpPOST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) { +func (wd *Driver) POST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) { var bsJSON []byte = nil if data != nil { if bsJSON, err = json.Marshal(data); err != nil { return nil, err } } - return wd.httpRequest(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON) + return wd.Request(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON) } -func (wd *Driver) httpDELETE(pathElem ...string) (rawResp rawResponse, err error) { - return wd.httpRequest(http.MethodDelete, wd.concatURL(nil, pathElem...), nil) +func (wd *Driver) DELETE(pathElem ...string) (rawResp rawResponse, err error) { + return wd.Request(http.MethodDelete, wd.concatURL(nil, pathElem...), nil) } -func (wd *Driver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { +func (wd *Driver) Request(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) { driverResult := &DriverResult{ RequestMethod: method, RequestUrl: rawURL, diff --git a/hrp/pkg/uixt/ios_stub_driver.go b/hrp/pkg/uixt/ios_stub_driver.go index 82b20624..188c320c 100644 --- a/hrp/pkg/uixt/ios_stub_driver.go +++ b/hrp/pkg/uixt/ios_stub_driver.go @@ -448,7 +448,7 @@ func (s *stubIOSDriver) GetDriverResults() []*DriverResult { } func (s *stubIOSDriver) Source(srcOpt ...SourceOption) (string, error) { - resp, err := s.Driver.httpRequest(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{}) + resp, err := s.Driver.Request(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{}) if err != nil { return "", err } @@ -470,7 +470,7 @@ func (s *stubIOSDriver) LoginNoneUI(packageName, phoneNumber string, captcha, pa if err != nil { return info, err } - resp, err := s.Driver.httpRequest(http.MethodPost, fmt.Sprintf("%s/host/login/account/", s.serverPrefix), bsJSON) + resp, err := s.Driver.Request(http.MethodPost, fmt.Sprintf("%s/host/login/account/", s.serverPrefix), bsJSON) if err != nil { return info, err } @@ -494,7 +494,7 @@ func (s *stubIOSDriver) LoginNoneUI(packageName, phoneNumber string, captcha, pa } func (s *stubIOSDriver) LogoutNoneUI(packageName string) error { - resp, err := s.Driver.httpRequest(http.MethodGet, fmt.Sprintf("%s/host/loginout/", s.serverPrefix), []byte{}) + resp, err := s.Driver.Request(http.MethodGet, fmt.Sprintf("%s/host/loginout/", s.serverPrefix), []byte{}) if err != nil { return err } @@ -518,7 +518,7 @@ func (s *stubIOSDriver) TearDown() error { } func (s *stubIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo, err error) { - resp, err := s.Driver.httpRequest(http.MethodGet, fmt.Sprintf("%s/host/app/info/", s.serverPrefix), []byte{}) + resp, err := s.Driver.Request(http.MethodGet, fmt.Sprintf("%s/host/app/info/", s.serverPrefix), []byte{}) if err != nil { return info, err } diff --git a/hrp/pkg/uixt/ios_wda_driver.go b/hrp/pkg/uixt/ios_wda_driver.go index 30f56f78..18227aaf 100644 --- a/hrp/pkg/uixt/ios_wda_driver.go +++ b/hrp/pkg/uixt/ios_wda_driver.go @@ -51,7 +51,7 @@ func (wd *wdaDriver) resetSession() error { 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.Driver.httpRequest(method, rawURL, rawBody) + rawResp, err = wd.Driver.Request(method, rawURL, rawBody) if err == nil { return } @@ -139,7 +139,8 @@ func (wd *wdaDriver) DeleteSession() (err error) { func (wd *wdaDriver) Status() (deviceStatus DeviceStatus, err error) { // [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/status"); err != nil { + // Notice: use Driver.GET instead of httpGET to avoid loop calling + if rawResp, err = wd.Driver.GET("/status"); err != nil { return DeviceStatus{}, err } reply := new(struct{ Value struct{ DeviceStatus } })