diff --git a/hrp/code/code.go b/hrp/code/code.go index 9fb22da5..bb1cb366 100644 --- a/hrp/code/code.go +++ b/hrp/code/code.go @@ -24,7 +24,7 @@ var ( LoadYAMLError = errors.New("load yaml error") // 12 LoadEnvError = errors.New("load .env error") // 13 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 ReferencedFileNotFound = errors.New("referenced file not found") // 17 InvalidPluginFile = errors.New("invalid plugin file") // 18 @@ -64,6 +64,7 @@ var ( DeviceConnectionError = errors.New("device general connection error") // 50 DeviceHTTPDriverError = errors.New("device HTTP driver error") // 51 DeviceUSBDriverError = errors.New("device USB driver error") // 52 + DeviceGetInfoError = errors.New("device get info error") // 60 DeviceShellExecError = errors.New("device shell exec error") // 62 DeviceOfflineError = errors.New("device offline") // 63 DeviceScreenShotError = errors.New("device screenshot error") // 65 @@ -121,7 +122,7 @@ var errorsMap = map[error]int{ LoadYAMLError: 12, LoadEnvError: 13, LoadCSVError: 14, - InvalidCaseFormat: 15, + InvalidCaseError: 15, UnsupportedFileExtension: 16, ReferencedFileNotFound: 17, InvalidPluginFile: 18, @@ -153,6 +154,7 @@ var errorsMap = map[error]int{ DeviceConnectionError: 50, DeviceHTTPDriverError: 51, DeviceUSBDriverError: 52, + DeviceGetInfoError: 60, DeviceShellExecError: 62, DeviceOfflineError: 63, DeviceScreenShotError: 65, diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 899d8138..7d4c6063 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.6.6 \ No newline at end of file +v5.0.0-beta-2409191642 \ No newline at end of file diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index 86593969..1e4d8977 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -117,15 +117,17 @@ func (ad *adbDriver) WindowSize() (size Size, err error) { ad.windowSize = &size } - orientation, err := ad.Orientation() - if err != nil { - log.Warn().Err(err).Msgf("window size get orientation failed, use default orientation") + orientation, err2 := ad.Orientation() + if err2 != nil { orientation = OrientationPortrait + log.Warn().Err(err2).Msgf( + "get window orientation failed, use default %s", orientation) } if orientation != OrientationPortrait { 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) { @@ -535,7 +537,7 @@ func (ad *adbDriver) Screenshot() (raw *bytes.Buffer, err error) { if err == 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) { diff --git a/hrp/pkg/uixt/android_test.go b/hrp/pkg/uixt/android_test.go index 965fc01a..8e6f4aa2 100644 --- a/hrp/pkg/uixt/android_test.go +++ b/hrp/pkg/uixt/android_test.go @@ -42,14 +42,6 @@ func TestAndroidDevice_GetPackageInfo(t *testing.T) { 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) { driver, err := NewUIADriver(nil, uiaServerURL) if err != nil { diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index df52a9ad..2e21f2f9 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -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 actionOptions.updateData(data) // wda 43 version - _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/drag") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/dragfromtoforduration") return } diff --git a/hrp/pkg/uixt/ios_test.go b/hrp/pkg/uixt/ios_test.go index 0ee94d36..6fb1ddc5 100644 --- a/hrp/pkg/uixt/ios_test.go +++ b/hrp/pkg/uixt/ios_test.go @@ -71,7 +71,7 @@ func TestNewIOSDevice(t *testing.T) { } func TestNewWDAHTTPDriver(t *testing.T) { - device, _ := NewIOSDevice() + device, _ := NewIOSDevice(WithWDAPort(8700), WithWDAMjpegPort(8800)) var err error _, err = device.NewHTTPDriver(nil) if err != nil { @@ -85,6 +85,14 @@ func TestNewUSBDriver(t *testing.T) { // 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) { setup(t) diff --git a/hrp/pkg/uixt/screenshot.go b/hrp/pkg/uixt/screenshot.go index 6b8f5edc..3c331784 100644 --- a/hrp/pkg/uixt/screenshot.go +++ b/hrp/pkg/uixt/screenshot.go @@ -62,7 +62,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S windowSize, err = dExt.Driver.WindowSize() if err != nil { - lastErr = errors.Wrap(code.MobileUIDriverError, err.Error()) + lastErr = errors.Wrap(code.DeviceGetInfoError, err.Error()) continue } diff --git a/hrp/pkg/uixt/swipe.go b/hrp/pkg/uixt/swipe.go index 94b625c9..184b6c6a 100644 --- a/hrp/pkg/uixt/swipe.go +++ b/hrp/pkg/uixt/swipe.go @@ -19,14 +19,14 @@ func assertRelative(p float64) bool { func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error { if !assertRelative(fromX) || !assertRelative(fromY) || !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", fromX, fromY, toX, toY)) } windowSize, err := dExt.Driver.WindowSize() if err != nil { - return errors.Wrap(code.MobileUISwipeError, err.Error()) + return errors.Wrap(code.DeviceGetInfoError, err.Error()) } width := windowSize.Width height := windowSize.Height diff --git a/hrp/testcase.go b/hrp/testcase.go index 03a16fc0..e8ebe08d 100644 --- a/hrp/testcase.go +++ b/hrp/testcase.go @@ -32,7 +32,7 @@ func (path *TestCasePath) GetTestCase() (*TestCase, error) { return nil, err } if tc.Steps == nil { - return nil, errors.Wrap(code.InvalidCaseFormat, + return nil, errors.Wrap(code.InvalidCaseError, "invalid testcase format, missing teststeps!") } @@ -171,7 +171,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) { } else { apiMap, ok := step.API.(map[string]interface{}) 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)) } api := &API{} @@ -183,7 +183,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) { } _, ok = step.API.(*API) 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)) } testCase.TestSteps = append(testCase.TestSteps, &StepAPIWithOptionalArgs{ @@ -207,7 +207,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) { } else { testCaseMap, ok := step.TestCase.(map[string]interface{}) 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)) } tCase := &TestCase{} @@ -223,7 +223,7 @@ func (tc *TestCase) loadISteps() (*TestCase, error) { } _, ok = step.TestCase.(*TestCase) 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)) } testCase.TestSteps = append(testCase.TestSteps, &StepTestCaseWithOptionalArgs{ @@ -309,7 +309,7 @@ func convertCompatValidator(Validators []interface{}) (err error) { validatorMap[strKey] = value } } else { - return errors.Wrap(code.InvalidCaseFormat, + return errors.Wrap(code.InvalidCaseError, fmt.Sprintf("unexpected validator format: %v", iValidator)) } @@ -335,7 +335,7 @@ func convertCompatValidator(Validators []interface{}) (err error) { for assertMethod, iValidatorContent := range validatorMap { validatorContent := iValidatorContent.([]interface{}) if len(validatorContent) > 3 { - return errors.Wrap(code.InvalidCaseFormat, + return errors.Wrap(code.InvalidCaseError, fmt.Sprintf("unexpected validator format: %v", validatorMap)) } validator.Check = validatorContent[0].(string) @@ -349,7 +349,7 @@ func convertCompatValidator(Validators []interface{}) (err error) { Validators[i] = validator continue } - return errors.Wrap(code.InvalidCaseFormat, + return errors.Wrap(code.InvalidCaseError, fmt.Sprintf("unexpected validator format: %v", validatorMap)) } return nil diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh deleted file mode 100644 index 98141421..00000000 --- a/scripts/bump_version.sh +++ /dev/null @@ -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 diff --git a/scripts/install-pre-commit-hook b/scripts/install-pre-commit-hook index 6c47fa98..350275bd 100644 --- a/scripts/install-pre-commit-hook +++ b/scripts/install-pre-commit-hook @@ -18,6 +18,7 @@ function install() { # 1. gofumpt go files automatically # 2. goimports-reviser go files automatically # 3. black python files automatically +# 4. bump hrp version # make sure gofumpt is installed # What does each letter mean in "ACMRTUXB"? @@ -38,6 +39,22 @@ do black "$file" git add "$file" 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 chmod +x $PRE_COMMIT_FILE