mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 05:19:38 +08:00
compatible with old tap_cv params
This commit is contained in:
@@ -455,3 +455,31 @@ func IsZeroFloat64(f float64) bool {
|
|||||||
threshold := 1e-3
|
threshold := 1e-3
|
||||||
return math.Abs(f) < threshold
|
return math.Abs(f) < threshold
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConvertToFloat64(val interface{}) (float64, error) {
|
||||||
|
switch v := val.(type) {
|
||||||
|
case float64:
|
||||||
|
return v, nil
|
||||||
|
case int:
|
||||||
|
return float64(v), nil
|
||||||
|
case int64:
|
||||||
|
return float64(v), nil
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("invalid type for conversion to float64: %T, value: %+v", val, val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertToStringSlice(val interface{}) ([]string, error) {
|
||||||
|
if valSlice, ok := val.([]interface{}); ok {
|
||||||
|
var res []string
|
||||||
|
for _, iVal := range valSlice {
|
||||||
|
valString, ok := iVal.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("invalid type for converting one of the elements to string: %T, value: %v", iVal, iVal)
|
||||||
|
}
|
||||||
|
res = append(res, valString)
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("invalid type for conversion to []string")
|
||||||
|
}
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
|||||||
if texts, ok := action.Params.([]string); ok {
|
if texts, ok := action.Params.([]string); ok {
|
||||||
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
if texts, err := convertToStringSlice(action.Params); err == nil {
|
if texts, err := builtin.ConvertToStringSlice(action.Params); err == nil {
|
||||||
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
||||||
@@ -652,39 +652,11 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
|||||||
|
|
||||||
var errActionNotImplemented = errors.New("UI action not implemented")
|
var errActionNotImplemented = errors.New("UI action not implemented")
|
||||||
|
|
||||||
func convertToFloat64(val interface{}) (float64, error) {
|
|
||||||
switch v := val.(type) {
|
|
||||||
case float64:
|
|
||||||
return v, nil
|
|
||||||
case int:
|
|
||||||
return float64(v), nil
|
|
||||||
case int64:
|
|
||||||
return float64(v), nil
|
|
||||||
default:
|
|
||||||
return 0, fmt.Errorf("invalid type for conversion to float64: %T, value: %+v", val, val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertToStringSlice(val interface{}) ([]string, error) {
|
|
||||||
if valSlice, ok := val.([]interface{}); ok {
|
|
||||||
var res []string
|
|
||||||
for _, iVal := range valSlice {
|
|
||||||
valString, ok := iVal.(string)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("invalid type for converting one of the elements to string: %T, value: %v", iVal, iVal)
|
|
||||||
}
|
|
||||||
res = append(res, valString)
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("invalid type for conversion to []string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// getSimulationDuration returns simulation duration by given params (in seconds)
|
// getSimulationDuration returns simulation duration by given params (in seconds)
|
||||||
func getSimulationDuration(params []interface{}) (milliseconds int64) {
|
func getSimulationDuration(params []interface{}) (milliseconds int64) {
|
||||||
if len(params) == 1 {
|
if len(params) == 1 {
|
||||||
// given constant duration time
|
// given constant duration time
|
||||||
seconds, err := convertToFloat64(params[0])
|
seconds, err := builtin.ConvertToFloat64(params[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Interface("params", params).Msg("invalid params")
|
log.Error().Err(err).Interface("params", params).Msg("invalid params")
|
||||||
return 0
|
return 0
|
||||||
@@ -703,17 +675,17 @@ func getSimulationDuration(params []interface{}) (milliseconds int64) {
|
|||||||
}
|
}
|
||||||
totalProb := 0.0
|
totalProb := 0.0
|
||||||
for i := 0; i+3 <= len(params); i += 3 {
|
for i := 0; i+3 <= len(params); i += 3 {
|
||||||
min, err := convertToFloat64(params[i])
|
min, err := builtin.ConvertToFloat64(params[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Interface("min", params[i]).Msg("invalid minimum time")
|
log.Error().Err(err).Interface("min", params[i]).Msg("invalid minimum time")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
max, err := convertToFloat64(params[i+1])
|
max, err := builtin.ConvertToFloat64(params[i+1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Interface("max", params[i+1]).Msg("invalid maximum time")
|
log.Error().Err(err).Interface("max", params[i+1]).Msg("invalid maximum time")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
weight, err := convertToFloat64(params[i+2])
|
weight, err := builtin.ConvertToFloat64(params[i+2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Interface("weight", params[i+2]).Msg("invalid weight value")
|
log.Error().Err(err).Interface("weight", params[i+2]).Msg("invalid weight value")
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ITestCase represents interface for testcases,
|
// ITestCase represents interface for testcases,
|
||||||
@@ -112,6 +113,13 @@ func (tc *TCase) MakeCompat() (err error) {
|
|||||||
|
|
||||||
// 3. deal with extract expr including hyphen
|
// 3. deal with extract expr including hyphen
|
||||||
convertExtract(step.Extract)
|
convertExtract(step.Extract)
|
||||||
|
|
||||||
|
// 4. deal with mobile step compatibility
|
||||||
|
if step.Android != nil {
|
||||||
|
convertCompatMobileStep(step.Android)
|
||||||
|
} else if step.IOS != nil {
|
||||||
|
convertCompatMobileStep(step.IOS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -352,6 +360,26 @@ func convertExtract(extract map[string]string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertCompatMobileStep(mobileStep *MobileStep) {
|
||||||
|
if mobileStep == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if mobileStep.MobileAction.Method == uixt.ACTION_TapByCV {
|
||||||
|
uiTypes, _ := builtin.ConvertToStringSlice(mobileStep.MobileAction.Params)
|
||||||
|
options := mobileStep.MobileAction.ActionOptions
|
||||||
|
options.ScreenShotWithUITypes = append(options.ScreenShotWithUITypes, uiTypes...)
|
||||||
|
}
|
||||||
|
for i := 0; i < len(mobileStep.Actions); i++ {
|
||||||
|
ma := mobileStep.Actions[i]
|
||||||
|
if ma.Method != uixt.ACTION_TapByCV {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
uiTypes, _ := builtin.ConvertToStringSlice(ma.Params)
|
||||||
|
ma.ActionOptions.ScreenShotWithUITypes = append(ma.ActionOptions.ScreenShotWithUITypes, uiTypes...)
|
||||||
|
mobileStep.Actions[i] = ma
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// convertJmespathExpr deals with limited jmespath expression conversion
|
// convertJmespathExpr deals with limited jmespath expression conversion
|
||||||
func convertJmespathExpr(checkExpr string) string {
|
func convertJmespathExpr(checkExpr string) string {
|
||||||
if strings.Contains(checkExpr, textExtractorSubRegexp) {
|
if strings.Contains(checkExpr, textExtractorSubRegexp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user