mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 20:41:44 +08:00
fix: check WDA summary logs
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
{
|
{
|
||||||
"method": "swipe_to_tap_app",
|
"method": "swipe_to_tap_app",
|
||||||
"params": "$app_name",
|
"params": "$app_name",
|
||||||
|
"identifier": "启动抖音",
|
||||||
"max_retry_times": 5
|
"max_retry_times": 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -45,20 +46,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "在推荐页上划,直到出现「点击进入直播间」",
|
"name": "向上滑动 2 次",
|
||||||
"ios": {
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"method": "swipe_to_tap_text",
|
|
||||||
"params": "点击进入直播间",
|
|
||||||
"identifier": "进入直播间",
|
|
||||||
"max_retry_times": 100
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "向上滑动,等待 10s",
|
|
||||||
"ios": {
|
"ios": {
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
@@ -87,6 +75,19 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "在推荐页上划,直到出现「点击进入直播间」",
|
||||||
|
"ios": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"method": "swipe_to_tap_text",
|
||||||
|
"params": "点击进入直播间",
|
||||||
|
"identifier": "进入直播间",
|
||||||
|
"max_retry_times": 10
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ teststeps:
|
|||||||
params: com.ss.iphone.ugc.Aweme
|
params: com.ss.iphone.ugc.Aweme
|
||||||
- method: swipe_to_tap_app
|
- method: swipe_to_tap_app
|
||||||
params: $app_name
|
params: $app_name
|
||||||
|
identifier: 启动抖音
|
||||||
max_retry_times: 5
|
max_retry_times: 5
|
||||||
- method: sleep
|
- method: sleep
|
||||||
params: 5
|
params: 5
|
||||||
@@ -23,14 +24,7 @@ teststeps:
|
|||||||
assert: exists
|
assert: exists
|
||||||
expect: 推荐
|
expect: 推荐
|
||||||
msg: 抖音启动失败,「推荐」不存在
|
msg: 抖音启动失败,「推荐」不存在
|
||||||
- name: 在推荐页上划,直到出现「点击进入直播间」
|
- name: 向上滑动 2 次
|
||||||
ios:
|
|
||||||
actions:
|
|
||||||
- method: swipe_to_tap_text
|
|
||||||
params: 点击进入直播间
|
|
||||||
identifier: 进入直播间
|
|
||||||
max_retry_times: 100
|
|
||||||
- name: 向上滑动,等待 10s
|
|
||||||
ios:
|
ios:
|
||||||
actions:
|
actions:
|
||||||
- method: swipe
|
- method: swipe
|
||||||
@@ -45,3 +39,10 @@ teststeps:
|
|||||||
- method: sleep
|
- method: sleep
|
||||||
params: 2
|
params: 2
|
||||||
- method: screenshot
|
- method: screenshot
|
||||||
|
- name: 在推荐页上划,直到出现「点击进入直播间」
|
||||||
|
ios:
|
||||||
|
actions:
|
||||||
|
- method: swipe_to_tap_text
|
||||||
|
params: 点击进入直播间
|
||||||
|
identifier: 进入直播间
|
||||||
|
max_retry_times: 10
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package uitest
|
package uitest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp"
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
@@ -19,19 +18,19 @@ func TestIOSDouyinLive(t *testing.T) {
|
|||||||
IOS().
|
IOS().
|
||||||
Home().
|
Home().
|
||||||
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
|
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
|
||||||
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5)).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("在推荐页上划,直到出现「点击进入直播间」").
|
hrp.NewStep("向上滑动 2 次").
|
||||||
IOS().
|
|
||||||
SwipeToTapText("点击进入直播间", hrp.WithMaxRetryTimes(100), hrp.WithIdentifier("进入直播间")),
|
|
||||||
hrp.NewStep("向上滑动,等待 10s").
|
|
||||||
IOS().
|
IOS().
|
||||||
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存
|
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存
|
||||||
SwipeUp(hrp.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s,截图保存
|
SwipeUp(hrp.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s,截图保存
|
||||||
|
hrp.NewStep("在推荐页上划,直到出现「点击进入直播间」").
|
||||||
|
IOS().
|
||||||
|
SwipeToTapText("点击进入直播间", hrp.WithMaxRetryTimes(10), hrp.WithIdentifier("进入直播间")),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +41,9 @@ func TestIOSDouyinLive(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runner := hrp.NewRunner(t)
|
runner := hrp.NewRunner(t).SetSaveTests(true)
|
||||||
sessionRunner, err := runner.NewSessionRunner(testCase)
|
err := runner.Run(testCase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := sessionRunner.Start(nil); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
summary := sessionRunner.GetSummary()
|
|
||||||
fmt.Println(summary)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package uitest
|
package uitest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp"
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
@@ -43,14 +42,9 @@ func TestIOSWeixinLive(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runner := hrp.NewRunner(t)
|
runner := hrp.NewRunner(t).SetSaveTests(true)
|
||||||
sessionRunner, err := runner.NewSessionRunner(testCase)
|
err := runner.Run(testCase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := sessionRunner.Start(nil); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
summary := sessionRunner.GetSummary()
|
|
||||||
fmt.Println(summary)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ func WithThreshold(threshold float64) CVOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DriverExt struct {
|
type DriverExt struct {
|
||||||
|
Device Device
|
||||||
Driver WebDriver
|
Driver WebDriver
|
||||||
windowSize Size
|
windowSize Size
|
||||||
frame *bytes.Buffer
|
frame *bytes.Buffer
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ func InitWDAClient(device *IOSDevice) (*DriverExt, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
driverExt.Device = iosDevice
|
||||||
return driverExt, nil
|
return driverExt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,10 +210,10 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for it := sessionRunner.parametersIterator; it.HasNext(); {
|
for it := sessionRunner.parametersIterator; it.HasNext(); {
|
||||||
err = sessionRunner.Start(it.Next())
|
err1 := sessionRunner.Start(it.Next())
|
||||||
caseSummary := sessionRunner.GetSummary()
|
caseSummary, err2 := sessionRunner.GetSummary()
|
||||||
s.appendCaseSummary(caseSummary)
|
s.appendCaseSummary(caseSummary)
|
||||||
if err != nil {
|
if err1 != nil || err2 != nil {
|
||||||
log.Error().Err(err).Msg("[Run] run testcase failed")
|
log.Error().Err(err).Msg("[Run] run testcase failed")
|
||||||
runErr = err
|
runErr = err
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import (
|
|||||||
"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.
|
||||||
@@ -151,7 +149,7 @@ func (r *SessionRunner) updateSessionVariables(parameters map[string]interface{}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SessionRunner) GetSummary() *TestCaseSummary {
|
func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
||||||
caseSummary := r.summary
|
caseSummary := r.summary
|
||||||
caseSummary.Name = r.parsedConfig.Name
|
caseSummary.Name = r.parsedConfig.Name
|
||||||
caseSummary.Time.StartAt = r.startTime
|
caseSummary.Time.StartAt = r.startTime
|
||||||
@@ -163,19 +161,16 @@ func (r *SessionRunner) GetSummary() *TestCaseSummary {
|
|||||||
caseSummary.InOut.ExportVars = exportVars
|
caseSummary.InOut.ExportVars = exportVars
|
||||||
caseSummary.InOut.ConfigVars = r.parsedConfig.Variables
|
caseSummary.InOut.ConfigVars = r.parsedConfig.Variables
|
||||||
|
|
||||||
|
// add WDA/UIA logs to summary
|
||||||
logs := make(map[string]string)
|
logs := make(map[string]string)
|
||||||
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 {
|
||||||
logs[udid] = err.Error()
|
return nil, err
|
||||||
} else {
|
|
||||||
logs[udid] = log
|
|
||||||
}
|
}
|
||||||
|
logs[udid] = log
|
||||||
}
|
}
|
||||||
logsStr, _ := json.Marshal(logs)
|
caseSummary.Logs = logs
|
||||||
caseSummary.Logs = string(logsStr)
|
|
||||||
|
|
||||||
// caseSummary.Log
|
return caseSummary, nil
|
||||||
return caseSummary
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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[uuid] = client
|
r.uiClients[client.Device.UUID()] = client
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func TestRunRequestStatOn(t *testing.T) {
|
|||||||
if err := sessionRunner.Start(nil); err != nil {
|
if err := sessionRunner.Start(nil); err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
summary := sessionRunner.GetSummary()
|
summary, _ := sessionRunner.GetSummary()
|
||||||
|
|
||||||
stat := summary.Records[0].HttpStat
|
stat := summary.Records[0].HttpStat
|
||||||
if !assert.GreaterOrEqual(t, stat["DNSLookup"], int64(0)) {
|
if !assert.GreaterOrEqual(t, stat["DNSLookup"], int64(0)) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,11 +90,17 @@ func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (stepResult *StepRe
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
// run referenced testcase with step variables
|
// run referenced testcase with step variables
|
||||||
err = sessionRunner.Start(stepVariables)
|
err = sessionRunner.Start(stepVariables)
|
||||||
if err == nil {
|
|
||||||
stepResult.Success = true
|
|
||||||
}
|
|
||||||
stepResult.Elapsed = time.Since(start).Milliseconds()
|
stepResult.Elapsed = time.Since(start).Milliseconds()
|
||||||
summary := sessionRunner.GetSummary()
|
|
||||||
|
summary, err2 := sessionRunner.GetSummary()
|
||||||
|
if err2 != nil {
|
||||||
|
log.Error().Err(err).Msg("get summary failed")
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, err2.Error())
|
||||||
|
} else {
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
|
}
|
||||||
// update step names
|
// update step names
|
||||||
for _, record := range summary.Records {
|
for _, record := range summary.Records {
|
||||||
record.Name = fmt.Sprintf("%s - %s", stepResult.Name, record.Name)
|
record.Name = fmt.Sprintf("%s - %s", stepResult.Name, record.Name)
|
||||||
@@ -108,5 +115,8 @@ func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (stepResult *StepRe
|
|||||||
r.summary.Stat.Successes += summary.Stat.Successes
|
r.summary.Stat.Successes += summary.Stat.Successes
|
||||||
r.summary.Stat.Failures += summary.Stat.Failures
|
r.summary.Stat.Failures += summary.Stat.Failures
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
stepResult.Success = true
|
||||||
|
}
|
||||||
return stepResult, err
|
return stepResult, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 string `json:"logs,omitempty" yaml:"logs,omitempty"` // TODO
|
Logs interface{} `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