Merge branch 'dev-v4.3' of https://github.com/httprunner/httprunner into dev-v4.3

This commit is contained in:
debugtalk
2022-10-17 16:46:42 +08:00
15 changed files with 349 additions and 236 deletions
+17 -28
View File
@@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/code"
"github.com/httprunner/httprunner/v4/hrp/internal/json"
)
@@ -379,12 +380,10 @@ func (wd *wdaDriver) TapFloat(x, y float64, options ...DataOption) (err error) {
"x": x,
"y": y,
}
// append options in post data for extra WDA configurations
// e.g. add identifier in tap event logs
for _, option := range options {
option(data)
}
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/tap/0")
// new data options in post data for extra WDA configurations
d := NewData(data, options...)
_, err = wd.httpPOST(d.Data, "/session", wd.sessionId, "/wda/tap/0")
return
}
@@ -433,26 +432,20 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
"toY": toY,
}
// append options in post data for extra WDA configurations
// e.g. use WithPressDuration to set pressForDuration
for _, option := range options {
option(data)
}
// new data options in post data for extra WDA configurations
d := NewData(data, options...)
if _, ok := data["duration"]; !ok {
data["duration"] = 1.0 // default duration
}
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/dragfromtoforduration")
_, err = wd.httpPOST(d.Data, "/session", wd.sessionId, "/wda/dragfromtoforduration")
return
}
func (wd *wdaDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
options = append(options, WithPressDuration(0))
options = append(options, WithDataPressDuration(0))
return wd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
}
func (wd *wdaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error {
options = append(options, WithPressDuration(0))
options = append(options, WithDataPressDuration(0))
return wd.DragFloat(fromX, fromY, toX, toY, options...)
}
@@ -514,16 +507,10 @@ func (wd *wdaDriver) SendKeys(text string, options ...DataOption) (err error) {
// [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)]
data := map[string]interface{}{"value": strings.Split(text, "")}
// append options in post data for extra WDA configurations
// e.g. use WithFrequency to set frequency of typing
for _, option := range options {
option(data)
}
// new data options in post data for extra WDA configurations
d := NewData(data, options...)
if _, ok := data["frequency"]; !ok {
data["frequency"] = 60 // default frequency
}
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/keys")
_, err = wd.httpPOST(d.Data, "/session", wd.sessionId, "/wda/keys")
return
}
@@ -721,11 +708,13 @@ func (wd *wdaDriver) Screenshot() (raw *bytes.Buffer, err error) {
// [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)]
var rawResp rawResponse
if rawResp, err = wd.httpGET("/session", wd.sessionId, "/screenshot"); err != nil {
return nil, errors.Wrap(err, "get WDA screenshot data failed")
return nil, errors.Wrap(code.IOSScreenShotError,
fmt.Sprintf("get WDA screenshot data failed: %v", err))
}
if raw, err = rawResp.valueDecodeAsBase64(); err != nil {
return nil, errors.Wrap(err, "decode WDA screenshot data failed")
return nil, errors.Wrap(code.IOSScreenShotError,
fmt.Sprintf("decode WDA screenshot data failed: %v", err))
}
return
}