Merge branch 'refactor-hrp-interface' into 'feat/yuhongzheng/harmony'

# Conflicts:
#   hrp/internal/version/VERSION
This commit is contained in:
李隆
2024-09-20 10:04:58 +00:00
11 changed files with 50 additions and 59 deletions
+4 -2
View File
@@ -24,7 +24,7 @@ var (
LoadYAMLError = errors.New("load yaml error") // 12 LoadYAMLError = errors.New("load yaml error") // 12
LoadEnvError = errors.New("load .env error") // 13 LoadEnvError = errors.New("load .env error") // 13
LoadCSVError = errors.New("load csv error") // 14 LoadCSVError = errors.New("load csv error") // 14
InvalidCaseFormat = errors.New("invalid case format") // 15 InvalidCaseError = errors.New("invalid case error") // 15
UnsupportedFileExtension = errors.New("unsupported file extension") // 16 UnsupportedFileExtension = errors.New("unsupported file extension") // 16
ReferencedFileNotFound = errors.New("referenced file not found") // 17 ReferencedFileNotFound = errors.New("referenced file not found") // 17
InvalidPluginFile = errors.New("invalid plugin file") // 18 InvalidPluginFile = errors.New("invalid plugin file") // 18
@@ -64,6 +64,7 @@ var (
DeviceConnectionError = errors.New("device general connection error") // 50 DeviceConnectionError = errors.New("device general connection error") // 50
DeviceHTTPDriverError = errors.New("device HTTP driver error") // 51 DeviceHTTPDriverError = errors.New("device HTTP driver error") // 51
DeviceUSBDriverError = errors.New("device USB driver error") // 52 DeviceUSBDriverError = errors.New("device USB driver error") // 52
DeviceGetInfoError = errors.New("device get info error") // 60
DeviceShellExecError = errors.New("device shell exec error") // 62 DeviceShellExecError = errors.New("device shell exec error") // 62
DeviceOfflineError = errors.New("device offline") // 63 DeviceOfflineError = errors.New("device offline") // 63
DeviceScreenShotError = errors.New("device screenshot error") // 65 DeviceScreenShotError = errors.New("device screenshot error") // 65
@@ -121,7 +122,7 @@ var errorsMap = map[error]int{
LoadYAMLError: 12, LoadYAMLError: 12,
LoadEnvError: 13, LoadEnvError: 13,
LoadCSVError: 14, LoadCSVError: 14,
InvalidCaseFormat: 15, InvalidCaseError: 15,
UnsupportedFileExtension: 16, UnsupportedFileExtension: 16,
ReferencedFileNotFound: 17, ReferencedFileNotFound: 17,
InvalidPluginFile: 18, InvalidPluginFile: 18,
@@ -153,6 +154,7 @@ var errorsMap = map[error]int{
DeviceConnectionError: 50, DeviceConnectionError: 50,
DeviceHTTPDriverError: 51, DeviceHTTPDriverError: 51,
DeviceUSBDriverError: 52, DeviceUSBDriverError: 52,
DeviceGetInfoError: 60,
DeviceShellExecError: 62, DeviceShellExecError: 62,
DeviceOfflineError: 63, DeviceOfflineError: 63,
DeviceScreenShotError: 65, DeviceScreenShotError: 65,
+1 -1
View File
@@ -1 +1 @@
v4.6.6 v5.0.0-beta-2409191642
+7 -5
View File
@@ -117,15 +117,17 @@ func (ad *adbDriver) WindowSize() (size Size, err error) {
ad.windowSize = &size ad.windowSize = &size
} }
orientation, err := ad.Orientation() orientation, err2 := ad.Orientation()
if err != nil { if err2 != nil {
log.Warn().Err(err).Msgf("window size get orientation failed, use default orientation")
orientation = OrientationPortrait orientation = OrientationPortrait
log.Warn().Err(err2).Msgf(
"get window orientation failed, use default %s", orientation)
} }
if orientation != OrientationPortrait { if orientation != OrientationPortrait {
size.Width, size.Height = size.Height, size.Width size.Width, size.Height = size.Height, size.Width
} }
return // Notice: do not return err if get window orientation failed
return size, nil
} }
func (ad *adbDriver) Screen() (screen Screen, err error) { func (ad *adbDriver) Screen() (screen Screen, err error) {
@@ -535,7 +537,7 @@ func (ad *adbDriver) Screenshot() (raw *bytes.Buffer, err error) {
if err == nil { if err == nil {
return bytes.NewBuffer(resp), nil return bytes.NewBuffer(resp), nil
} }
return nil, err return nil, errors.Wrap(err, "adb screencap failed")
} }
func (ad *adbDriver) Source(srcOpt ...SourceOption) (source string, err error) { func (ad *adbDriver) Source(srcOpt ...SourceOption) (source string, err error) {
-8
View File
@@ -42,14 +42,6 @@ func TestAndroidDevice_GetPackageInfo(t *testing.T) {
t.Log(appInfo) t.Log(appInfo)
} }
func TestIOSDevice_GetPackageInfo(t *testing.T) {
device, err := NewIOSDevice()
checkErr(t, err)
appInfo, err := device.GetPackageInfo("com.apple.Preferences")
checkErr(t, err)
t.Log(appInfo)
}
func TestDriver_NewSession(t *testing.T) { func TestDriver_NewSession(t *testing.T) {
driver, err := NewUIADriver(nil, uiaServerURL) driver, err := NewUIADriver(nil, uiaServerURL)
if err != nil { if err != nil {
+1 -1
View File
@@ -564,7 +564,7 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...Action
// update data options in post data for extra WDA configurations // update data options in post data for extra WDA configurations
actionOptions.updateData(data) actionOptions.updateData(data)
// wda 43 version // wda 43 version
_, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/drag") _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/dragfromtoforduration")
return return
} }
+9 -1
View File
@@ -71,7 +71,7 @@ func TestNewIOSDevice(t *testing.T) {
} }
func TestNewWDAHTTPDriver(t *testing.T) { func TestNewWDAHTTPDriver(t *testing.T) {
device, _ := NewIOSDevice() device, _ := NewIOSDevice(WithWDAPort(8700), WithWDAMjpegPort(8800))
var err error var err error
_, err = device.NewHTTPDriver(nil) _, err = device.NewHTTPDriver(nil)
if err != nil { if err != nil {
@@ -85,6 +85,14 @@ func TestNewUSBDriver(t *testing.T) {
// t.Log(driver.IsWdaHealthy()) // t.Log(driver.IsWdaHealthy())
} }
func TestIOSDevice_GetPackageInfo(t *testing.T) {
device, err := NewIOSDevice(WithWDAPort(8700))
checkErr(t, err)
appInfo, err := device.GetPackageInfo("com.apple.Preferences")
checkErr(t, err)
t.Log(appInfo)
}
func TestDriver_DeviceScaleRatio(t *testing.T) { func TestDriver_DeviceScaleRatio(t *testing.T) {
setup(t) setup(t)
+1 -1
View File
@@ -62,7 +62,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
windowSize, err = dExt.Driver.WindowSize() windowSize, err = dExt.Driver.WindowSize()
if err != nil { if err != nil {
lastErr = errors.Wrap(code.MobileUIDriverError, err.Error()) lastErr = errors.Wrap(code.DeviceGetInfoError, err.Error())
continue continue
} }
+2 -2
View File
@@ -19,14 +19,14 @@ func assertRelative(p float64) bool {
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error { func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error {
if !assertRelative(fromX) || !assertRelative(fromY) || if !assertRelative(fromX) || !assertRelative(fromY) ||
!assertRelative(toX) || !assertRelative(toY) { !assertRelative(toX) || !assertRelative(toY) {
return errors.Wrap(code.MobileUISwipeError, return errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("fromX(%f), fromY(%f), toX(%f), toY(%f) must be less than 1", fmt.Sprintf("fromX(%f), fromY(%f), toX(%f), toY(%f) must be less than 1",
fromX, fromY, toX, toY)) fromX, fromY, toX, toY))
} }
windowSize, err := dExt.Driver.WindowSize() windowSize, err := dExt.Driver.WindowSize()
if err != nil { if err != nil {
return errors.Wrap(code.MobileUISwipeError, err.Error()) return errors.Wrap(code.DeviceGetInfoError, err.Error())
} }
width := windowSize.Width width := windowSize.Width
height := windowSize.Height height := windowSize.Height
+8 -8
View File
@@ -32,7 +32,7 @@ func (path *TestCasePath) GetTestCase() (*TestCase, error) {
return nil, err return nil, err
} }
if tc.Steps == nil { if tc.Steps == nil {
return nil, errors.Wrap(code.InvalidCaseFormat, return nil, errors.Wrap(code.InvalidCaseError,
"invalid testcase format, missing teststeps!") "invalid testcase format, missing teststeps!")
} }
@@ -171,7 +171,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) {
} else { } else {
apiMap, ok := step.API.(map[string]interface{}) apiMap, ok := step.API.(map[string]interface{})
if !ok { if !ok {
return nil, errors.Wrap(code.InvalidCaseFormat, return nil, errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("referenced api should be map or path(string), got %v", step.API)) fmt.Sprintf("referenced api should be map or path(string), got %v", step.API))
} }
api := &API{} api := &API{}
@@ -183,7 +183,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) {
} }
_, ok = step.API.(*API) _, ok = step.API.(*API)
if !ok { if !ok {
return nil, errors.Wrap(code.InvalidCaseFormat, return nil, errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("failed to handle referenced API, got %v", step.TestCase)) fmt.Sprintf("failed to handle referenced API, got %v", step.TestCase))
} }
testCase.TestSteps = append(testCase.TestSteps, &StepAPIWithOptionalArgs{ testCase.TestSteps = append(testCase.TestSteps, &StepAPIWithOptionalArgs{
@@ -207,7 +207,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) {
} else { } else {
testCaseMap, ok := step.TestCase.(map[string]interface{}) testCaseMap, ok := step.TestCase.(map[string]interface{})
if !ok { if !ok {
return nil, errors.Wrap(code.InvalidCaseFormat, return nil, errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("referenced testcase should be map or path(string), got %v", step.TestCase)) fmt.Sprintf("referenced testcase should be map or path(string), got %v", step.TestCase))
} }
tCase := &TestCase{} tCase := &TestCase{}
@@ -223,7 +223,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) {
} }
_, ok = step.TestCase.(*TestCase) _, ok = step.TestCase.(*TestCase)
if !ok { if !ok {
return nil, errors.Wrap(code.InvalidCaseFormat, return nil, errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("failed to handle referenced testcase, got %v", step.TestCase)) fmt.Sprintf("failed to handle referenced testcase, got %v", step.TestCase))
} }
testCase.TestSteps = append(testCase.TestSteps, &StepTestCaseWithOptionalArgs{ testCase.TestSteps = append(testCase.TestSteps, &StepTestCaseWithOptionalArgs{
@@ -309,7 +309,7 @@ func convertCompatValidator(Validators []interface{}) (err error) {
validatorMap[strKey] = value validatorMap[strKey] = value
} }
} else { } else {
return errors.Wrap(code.InvalidCaseFormat, return errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("unexpected validator format: %v", iValidator)) fmt.Sprintf("unexpected validator format: %v", iValidator))
} }
@@ -335,7 +335,7 @@ func convertCompatValidator(Validators []interface{}) (err error) {
for assertMethod, iValidatorContent := range validatorMap { for assertMethod, iValidatorContent := range validatorMap {
validatorContent := iValidatorContent.([]interface{}) validatorContent := iValidatorContent.([]interface{})
if len(validatorContent) > 3 { if len(validatorContent) > 3 {
return errors.Wrap(code.InvalidCaseFormat, return errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("unexpected validator format: %v", validatorMap)) fmt.Sprintf("unexpected validator format: %v", validatorMap))
} }
validator.Check = validatorContent[0].(string) validator.Check = validatorContent[0].(string)
@@ -349,7 +349,7 @@ func convertCompatValidator(Validators []interface{}) (err error) {
Validators[i] = validator Validators[i] = validator
continue continue
} }
return errors.Wrap(code.InvalidCaseFormat, return errors.Wrap(code.InvalidCaseError,
fmt.Sprintf("unexpected validator format: %v", validatorMap)) fmt.Sprintf("unexpected validator format: %v", validatorMap))
} }
return nil return nil
-30
View File
@@ -1,30 +0,0 @@
#!/bin/bash
# build hrp cli binary for testing
# release will be triggered on github actions, see .github/workflows/release.yml
# Usage:
# $ make bump version=v4.3.0
# or
# $ bash scripts/bump_version.sh v4.3.0
set -e
version=$1
if [ -z "$version" ]; then
echo "version is required"
exit 1
fi
if [[ $version != v* ]]; then
version="v$version"
fi
echo "bump hrp version to $version"
echo -n "$version" > hrp/internal/version/VERSION
echo "bump httprunner version to $version"
sed -i'.bak' "s/__version__ = \".*\"/__version__ = \"$version\"/g" httprunner/__init__.py
echo "bump pyproject.toml version to $version"
sed -i'.bak' "s/^version = \".*\"/version = \"$version\"/g" pyproject.toml
+17
View File
@@ -18,6 +18,7 @@ function install() {
# 1. gofumpt go files automatically # 1. gofumpt go files automatically
# 2. goimports-reviser go files automatically # 2. goimports-reviser go files automatically
# 3. black python files automatically # 3. black python files automatically
# 4. bump hrp version
# make sure gofumpt is installed # make sure gofumpt is installed
# What does each letter mean in "ACMRTUXB"? # What does each letter mean in "ACMRTUXB"?
@@ -38,6 +39,22 @@ do
black "$file" black "$file"
git add "$file" git add "$file"
done done
# bump hrp version
version_file=hrp/internal/version/VERSION
# get current date
current_date=$(date +"%y%m%d%H%M")
# update version
sed -i '' "s/[0-9]\{10\}/${current_date}/" "$version_file"
# add change to stage
git add $version_file
# print updated version
updated_version=$(cat "$version_file")
echo "update hrp version to $updated_version"
EOF EOF
chmod +x $PRE_COMMIT_FILE chmod +x $PRE_COMMIT_FILE