mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-28 20:09:36 +08:00
fix: init wda driver
This commit is contained in:
@@ -334,15 +334,6 @@ func (r DriverRawResponse) ValueConvertToBool() (b bool, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (r DriverRawResponse) ValueConvertToSessionInfo() (sessionInfo DriverSession, err error) {
|
||||
reply := new(struct{ Value struct{ DriverSession } })
|
||||
if err = json.Unmarshal(r, reply); err != nil {
|
||||
return DriverSession{}, err
|
||||
}
|
||||
sessionInfo = reply.Value.DriverSession
|
||||
return
|
||||
}
|
||||
|
||||
func (r DriverRawResponse) ValueConvertToJsonRawMessage() (raw builtinJSON.RawMessage, err error) {
|
||||
reply := new(struct{ Value builtinJSON.RawMessage })
|
||||
if err = json.Unmarshal(r, reply); err != nil {
|
||||
|
||||
@@ -36,16 +36,8 @@ func NewWDADriver(device *IOSDevice) (*WDADriver, error) {
|
||||
Device: device,
|
||||
Session: NewDriverSession(),
|
||||
}
|
||||
err := driver.InitSession(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// init WDA scale
|
||||
if driver.scale, err = driver.Scale(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var err error
|
||||
// forward local port to device
|
||||
var localPort int
|
||||
localPort, err = strconv.Atoi(os.Getenv("WDA_LOCAL_PORT"))
|
||||
@@ -97,6 +89,11 @@ func NewWDADriver(device *IOSDevice) (*WDADriver, error) {
|
||||
driver.mjpegClient = NewHTTPClientWithConnection(driver.mjpegHTTPConn, 30*time.Second)
|
||||
driver.mjpegUrl = fmt.Sprintf("%s:%d", host, localMjpegPort)
|
||||
|
||||
// init WDA scale
|
||||
if driver.scale, err = driver.Scale(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
@@ -129,12 +126,12 @@ func (wd *WDADriver) InitSession(capabilities option.Capabilities) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sessionInfo, err := rawResp.ValueConvertToSessionInfo()
|
||||
if err != nil {
|
||||
reply := new(struct{ Value struct{ SessionId string } })
|
||||
if err = json.Unmarshal(rawResp, reply); err != nil {
|
||||
return err
|
||||
}
|
||||
// update session ID
|
||||
wd.Session.ID = sessionInfo.ID
|
||||
wd.Session.ID = reply.Value.SessionId
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -906,8 +903,9 @@ func (wd *WDADriver) StartCaptureLog(identifier ...string) error {
|
||||
}
|
||||
|
||||
type wdaResponse struct {
|
||||
Value interface{} `json:"value"`
|
||||
Status int `json:"status"`
|
||||
SessionID string `json:"sessionId"`
|
||||
Value interface{} `json:"value"`
|
||||
}
|
||||
|
||||
func (wd *WDADriver) StopCaptureLog() (result interface{}, err error) {
|
||||
|
||||
@@ -28,8 +28,6 @@ func setup(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
capabilities := option.NewCapabilities()
|
||||
capabilities.WithDefaultAlertAction(option.AlertActionAccept)
|
||||
driver, err = device.NewDriver()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -2,6 +2,30 @@ package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
// DeviceStatus example:
|
||||
//
|
||||
// {
|
||||
// "status": 0,
|
||||
// "sessionId": "7DD3B0F7-958B-45F1-B99D-745B4EEFE178",
|
||||
// "value": {
|
||||
// "message": "WebDriverAgent is ready to accept commands",
|
||||
// "state": "success",
|
||||
// "os": {
|
||||
// "testmanagerdVersion": 28,
|
||||
// "name": "iOS",
|
||||
// "sdkVersion": "16.0",
|
||||
// "version": "15.3.1"
|
||||
// },
|
||||
// "ios": {
|
||||
// "ip": "169.254.237.64"
|
||||
// },
|
||||
// "ready": true,
|
||||
// "build": {
|
||||
// "time": "Jun 21 2024 11:11:37",
|
||||
// "productBundleIdentifier": "com.facebook.WebDriverAgentRunner"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
type DeviceStatus struct {
|
||||
Message string `json:"message"`
|
||||
State string `json:"state"`
|
||||
|
||||
Reference in New Issue
Block a user