mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
feat: ApplyOffset for tap xy
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2502182234
|
v5.0.0+2502191055
|
||||||
|
|||||||
@@ -298,6 +298,9 @@ func (ad *ADBDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
|
||||||
// adb shell input tap x y
|
// adb shell input tap x y
|
||||||
xStr := fmt.Sprintf("%.1f", x)
|
xStr := fmt.Sprintf("%.1f", x)
|
||||||
yStr := fmt.Sprintf("%.1f", y)
|
yStr := fmt.Sprintf("%.1f", y)
|
||||||
@@ -314,6 +317,9 @@ func (ad *ADBDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) erro
|
|||||||
if x, y, err = convertToAbsolutePoint(ad, x, y); err != nil {
|
if x, y, err = convertToAbsolutePoint(ad, x, y); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
|
||||||
// adb shell input tap x y
|
// adb shell input tap x y
|
||||||
xStr := fmt.Sprintf("%.1f", x)
|
xStr := fmt.Sprintf("%.1f", x)
|
||||||
yStr := fmt.Sprintf("%.1f", y)
|
yStr := fmt.Sprintf("%.1f", y)
|
||||||
@@ -333,13 +339,7 @@ func (ad *ADBDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) erro
|
|||||||
|
|
||||||
func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
|
func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
if len(actionOptions.Offset) == 2 {
|
|
||||||
x += float64(actionOptions.Offset[0])
|
|
||||||
y += float64(actionOptions.Offset[1])
|
|
||||||
}
|
|
||||||
x += actionOptions.GetRandomOffset()
|
|
||||||
y += actionOptions.GetRandomOffset()
|
|
||||||
duration := 1000.0
|
duration := 1000.0
|
||||||
if actionOptions.Duration > 0 {
|
if actionOptions.Duration > 0 {
|
||||||
duration = actionOptions.Duration * 1000
|
duration = actionOptions.Duration * 1000
|
||||||
|
|||||||
@@ -246,6 +246,9 @@ func (ud *UIA2Driver) DoubleTapXY(x, y float64, opts ...option.ActionOption) err
|
|||||||
if x, y, err = convertToAbsolutePoint(ud, x, y); err != nil {
|
if x, y, err = convertToAbsolutePoint(ud, x, y); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"actions": []interface{}{
|
"actions": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
@@ -279,6 +282,7 @@ func (ud *UIA2Driver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
|||||||
func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
|
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
|
||||||
duration := 100.0
|
duration := 100.0
|
||||||
if actionOptions.PressDuration > 0 {
|
if actionOptions.PressDuration > 0 {
|
||||||
@@ -306,8 +310,9 @@ func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
|
func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
|
||||||
actionOpts := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
duration := actionOpts.Duration
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
duration := actionOptions.Duration
|
||||||
if duration == 0 {
|
if duration == 0 {
|
||||||
duration = 1.0
|
duration = 1.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,13 +106,11 @@ func (s *StubIOSDriver) Source(srcOpt ...option.SourceOption) (string, error) {
|
|||||||
|
|
||||||
func (s *StubIOSDriver) OpenUrl(urlStr string, options ...option.ActionOption) (err error) {
|
func (s *StubIOSDriver) OpenUrl(urlStr string, options ...option.ActionOption) (err error) {
|
||||||
targetUrl := fmt.Sprintf("/openURL?url=%s", url.QueryEscape(urlStr))
|
targetUrl := fmt.Sprintf("/openURL?url=%s", url.QueryEscape(urlStr))
|
||||||
fmt.Sprintln(targetUrl)
|
_, err = s.Session.GET(targetUrl)
|
||||||
resp, err := s.Session.GET(targetUrl)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("get source err")
|
log.Error().Err(err).Msg("get source err")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
fmt.Sprintln(resp)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ func (hd *HDCDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
|||||||
|
|
||||||
func (hd *HDCDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
func (hd *HDCDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
|
||||||
if actionOptions.Identifier != "" {
|
if actionOptions.Identifier != "" {
|
||||||
startTime := int(time.Now().UnixMilli())
|
startTime := int(time.Now().UnixMilli())
|
||||||
|
|||||||
@@ -566,6 +566,8 @@ func (wd *WDADriver) TapXY(x, y float64, opts ...option.ActionOption) error {
|
|||||||
|
|
||||||
func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
|
||||||
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"x": wd.toScale(x),
|
"x": wd.toScale(x),
|
||||||
"y": wd.toScale(y),
|
"y": wd.toScale(y),
|
||||||
@@ -582,6 +584,8 @@ func (wd *WDADriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) erro
|
|||||||
if x, y, err = convertToAbsolutePoint(wd, x, y); err != nil {
|
if x, y, err = convertToAbsolutePoint(wd, x, y); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
|
|
||||||
x = wd.toScale(x)
|
x = wd.toScale(x)
|
||||||
y = wd.toScale(y)
|
y = wd.toScale(y)
|
||||||
@@ -596,6 +600,7 @@ func (wd *WDADriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) erro
|
|||||||
// FIXME: hold not work
|
// FIXME: hold not work
|
||||||
func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
|
func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
x, y = actionOptions.ApplyOffset(x, y)
|
||||||
if actionOptions.Duration == 0 {
|
if actionOptions.Duration == 0 {
|
||||||
opts = append(opts, option.WithPressDuration(1))
|
opts = append(opts, option.WithPressDuration(1))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,17 @@ func (o *ActionOptions) GetScreenOptions() []ActionOption {
|
|||||||
return o.ScreenOptions.Options()
|
return o.ScreenOptions.Options()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ActionOptions) GetRandomOffset() float64 {
|
func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) {
|
||||||
|
if len(o.Offset) == 2 {
|
||||||
|
absX += float64(o.Offset[0])
|
||||||
|
absY += float64(o.Offset[1])
|
||||||
|
}
|
||||||
|
absX += o.GenerateRandomOffset()
|
||||||
|
absY += o.GenerateRandomOffset()
|
||||||
|
return absX, absY
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *ActionOptions) GenerateRandomOffset() float64 {
|
||||||
if len(o.OffsetRandomRange) != 2 {
|
if len(o.OffsetRandomRange) != 2 {
|
||||||
// invalid offset random range, should be [min, max]
|
// invalid offset random range, should be [min, max]
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user