mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
refactor: rename files
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2502061808
|
v5.0.0+2502061953
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type adbDriver struct {
|
type adbDriver struct {
|
||||||
Driver
|
DriverClient
|
||||||
|
|
||||||
adbClient *gadb.Device
|
adbClient *gadb.Device
|
||||||
logcat *AdbLogcat
|
logcat *AdbLogcat
|
||||||
@@ -80,7 +80,7 @@ func (ad *adbDriver) runShellCommand(cmd string, args ...string) (output string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) NewSession(capabilities option.Capabilities) (sessionInfo SessionInfo, err error) {
|
func (ad *adbDriver) NewSession(capabilities option.Capabilities) (sessionInfo SessionInfo, err error) {
|
||||||
ad.Driver.session.Reset()
|
ad.DriverClient.session.Reset()
|
||||||
err = errDriverNotImplemented
|
err = errDriverNotImplemented
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -863,7 +863,7 @@ func (ad *adbDriver) StopCaptureLog() (result interface{}, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) GetSession() *DriverSession {
|
func (ad *adbDriver) GetSession() *DriverSession {
|
||||||
return &ad.Driver.session
|
return &ad.DriverClient.session
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) GetDriverResults() []*DriverResult {
|
func (ad *adbDriver) GetDriverResults() []*DriverResult {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func (sad *stubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (ra
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sad *stubAndroidDriver) NewSession(capabilities option.Capabilities) (SessionInfo, error) {
|
func (sad *stubAndroidDriver) NewSession(capabilities option.Capabilities) (SessionInfo, error) {
|
||||||
sad.Driver.session.Reset()
|
sad.DriverClient.session.Reset()
|
||||||
return SessionInfo{}, errDriverNotImplemented
|
return SessionInfo{}, errDriverNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (ud *uiaDriver) resetDriver() error {
|
|||||||
|
|
||||||
func (ud *uiaDriver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) {
|
func (ud *uiaDriver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) {
|
||||||
for retryCount := 1; retryCount <= 5; retryCount++ {
|
for retryCount := 1; retryCount <= 5; retryCount++ {
|
||||||
rawResp, err = ud.Driver.Request(method, rawURL, rawBody)
|
rawResp, err = ud.DriverClient.Request(method, rawURL, rawBody)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ func (ud *uiaDriver) NewSession(capabilities option.Capabilities) (sessionInfo S
|
|||||||
} else {
|
} else {
|
||||||
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
|
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
|
||||||
}
|
}
|
||||||
if rawResp, err = ud.Driver.POST(data, "/session"); err != nil {
|
if rawResp, err = ud.DriverClient.POST(data, "/session"); err != nil {
|
||||||
return SessionInfo{SessionId: ""}, err
|
return SessionInfo{SessionId: ""}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ SessionId string } })
|
reply := new(struct{ Value struct{ SessionId string } })
|
||||||
@@ -151,8 +151,8 @@ func (ud *uiaDriver) NewSession(capabilities option.Capabilities) (sessionInfo S
|
|||||||
return SessionInfo{SessionId: ""}, err
|
return SessionInfo{SessionId: ""}, err
|
||||||
}
|
}
|
||||||
sessionID := reply.Value.SessionId
|
sessionID := reply.Value.SessionId
|
||||||
ud.Driver.session.Reset()
|
ud.DriverClient.session.Reset()
|
||||||
ud.Driver.session.ID = sessionID
|
ud.DriverClient.session.ID = sessionID
|
||||||
// d.sessionIdCache[sessionID] = true
|
// d.sessionIdCache[sessionID] = true
|
||||||
return SessionInfo{SessionId: sessionID}, nil
|
return SessionInfo{SessionId: sessionID}, nil
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ func (ud *uiaDriver) Status() (deviceStatus DeviceStatus, err error) {
|
|||||||
// register(getHandler, new Status("/wd/hub/status"))
|
// register(getHandler, new Status("/wd/hub/status"))
|
||||||
var rawResp rawResponse
|
var rawResp rawResponse
|
||||||
// Notice: use Driver.GET instead of httpGET to avoid loop calling
|
// Notice: use Driver.GET instead of httpGET to avoid loop calling
|
||||||
if rawResp, err = ud.Driver.GET("/status"); err != nil {
|
if rawResp, err = ud.DriverClient.GET("/status"); err != nil {
|
||||||
return DeviceStatus{Ready: false}, err
|
return DeviceStatus{Ready: false}, err
|
||||||
}
|
}
|
||||||
reply := new(struct {
|
reply := new(struct {
|
||||||
@@ -650,7 +650,7 @@ func (ud *uiaDriver) TapByTexts(actions ...TapTextAction) error {
|
|||||||
|
|
||||||
func (ud *uiaDriver) GetDriverResults() []*DriverResult {
|
func (ud *uiaDriver) GetDriverResults() []*DriverResult {
|
||||||
defer func() {
|
defer func() {
|
||||||
ud.Driver.driverResults = nil
|
ud.DriverClient.driverResults = nil
|
||||||
}()
|
}()
|
||||||
return ud.Driver.driverResults
|
return ud.DriverClient.driverResults
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -220,19 +220,6 @@ func (d *DriverSession) Get(withReset bool) Attachments {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
type Driver struct {
|
|
||||||
urlPrefix *url.URL
|
|
||||||
client *http.Client
|
|
||||||
|
|
||||||
// cache to avoid repeated query
|
|
||||||
scale float64
|
|
||||||
windowSize Size
|
|
||||||
driverResults []*DriverResult
|
|
||||||
|
|
||||||
// cache session data
|
|
||||||
session DriverSession
|
|
||||||
}
|
|
||||||
|
|
||||||
type DriverResult struct {
|
type DriverResult struct {
|
||||||
RequestMethod string `json:"request_method"`
|
RequestMethod string `json:"request_method"`
|
||||||
RequestUrl string `json:"request_url"`
|
RequestUrl string `json:"request_url"`
|
||||||
@@ -246,7 +233,20 @@ type DriverResult struct {
|
|||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *Driver) concatURL(u *url.URL, elem ...string) string {
|
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 {
|
||||||
var tmp *url.URL
|
var tmp *url.URL
|
||||||
if u == nil {
|
if u == nil {
|
||||||
u = wd.urlPrefix
|
u = wd.urlPrefix
|
||||||
@@ -256,11 +256,11 @@ func (wd *Driver) concatURL(u *url.URL, elem ...string) string {
|
|||||||
return tmp.String()
|
return tmp.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *Driver) GET(pathElem ...string) (rawResp rawResponse, err error) {
|
func (wd *DriverClient) GET(pathElem ...string) (rawResp rawResponse, err error) {
|
||||||
return wd.Request(http.MethodGet, wd.concatURL(nil, pathElem...), nil)
|
return wd.Request(http.MethodGet, wd.concatURL(nil, pathElem...), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *Driver) POST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) {
|
func (wd *DriverClient) POST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) {
|
||||||
var bsJSON []byte = nil
|
var bsJSON []byte = nil
|
||||||
if data != nil {
|
if data != nil {
|
||||||
if bsJSON, err = json.Marshal(data); err != nil {
|
if bsJSON, err = json.Marshal(data); err != nil {
|
||||||
@@ -270,11 +270,11 @@ func (wd *Driver) POST(data interface{}, pathElem ...string) (rawResp rawRespons
|
|||||||
return wd.Request(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON)
|
return wd.Request(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *Driver) DELETE(pathElem ...string) (rawResp rawResponse, err error) {
|
func (wd *DriverClient) DELETE(pathElem ...string) (rawResp rawResponse, err error) {
|
||||||
return wd.Request(http.MethodDelete, wd.concatURL(nil, pathElem...), nil)
|
return wd.Request(http.MethodDelete, wd.concatURL(nil, pathElem...), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *Driver) Request(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) {
|
func (wd *DriverClient) Request(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) {
|
||||||
driverResult := &DriverResult{
|
driverResult := &DriverResult{
|
||||||
RequestMethod: method,
|
RequestMethod: method,
|
||||||
RequestUrl: rawURL,
|
RequestUrl: rawURL,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
type hdcDriver struct {
|
type hdcDriver struct {
|
||||||
points []ExportPoint
|
points []ExportPoint
|
||||||
Driver
|
DriverClient
|
||||||
device *ghdc.Device
|
device *ghdc.Device
|
||||||
uiDriver *ghdc.UIDriver
|
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) {
|
func (hd *hdcDriver) NewSession(capabilities option.Capabilities) (SessionInfo, error) {
|
||||||
hd.Driver.session.Reset()
|
hd.DriverClient.session.Reset()
|
||||||
hd.Unlock()
|
hd.Unlock()
|
||||||
return SessionInfo{}, errDriverNotImplemented
|
return SessionInfo{}, errDriverNotImplemented
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ func (hd *hdcDriver) DeleteSession() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hd *hdcDriver) GetSession() *DriverSession {
|
func (hd *hdcDriver) GetSession() *DriverSession {
|
||||||
return &hd.Driver.session
|
return &hd.DriverClient.session
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hd *hdcDriver) Status() (DeviceStatus, error) {
|
func (hd *hdcDriver) Status() (DeviceStatus, error) {
|
||||||
|
|||||||
+11
-10
@@ -13,12 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type stubIOSDriver struct {
|
type stubIOSDriver struct {
|
||||||
|
*wdaDriver
|
||||||
|
DriverClient
|
||||||
|
|
||||||
bightInsightPrefix string
|
bightInsightPrefix string
|
||||||
serverPrefix string
|
serverPrefix string
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
Driver
|
device *IOSDevice
|
||||||
*wdaDriver
|
|
||||||
device *IOSDevice
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStubIOSDriver(bightInsightAddr, serverAddr string, dev *IOSDevice, readTimeout ...time.Duration) (*stubIOSDriver, error) {
|
func newStubIOSDriver(bightInsightAddr, serverAddr string, dev *IOSDevice, readTimeout ...time.Duration) (*stubIOSDriver, error) {
|
||||||
@@ -31,7 +32,7 @@ func newStubIOSDriver(bightInsightAddr, serverAddr string, dev *IOSDevice, readT
|
|||||||
driver.bightInsightPrefix = bightInsightAddr
|
driver.bightInsightPrefix = bightInsightAddr
|
||||||
driver.serverPrefix = serverAddr
|
driver.serverPrefix = serverAddr
|
||||||
driver.timeout = timeout
|
driver.timeout = timeout
|
||||||
driver.Driver.client = &http.Client{
|
driver.DriverClient.client = &http.Client{
|
||||||
Timeout: time.Second * 10, // 设置超时时间为 10 秒
|
Timeout: time.Second * 10, // 设置超时时间为 10 秒
|
||||||
}
|
}
|
||||||
return driver, nil
|
return driver, nil
|
||||||
@@ -450,7 +451,7 @@ func (s *stubIOSDriver) GetDriverResults() []*DriverResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubIOSDriver) Source(srcOpt ...SourceOption) (string, error) {
|
func (s *stubIOSDriver) Source(srcOpt ...SourceOption) (string, error) {
|
||||||
resp, err := s.Driver.Request(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{})
|
resp, err := s.DriverClient.Request(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -472,7 +473,7 @@ func (s *stubIOSDriver) LoginNoneUI(packageName, phoneNumber string, captcha, pa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
resp, err := s.Driver.Request(http.MethodPost, fmt.Sprintf("%s/host/login/account/", s.serverPrefix), bsJSON)
|
resp, err := s.DriverClient.Request(http.MethodPost, fmt.Sprintf("%s/host/login/account/", s.serverPrefix), bsJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
@@ -496,7 +497,7 @@ func (s *stubIOSDriver) LoginNoneUI(packageName, phoneNumber string, captcha, pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubIOSDriver) LogoutNoneUI(packageName string) error {
|
func (s *stubIOSDriver) LogoutNoneUI(packageName string) error {
|
||||||
resp, err := s.Driver.Request(http.MethodGet, fmt.Sprintf("%s/host/loginout/", s.serverPrefix), []byte{})
|
resp, err := s.DriverClient.Request(http.MethodGet, fmt.Sprintf("%s/host/loginout/", s.serverPrefix), []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -515,12 +516,12 @@ func (s *stubIOSDriver) LogoutNoneUI(packageName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubIOSDriver) TearDown() error {
|
func (s *stubIOSDriver) TearDown() error {
|
||||||
s.Driver.client.CloseIdleConnections()
|
s.DriverClient.client.CloseIdleConnections()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo, err error) {
|
func (s *stubIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo, err error) {
|
||||||
resp, err := s.Driver.Request(http.MethodGet, fmt.Sprintf("%s/host/app/info/", s.serverPrefix), []byte{})
|
resp, err := s.DriverClient.Request(http.MethodGet, fmt.Sprintf("%s/host/app/info/", s.serverPrefix), []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
@@ -542,5 +543,5 @@ func (s *stubIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubIOSDriver) GetSession() *DriverSession {
|
func (s *stubIOSDriver) GetSession() *DriverSession {
|
||||||
return &s.Driver.session
|
return &s.DriverClient.session
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type wdaDriver struct {
|
type wdaDriver struct {
|
||||||
Driver
|
DriverClient
|
||||||
udid string
|
udid string
|
||||||
device *IOSDevice
|
device *IOSDevice
|
||||||
mjpegHTTPConn net.Conn // via HTTP
|
mjpegHTTPConn net.Conn // via HTTP
|
||||||
@@ -47,7 +47,7 @@ func (wd *wdaDriver) resetSession() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notice: use Driver.POST instead of httpPOST to avoid loop calling
|
// Notice: use Driver.POST instead of httpPOST to avoid loop calling
|
||||||
rawResp, err := wd.Driver.POST(data, "/session")
|
rawResp, err := wd.DriverClient.POST(data, "/session")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func (wd *wdaDriver) resetSession() error {
|
|||||||
func (wd *wdaDriver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) {
|
func (wd *wdaDriver) httpRequest(method string, rawURL string, rawBody []byte) (rawResp rawResponse, err error) {
|
||||||
retryInterval := 3 * time.Second
|
retryInterval := 3 * time.Second
|
||||||
for retryCount := 1; retryCount <= 3; retryCount++ {
|
for retryCount := 1; retryCount <= 3; retryCount++ {
|
||||||
rawResp, err = wd.Driver.Request(method, rawURL, rawBody)
|
rawResp, err = wd.DriverClient.Request(method, rawURL, rawBody)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ func (wd *wdaDriver) Status() (deviceStatus DeviceStatus, err error) {
|
|||||||
// [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)]
|
// [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)]
|
||||||
var rawResp rawResponse
|
var rawResp rawResponse
|
||||||
// Notice: use Driver.GET instead of httpGET to avoid loop calling
|
// Notice: use Driver.GET instead of httpGET to avoid loop calling
|
||||||
if rawResp, err = wd.Driver.GET("/status"); err != nil {
|
if rawResp, err = wd.DriverClient.GET("/status"); err != nil {
|
||||||
return DeviceStatus{}, err
|
return DeviceStatus{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ DeviceStatus } })
|
reply := new(struct{ Value struct{ DeviceStatus } })
|
||||||
@@ -1009,14 +1009,14 @@ func (wd *wdaDriver) StopCaptureLog() (result interface{}, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) GetSession() *DriverSession {
|
func (wd *wdaDriver) GetSession() *DriverSession {
|
||||||
return &wd.Driver.session
|
return &wd.DriverClient.session
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) GetDriverResults() []*DriverResult {
|
func (wd *wdaDriver) GetDriverResults() []*DriverResult {
|
||||||
defer func() {
|
defer func() {
|
||||||
wd.Driver.driverResults = nil
|
wd.DriverClient.driverResults = nil
|
||||||
}()
|
}()
|
||||||
return wd.Driver.driverResults
|
return wd.DriverClient.driverResults
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) TearDown() error {
|
func (wd *wdaDriver) TearDown() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user