diff --git a/examples/uitest/demo_douyin_live.json b/examples/uitest/demo_douyin_live.json index 94fe4496..e9dd2f84 100644 --- a/examples/uitest/demo_douyin_live.json +++ b/examples/uitest/demo_douyin_live.json @@ -45,6 +45,18 @@ } ] }, + { + "name": "处理青少年弹窗", + "ios": { + "actions": [ + { + "method": "tap_ocr", + "params": "我知道了", + "ignore_NotFoundError": true + } + ] + } + }, { "name": "向上滑动 2 次", "ios": { diff --git a/examples/uitest/demo_douyin_live.yaml b/examples/uitest/demo_douyin_live.yaml index d2463772..b1eccd04 100644 --- a/examples/uitest/demo_douyin_live.yaml +++ b/examples/uitest/demo_douyin_live.yaml @@ -24,6 +24,12 @@ teststeps: assert: exists expect: 推荐 msg: 抖音启动失败,「推荐」不存在 + - name: 处理青少年弹窗 + ios: + actions: + - method: tap_ocr + params: 我知道了 + ignore_NotFoundError: true - name: 向上滑动 2 次 ios: actions: diff --git a/examples/uitest/demo_douyin_test.go b/examples/uitest/demo_douyin_test.go index 9abc72d6..b9ca8fa9 100644 --- a/examples/uitest/demo_douyin_test.go +++ b/examples/uitest/demo_douyin_test.go @@ -21,9 +21,9 @@ func TestIOSDouyinLive(t *testing.T) { SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5). Validate(). AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"), - // hrp.NewStep("处理青少年弹窗"). - // IOS(). - // TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)), + hrp.NewStep("处理青少年弹窗"). + IOS(). + TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)), hrp.NewStep("向上滑动 2 次"). IOS(). SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存 diff --git a/hrp/internal/uixt/ext.go b/hrp/internal/uixt/ext.go index c4aaad79..bed62ffc 100644 --- a/hrp/internal/uixt/ext.go +++ b/hrp/internal/uixt/ext.go @@ -124,7 +124,7 @@ func WithThreshold(threshold float64) CVOption { } type DriverExt struct { - Device Device + UUID string // ios udid or android serial Driver WebDriver windowSize Size frame *bytes.Buffer diff --git a/hrp/internal/uixt/ios_device.go b/hrp/internal/uixt/ios_device.go index 8313aa89..bfacfb72 100644 --- a/hrp/internal/uixt/ios_device.go +++ b/hrp/internal/uixt/ios_device.go @@ -96,7 +96,7 @@ func InitWDAClient(device *IOSDevice) (*DriverExt, error) { } } - driverExt.Device = iosDevice + driverExt.UUID = iosDevice.UUID() return driverExt, nil } @@ -224,8 +224,8 @@ func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver WebDriver, } type wdaResponse struct { - Value string `json:"value"` - SessionID string `json:"sessionId"` + Value interface{} `json:"value"` + SessionID string `json:"sessionId"` } func (dExt *DriverExt) StartLogRecording(identifier string) error { @@ -239,11 +239,12 @@ func (dExt *DriverExt) StartLogRecording(identifier string) error { return nil } -func (dExt *DriverExt) GetLogs() (string, error) { +func (dExt *DriverExt) GetLogs() (interface{}, error) { log.Info().Msg("stop WDA log recording") data := map[string]interface{}{"action": "stop"} reply, err := dExt.triggerWDALog(data) if err != nil { + log.Error().Err(err).Msg("failed to get WDA logs") return "", errors.Wrap(err, "failed to get WDA logs") } @@ -275,8 +276,10 @@ func (dExt *DriverExt) triggerWDALog(data map[string]interface{}) (*wdaResponse, reply := new(wdaResponse) if err = json.Unmarshal(rawResp, reply); err != nil { + log.Info().Bytes("rawResp", rawResp).Msg("get unexpected WDA log response") return nil, err } + log.Info().Interface("value", reply.Value).Msg("get WDA log response") return reply, nil } diff --git a/hrp/internal/uixt/ocr_on.go b/hrp/internal/uixt/ocr_on.go index 327bc373..13f1b213 100644 --- a/hrp/internal/uixt/ocr_on.go +++ b/hrp/internal/uixt/ocr_on.go @@ -163,7 +163,7 @@ func (dExt *DriverExt) FindTextByOCR(ocrText string, index ...int) (x, y, width, service := &veDEMOCRService{} rect, err := service.FindText(ocrText, bufSource.Bytes(), index...) if err != nil { - log.Warn().Err(err).Msg("FindText failed") + log.Warn().Msgf("FindText failed: %s", err.Error()) err = fmt.Errorf("FindText failed: %v", err) return } diff --git a/hrp/runner.go b/hrp/runner.go index d7d59202..2524ff8c 100644 --- a/hrp/runner.go +++ b/hrp/runner.go @@ -214,7 +214,7 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error { caseSummary, err2 := sessionRunner.GetSummary() s.appendCaseSummary(caseSummary) if err1 != nil || err2 != nil { - log.Error().Err(err).Msg("[Run] run testcase failed") + log.Error().Err(err1).Msg("[Run] run testcase failed") runErr = err break } diff --git a/hrp/session.go b/hrp/session.go index 10b0d76a..83c0429b 100644 --- a/hrp/session.go +++ b/hrp/session.go @@ -5,8 +5,11 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/pkg/errors" "github.com/rs/zerolog/log" + + "github.com/httprunner/httprunner/v4/hrp/internal/json" ) // SessionRunner is used to run testcase and its steps. @@ -162,15 +165,17 @@ func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) { caseSummary.InOut.ConfigVars = r.parsedConfig.Variables // add WDA/UIA logs to summary - logs := make(map[string]string) + logs := make(map[string]interface{}) for udid, client := range r.hrpRunner.uiClients { log, err := client.GetLogs() if err != nil { - return nil, err + return caseSummary, err } logs[udid] = log } - caseSummary.Logs = logs + + logsBytes, _ := json.Marshal(logs) + caseSummary.Logs = string(logsBytes) return caseSummary, nil } diff --git a/hrp/step_ios_ui.go b/hrp/step_ios_ui.go index be9a566d..7b2c0c9e 100644 --- a/hrp/step_ios_ui.go +++ b/hrp/step_ios_ui.go @@ -499,7 +499,7 @@ func (r *HRPRunner) initUIClient(device uixt.Device) (client *uixt.DriverExt, er if r.uiClients == nil { r.uiClients = make(map[string]*uixt.DriverExt) } - r.uiClients[client.Device.UUID()] = client + r.uiClients[client.UUID] = client return client, nil } diff --git a/hrp/summary.go b/hrp/summary.go index da3b0197..841f7fc5 100644 --- a/hrp/summary.go +++ b/hrp/summary.go @@ -151,7 +151,7 @@ type TestCaseSummary struct { Stat *TestStepStat `json:"stat" yaml:"stat"` Time *TestCaseTime `json:"time" yaml:"time"` InOut *TestCaseInOut `json:"in_out" yaml:"in_out"` - Logs interface{} `json:"logs,omitempty" yaml:"logs,omitempty"` + Logs string `json:"logs,omitempty" yaml:"logs,omitempty"` Records []*StepResult `json:"records" yaml:"records"` RootDir string `json:"root_dir" yaml:"root_dir"` }