diff --git a/Makefile b/Makefile index b094ea9c..f2f15434 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ bump: ## bump hrp version, e.g. make bump version=4.0.0 .PHONY: build build: ## build hrp cli tool @echo "[info] build hrp cli tool" - @. scripts/build.sh + @. scripts/build.sh $(tags) .PHONY: install-hooks install-hooks: ## install git hooks diff --git a/examples/uitest/demo_weixin_live.json b/examples/uitest/demo_weixin_live.json index a789f0ee..9aa990f3 100644 --- a/examples/uitest/demo_weixin_live.json +++ b/examples/uitest/demo_weixin_live.json @@ -64,6 +64,7 @@ { "method": "swipe_to_tap_text", "params": "轻触进入直播间", + "identifier": "进入直播间", "max_retry_times": 10 } ] @@ -75,7 +76,8 @@ "actions": [ { "method": "swipe", - "params": "up" + "params": "up", + "identifier": "第一次上划" }, { "method": "sleep", @@ -86,7 +88,8 @@ }, { "method": "swipe", - "params": "up" + "params": "up", + "identifier": "第二次上划" }, { "method": "sleep", diff --git a/examples/uitest/demo_weixin_live.yaml b/examples/uitest/demo_weixin_live.yaml index d5f3d795..45393eb2 100644 --- a/examples/uitest/demo_weixin_live.yaml +++ b/examples/uitest/demo_weixin_live.yaml @@ -33,17 +33,20 @@ teststeps: actions: - method: swipe_to_tap_text params: 轻触进入直播间 + identifier: 进入直播间 max_retry_times: 10 - name: 向上滑动,等待 10s ios: actions: - method: swipe params: up + identifier: 第一次上划 - method: sleep params: 10 - method: screenshot - method: swipe params: up + identifier: 第二次上划 - method: sleep params: 10 - method: screenshot diff --git a/hrp/internal/uixt/README.md b/hrp/internal/uixt/README.md index e9191b29..111281c0 100644 --- a/hrp/internal/uixt/README.md +++ b/hrp/internal/uixt/README.md @@ -28,6 +28,10 @@ You can get more installation introduction on [hybridgroup/gocv]. OCR API is a paid service, you need to pre-purchase and configure the account key. +```bash +$ make build tags=ocr +``` + ## Thanks This uixt module is initially forked from [electricbubble/gwda-ext-opencv] and made a lot of changes. diff --git a/hrp/internal/uixt/ext.go b/hrp/internal/uixt/ext.go index 40907c4f..c140edc2 100644 --- a/hrp/internal/uixt/ext.go +++ b/hrp/internal/uixt/ext.go @@ -22,7 +22,6 @@ import ( type TemplateMatchMode int type CVArgs struct { - scale float64 matchMode TemplateMatchMode threshold float64 } @@ -46,6 +45,7 @@ type DriverExt struct { windowSize gwda.Size frame *bytes.Buffer doneMjpegStream chan bool + scale float64 CVArgs } @@ -60,6 +60,10 @@ func extend(driver gwda.WebDriver) (dExt *DriverExt, err error) { return nil, errors.Wrap(err, "failed to get windows size") } + if dExt.scale, err = dExt.Scale(); err != nil { + return nil, err + } + return dExt, nil } @@ -213,6 +217,12 @@ func (dExt *DriverExt) FindUIRectInUIKit(search string) (x, y, width, height flo return dExt.FindImageRectInUIKit(search) } +func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) { + x, y = float64(rect.Min.X)/dExt.scale, float64(rect.Min.Y)/dExt.scale + width, height = float64(rect.Dx())/dExt.scale, float64(rect.Dy())/dExt.scale + return +} + func (dExt *DriverExt) PerformTouchActions(touchActions *gwda.TouchActions) error { return dExt.PerformAppiumTouchActions(touchActions) } diff --git a/hrp/internal/uixt/gesture.go b/hrp/internal/uixt/gesture.go index 2491bb27..5edd8147 100644 --- a/hrp/internal/uixt/gesture.go +++ b/hrp/internal/uixt/gesture.go @@ -4,6 +4,7 @@ package uixt import ( "image" + "sort" "github.com/electricbubble/gwda" ) diff --git a/hrp/internal/uixt/ocr_on.go b/hrp/internal/uixt/ocr_on.go index 2edf0d5a..79d0c271 100644 --- a/hrp/internal/uixt/ocr_on.go +++ b/hrp/internal/uixt/ocr_on.go @@ -4,11 +4,15 @@ package uixt import ( "bytes" + "encoding/base64" + "encoding/json" "fmt" "image" + "io/ioutil" "mime/multipart" "net/http" "strings" + "time" ) var client = &http.Client{ diff --git a/hrp/internal/uixt/opencv_off.go b/hrp/internal/uixt/opencv_off.go index 7d56d5c5..18045295 100644 --- a/hrp/internal/uixt/opencv_off.go +++ b/hrp/internal/uixt/opencv_off.go @@ -22,8 +22,3 @@ func (dExt *DriverExt) FindImageRectInUIKit(imagePath string) (x, y, width, heig log.Fatal().Msg("opencv is not supported") return } - -func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) { - log.Fatal().Msg("opencv is not supported") - return -} diff --git a/hrp/internal/uixt/opencv_on.go b/hrp/internal/uixt/opencv_on.go index 6a184695..81afe225 100644 --- a/hrp/internal/uixt/opencv_on.go +++ b/hrp/internal/uixt/opencv_on.go @@ -53,10 +53,6 @@ func Extend(driver gwda.WebDriver, options ...CVOption) (dExt *DriverExt, err er option(&dExt.CVArgs) } - if dExt.scale, err = dExt.Scale(); err != nil { - return nil, err - } - if dExt.threshold == 0 { dExt.threshold = 0.95 // default threshold } @@ -149,9 +145,3 @@ func getBufFromDisk(name string) (*bytes.Buffer, error) { } return bytes.NewBuffer(all), nil } - -func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) { - x, y = float64(rect.Min.X)/dExt.scale, float64(rect.Min.Y)/dExt.scale - width, height = float64(rect.Dx())/dExt.scale, float64(rect.Dy())/dExt.scale - return -} diff --git a/scripts/build.sh b/scripts/build.sh index 1c6cfd52..67c514ce 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,8 +4,10 @@ # Usage: # $ make build +# $ make build tags=ocr # or -# $ bash cli/scripts/build.sh +# $ bash scripts/build.sh +# $ bash scripts/build.sh ocr set -e set -x @@ -14,9 +16,15 @@ set -x mkdir -p "output" bin_path="output/hrp" -# build # optional build tags: opencv ocr -go build -ldflags '-s -w' -tags ocr -o "$bin_path" hrp/cmd/cli/main.go +tags=$1 + +# build +if [ -z "$tags" ]; then + go build -ldflags '-s -w' -o "$bin_path" hrp/cmd/cli/main.go +else + go build -ldflags '-s -w' -tags "$tags" -o "$bin_path" hrp/cmd/cli/main.go +fi # check output and version ls -lh "$bin_path" diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh index 1abba52d..98141421 100644 --- a/scripts/bump_version.sh +++ b/scripts/bump_version.sh @@ -3,9 +3,9 @@ # release will be triggered on github actions, see .github/workflows/release.yml # Usage: -# $ make bump version=v0.5.2 +# $ make bump version=v4.3.0 # or -# $ bash cli/scripts/bump_version.sh v0.5.2 +# $ bash scripts/bump_version.sh v4.3.0 set -e