mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 22:13:13 +08:00
fix: swipe with params
This commit is contained in:
@@ -151,9 +151,6 @@ func convertCompatMobileStep(mobileUI *MobileUI) {
|
|||||||
if ma.Method == uixt.ACTION_SwipeToTapText && actionOptions.MaxRetryTimes == 0 {
|
if ma.Method == uixt.ACTION_SwipeToTapText && actionOptions.MaxRetryTimes == 0 {
|
||||||
ma.ActionOptions.MaxRetryTimes = 10
|
ma.ActionOptions.MaxRetryTimes = 10
|
||||||
}
|
}
|
||||||
if ma.Method == uixt.ACTION_Swipe {
|
|
||||||
ma.ActionOptions.Direction = ma.Params
|
|
||||||
}
|
|
||||||
mobileUI.Actions[i] = ma
|
mobileUI.Actions[i] = ma
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,12 +195,12 @@ func Interface2Float64(i interface{}) (float64, error) {
|
|||||||
return float64(v), nil
|
return float64(v), nil
|
||||||
case float64:
|
case float64:
|
||||||
return v, nil
|
return v, nil
|
||||||
case string:
|
case string: // e.g. "1", "0.5"
|
||||||
floatVar, err := strconv.ParseFloat(v, 64)
|
floatVar, err := strconv.ParseFloat(v, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return floatVar, err
|
return floatVar, nil
|
||||||
}
|
}
|
||||||
// json.Number
|
// json.Number
|
||||||
value, ok := i.(builtinJSON.Number)
|
value, ok := i.(builtinJSON.Number)
|
||||||
|
|||||||
96
internal/builtin/utils_test.go
Normal file
96
internal/builtin/utils_test.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package builtin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInterface2Float64(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input interface{}
|
||||||
|
want float64
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "convert int",
|
||||||
|
input: 42,
|
||||||
|
want: 42.0,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert int32",
|
||||||
|
input: int32(42),
|
||||||
|
want: 42.0,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert int64",
|
||||||
|
input: int64(42),
|
||||||
|
want: 42.0,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert float32",
|
||||||
|
input: float32(42.5),
|
||||||
|
want: 42.5,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert float64",
|
||||||
|
input: 42.5,
|
||||||
|
want: 42.5,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert string valid number",
|
||||||
|
input: "42.5",
|
||||||
|
want: 42.5,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert string valid number",
|
||||||
|
input: "425",
|
||||||
|
want: 425.0,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert string invalid number",
|
||||||
|
input: "invalid",
|
||||||
|
want: 0,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert json.Number valid",
|
||||||
|
input: json.Number("42.5"),
|
||||||
|
want: 42.5,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert json.Number invalid",
|
||||||
|
input: json.Number("invalid"),
|
||||||
|
want: 0,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "convert unsupported type",
|
||||||
|
input: []int{1, 2, 3},
|
||||||
|
want: 0,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := Interface2Float64(tt.input)
|
||||||
|
if tt.wantErr {
|
||||||
|
assert.Error(t, err)
|
||||||
|
} else {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, tt.want, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2505122246
|
v5.0.0-beta-2505141436
|
||||||
|
|||||||
@@ -306,6 +306,13 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
} else if sd, ok := action.Params.(SleepConfig); ok {
|
} else if sd, ok := action.Params.(SleepConfig); ok {
|
||||||
sleepStrict(sd.StartTime, int64(sd.Seconds*1000))
|
sleepStrict(sd.StartTime, int64(sd.Seconds*1000))
|
||||||
return nil
|
return nil
|
||||||
|
} else if param, ok := action.Params.(string); ok {
|
||||||
|
seconds, err := builtin.ConvertToFloat64(param)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "invalid sleep params: %v(%T)", action.Params, action.Params)
|
||||||
|
}
|
||||||
|
time.Sleep(time.Duration(seconds*1000) * time.Millisecond)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid sleep params: %v(%T)", action.Params, action.Params)
|
return fmt.Errorf("invalid sleep params: %v(%T)", action.Params, action.Params)
|
||||||
case ACTION_SleepMS:
|
case ACTION_SleepMS:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActionOptions struct {
|
type ActionOptions struct {
|
||||||
@@ -72,10 +73,22 @@ func (o *ActionOptions) Options() []ActionOption {
|
|||||||
case []interface{}:
|
case []interface{}:
|
||||||
// loaded from json case
|
// loaded from json case
|
||||||
// custom direction: [fromX, fromY, toX, toY]
|
// custom direction: [fromX, fromY, toX, toY]
|
||||||
sx, _ := builtin.Interface2Float64(v[0])
|
sx, err := builtin.Interface2Float64(v[0])
|
||||||
sy, _ := builtin.Interface2Float64(v[1])
|
if err != nil {
|
||||||
ex, _ := builtin.Interface2Float64(v[2])
|
log.Error().Err(err).Interface("fromX", v[0]).Msg("convert float64 failed")
|
||||||
ey, _ := builtin.Interface2Float64(v[3])
|
}
|
||||||
|
sy, err := builtin.Interface2Float64(v[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Interface("fromY", v[1]).Msg("convert float64 failed")
|
||||||
|
}
|
||||||
|
ex, err := builtin.Interface2Float64(v[2])
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Interface("toX", v[2]).Msg("convert float64 failed")
|
||||||
|
}
|
||||||
|
ey, err := builtin.Interface2Float64(v[3])
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Interface("toY", v[3]).Msg("convert float64 failed")
|
||||||
|
}
|
||||||
options = append(options, WithCustomDirection(
|
options = append(options, WithCustomDirection(
|
||||||
sx, sy,
|
sx, sy,
|
||||||
ex, ey,
|
ex, ey,
|
||||||
|
|||||||
Reference in New Issue
Block a user