mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +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 次",
|
"name": "向上滑动 2 次",
|
||||||
"ios": {
|
"ios": {
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ teststeps:
|
|||||||
assert: exists
|
assert: exists
|
||||||
expect: 推荐
|
expect: 推荐
|
||||||
msg: 抖音启动失败,「推荐」不存在
|
msg: 抖音启动失败,「推荐」不存在
|
||||||
|
- name: 处理青少年弹窗
|
||||||
|
ios:
|
||||||
|
actions:
|
||||||
|
- method: tap_ocr
|
||||||
|
params: 我知道了
|
||||||
|
ignore_NotFoundError: true
|
||||||
- name: 向上滑动 2 次
|
- name: 向上滑动 2 次
|
||||||
ios:
|
ios:
|
||||||
actions:
|
actions:
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ func TestIOSDouyinLive(t *testing.T) {
|
|||||||
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5).
|
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5).
|
||||||
Validate().
|
Validate().
|
||||||
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
|
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
|
||||||
// hrp.NewStep("处理青少年弹窗").
|
hrp.NewStep("处理青少年弹窗").
|
||||||
// IOS().
|
IOS().
|
||||||
// TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
||||||
hrp.NewStep("向上滑动 2 次").
|
hrp.NewStep("向上滑动 2 次").
|
||||||
IOS().
|
IOS().
|
||||||
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存
|
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func WithThreshold(threshold float64) CVOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DriverExt struct {
|
type DriverExt struct {
|
||||||
Device Device
|
UUID string // ios udid or android serial
|
||||||
Driver WebDriver
|
Driver WebDriver
|
||||||
windowSize Size
|
windowSize Size
|
||||||
frame *bytes.Buffer
|
frame *bytes.Buffer
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func InitWDAClient(device *IOSDevice) (*DriverExt, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
driverExt.Device = iosDevice
|
driverExt.UUID = iosDevice.UUID()
|
||||||
return driverExt, nil
|
return driverExt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,8 +224,8 @@ func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver WebDriver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
type wdaResponse struct {
|
type wdaResponse struct {
|
||||||
Value string `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
SessionID string `json:"sessionId"`
|
SessionID string `json:"sessionId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) StartLogRecording(identifier string) error {
|
func (dExt *DriverExt) StartLogRecording(identifier string) error {
|
||||||
@@ -239,11 +239,12 @@ func (dExt *DriverExt) StartLogRecording(identifier string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) GetLogs() (string, error) {
|
func (dExt *DriverExt) GetLogs() (interface{}, error) {
|
||||||
log.Info().Msg("stop WDA log recording")
|
log.Info().Msg("stop WDA log recording")
|
||||||
data := map[string]interface{}{"action": "stop"}
|
data := map[string]interface{}{"action": "stop"}
|
||||||
reply, err := dExt.triggerWDALog(data)
|
reply, err := dExt.triggerWDALog(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("failed to get WDA logs")
|
||||||
return "", errors.Wrap(err, "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)
|
reply := new(wdaResponse)
|
||||||
if err = json.Unmarshal(rawResp, reply); err != nil {
|
if err = json.Unmarshal(rawResp, reply); err != nil {
|
||||||
|
log.Info().Bytes("rawResp", rawResp).Msg("get unexpected WDA log response")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
log.Info().Interface("value", reply.Value).Msg("get WDA log response")
|
||||||
|
|
||||||
return reply, nil
|
return reply, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ func (dExt *DriverExt) FindTextByOCR(ocrText string, index ...int) (x, y, width,
|
|||||||
service := &veDEMOCRService{}
|
service := &veDEMOCRService{}
|
||||||
rect, err := service.FindText(ocrText, bufSource.Bytes(), index...)
|
rect, err := service.FindText(ocrText, bufSource.Bytes(), index...)
|
||||||
if err != nil {
|
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)
|
err = fmt.Errorf("FindText failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -214,7 +214,7 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error {
|
|||||||
caseSummary, err2 := sessionRunner.GetSummary()
|
caseSummary, err2 := sessionRunner.GetSummary()
|
||||||
s.appendCaseSummary(caseSummary)
|
s.appendCaseSummary(caseSummary)
|
||||||
if err1 != nil || err2 != nil {
|
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
|
runErr = err
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-3
@@ -5,8 +5,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SessionRunner is used to run testcase and its steps.
|
// 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
|
caseSummary.InOut.ConfigVars = r.parsedConfig.Variables
|
||||||
|
|
||||||
// add WDA/UIA logs to summary
|
// add WDA/UIA logs to summary
|
||||||
logs := make(map[string]string)
|
logs := make(map[string]interface{})
|
||||||
for udid, client := range r.hrpRunner.uiClients {
|
for udid, client := range r.hrpRunner.uiClients {
|
||||||
log, err := client.GetLogs()
|
log, err := client.GetLogs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return caseSummary, err
|
||||||
}
|
}
|
||||||
logs[udid] = log
|
logs[udid] = log
|
||||||
}
|
}
|
||||||
caseSummary.Logs = logs
|
|
||||||
|
logsBytes, _ := json.Marshal(logs)
|
||||||
|
caseSummary.Logs = string(logsBytes)
|
||||||
|
|
||||||
return caseSummary, nil
|
return caseSummary, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -499,7 +499,7 @@ func (r *HRPRunner) initUIClient(device uixt.Device) (client *uixt.DriverExt, er
|
|||||||
if r.uiClients == nil {
|
if r.uiClients == nil {
|
||||||
r.uiClients = make(map[string]*uixt.DriverExt)
|
r.uiClients = make(map[string]*uixt.DriverExt)
|
||||||
}
|
}
|
||||||
r.uiClients[client.Device.UUID()] = client
|
r.uiClients[client.UUID] = client
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -151,7 +151,7 @@ type TestCaseSummary struct {
|
|||||||
Stat *TestStepStat `json:"stat" yaml:"stat"`
|
Stat *TestStepStat `json:"stat" yaml:"stat"`
|
||||||
Time *TestCaseTime `json:"time" yaml:"time"`
|
Time *TestCaseTime `json:"time" yaml:"time"`
|
||||||
InOut *TestCaseInOut `json:"in_out" yaml:"in_out"`
|
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"`
|
Records []*StepResult `json:"records" yaml:"records"`
|
||||||
RootDir string `json:"root_dir" yaml:"root_dir"`
|
RootDir string `json:"root_dir" yaml:"root_dir"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user