mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-15 12:27:59 +08:00
change: update wda logs
This commit is contained in:
@@ -45,6 +45,18 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "处理青少年弹窗",
|
||||
"ios": {
|
||||
"actions": [
|
||||
{
|
||||
"method": "tap_ocr",
|
||||
"params": "我知道了",
|
||||
"ignore_NotFoundError": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "向上滑动 2 次",
|
||||
"ios": {
|
||||
|
||||
@@ -24,6 +24,12 @@ teststeps:
|
||||
assert: exists
|
||||
expect: 推荐
|
||||
msg: 抖音启动失败,「推荐」不存在
|
||||
- name: 处理青少年弹窗
|
||||
ios:
|
||||
actions:
|
||||
- method: tap_ocr
|
||||
params: 我知道了
|
||||
ignore_NotFoundError: true
|
||||
- name: 向上滑动 2 次
|
||||
ios:
|
||||
actions:
|
||||
|
||||
@@ -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,截图保存
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user