change: GenNameWithTimestamp

This commit is contained in:
lilong.129
2023-04-17 22:45:58 +08:00
parent a286e0f37f
commit 804e69037a
12 changed files with 151 additions and 17 deletions
@@ -0,0 +1,134 @@
{
"config": {
"name": "点播_抖音_滑动场景_随机间隔_android",
"variables": {
"device": "${ENV(SerialNumber)}"
},
"android": [
{
"serial": "$device"
}
]
},
"teststeps": [
{
"name": "启动抖音",
"android": {
"actions": [
{
"method": "app_terminate",
"params": "com.ss.android.ugc.aweme"
},
{
"method": "app_launch",
"params": "com.ss.android.ugc.aweme"
},
{
"method": "sleep",
"params": 10
}
]
},
"validate": [
{
"check": "ui_foreground_app",
"assert": "equal",
"expect": "com.ss.android.ugc.aweme",
"msg": "app [com.ss.android.ugc.aweme] should be in foreground"
}
]
},
{
"name": "处理青少年弹窗",
"android": {
"actions": [
{
"method": "tap_ocr",
"params": "我知道了",
"ignore_NotFoundError": true
}
]
}
},
{
"name": "滑动 Feed 3 次,随机间隔 0-5s",
"android": {
"actions": [
{
"method": "swipe",
"params": "up"
},
{
"method": "sleep_random",
"params": [
0,
5
]
}
]
},
"loops": 3
},
{
"name": "滑动 Feed 1 次,随机间隔 5-10s",
"android": {
"actions": [
{
"method": "swipe",
"params": "up"
},
{
"method": "sleep_random",
"params": [
5,
10
]
}
]
},
"loops": 1
},
{
"name": "滑动 Feed 10 次,70% 随机间隔 0-5s30% 随机间隔 5-10s",
"android": {
"actions": [
{
"method": "swipe",
"params": "up"
},
{
"method": "sleep_random",
"params": [
0,
5,
0.7,
5,
10,
0.3
]
}
]
},
"loops": 10
},
{
"name": "exit",
"android": {
"actions": [
{
"method": "app_terminate",
"params": "com.ss.android.ugc.aweme"
}
]
},
"validate": [
{
"check": "ui_foreground_app",
"assert": "not_equal",
"expect": "com.ss.android.ugc.aweme",
"msg": "app [com.ss.android.ugc.aweme] should not be in foreground"
}
]
}
]
}
@@ -50,7 +50,7 @@ func TestAndroidDouyinFeedTest(t *testing.T) {
}, },
} }
if err := testCase.Dump2JSON("demo_feed_random_slide.json"); err != nil { if err := testCase.Dump2JSON("demo_android_feed_random_swipe.json"); err != nil {
t.Fatal(err) t.Fatal(err)
} }
+1 -1
View File
@@ -109,7 +109,7 @@
} }
] ]
}, },
"loops": 10 "loops": 2
}, },
{ {
"name": "exit", "name": "exit",
@@ -45,10 +45,7 @@ func TestIOSDouyinLive(t *testing.T) {
}, },
} }
if err := testCase.Dump2JSON("demo_douyin_live.json"); err != nil { if err := testCase.Dump2JSON("demo_ios_live_swipe.json"); err != nil {
t.Fatal(err)
}
if err := testCase.Dump2YAML("demo_douyin_live.yaml"); err != nil {
t.Fatal(err) t.Fatal(err)
} }
+1 -1
View File
@@ -23,7 +23,7 @@ var screencapAndroidDevicesCmd = &cobra.Command{
return err return err
} }
filepath := fmt.Sprintf("%s.png", builtin.GenNameWithTimestamp("screencap_")) filepath := fmt.Sprintf("%s.png", builtin.GenNameWithTimestamp("screencap_%d"))
if err = ioutil.WriteFile(filepath, res, 0o644); err != nil { if err = ioutil.WriteFile(filepath, res, 0o644); err != nil {
return err return err
} }
+5 -2
View File
@@ -444,6 +444,9 @@ func Sign(ver string, ak string, sk string, body []byte) string {
return fmt.Sprintf("%v/%v", signKeyInfo, string(signResult)) return fmt.Sprintf("%v/%v", signKeyInfo, string(signResult))
} }
func GenNameWithTimestamp(prefix string) string { func GenNameWithTimestamp(tmpl string) string {
return fmt.Sprintf("%s%d", prefix, time.Now().Unix()) if !strings.Contains(tmpl, "%d") {
tmpl = tmpl + "_%d"
}
return fmt.Sprintf(tmpl, time.Now().Unix())
} }
+1 -1
View File
@@ -540,7 +540,7 @@ func (d *Device) InstallAPK(apk io.ReadSeeker) (string, error) {
return string(raw), err return string(raw), err
} }
remote := fmt.Sprintf("/data/local/tmp/%s.apk", builtin.GenNameWithTimestamp("gadb_remote_")) remote := fmt.Sprintf("/data/local/tmp/%s.apk", builtin.GenNameWithTimestamp("gadb_remote_%d"))
err := d.Push(apk, remote, time.Now()) err := d.Push(apk, remote, time.Now())
if err != nil { if err != nil {
return "", fmt.Errorf("error pushing: %v", err) return "", fmt.Errorf("error pushing: %v", err)
+1 -1
View File
@@ -698,7 +698,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
case CtlScreenShot: case CtlScreenShot:
// take screenshot // take screenshot
log.Info().Msg("take screenshot for current screen") log.Info().Msg("take screenshot for current screen")
_, err := dExt.TakeScreenShot(builtin.GenNameWithTimestamp("screenshot_")) _, err := dExt.TakeScreenShot(builtin.GenNameWithTimestamp("screenshot_%d"))
return err return err
case CtlStartCamera: case CtlStartCamera:
return dExt.Driver.StartCamera() return dExt.Driver.StartCamera()
+3 -3
View File
@@ -305,7 +305,7 @@ type OCRService interface {
func (dExt *DriverExt) GetTextsByOCR(options ...DataOption) (texts OCRTexts, err error) { func (dExt *DriverExt) GetTextsByOCR(options ...DataOption) (texts OCRTexts, err error) {
var bufSource *bytes.Buffer var bufSource *bytes.Buffer
if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("ocr_")); err != nil { if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("step_%d_ocr")); err != nil {
return return
} }
@@ -320,7 +320,7 @@ func (dExt *DriverExt) GetTextsByOCR(options ...DataOption) (texts OCRTexts, err
func (dExt *DriverExt) FindTextByOCR(ocrText string, options ...DataOption) (x, y, width, height float64, err error) { func (dExt *DriverExt) FindTextByOCR(ocrText string, options ...DataOption) (x, y, width, height float64, err error) {
var bufSource *bytes.Buffer var bufSource *bytes.Buffer
if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("ocr_")); err != nil { if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("step_%d_ocr")); err != nil {
return return
} }
@@ -338,7 +338,7 @@ func (dExt *DriverExt) FindTextByOCR(ocrText string, options ...DataOption) (x,
func (dExt *DriverExt) FindTextsByOCR(ocrTexts []string, options ...DataOption) (points [][]float64, err error) { func (dExt *DriverExt) FindTextsByOCR(ocrTexts []string, options ...DataOption) (points [][]float64, err error) {
var bufSource *bytes.Buffer var bufSource *bytes.Buffer
if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("ocr_")); err != nil { if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("step_%d_ocr")); err != nil {
return return
} }
+2 -2
View File
@@ -103,7 +103,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
if bufSearch, err = getBufFromDisk(search); err != nil { if bufSearch, err = getBufFromDisk(search); err != nil {
return nil, err return nil, err
} }
if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("cv_")); err != nil { if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("step_%d_cv")); err != nil {
return nil, err return nil, err
} }
@@ -118,7 +118,7 @@ func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...DataOpt
if bufSearch, err = getBufFromDisk(imagePath); err != nil { if bufSearch, err = getBufFromDisk(imagePath); err != nil {
return 0, 0, 0, 0, err return 0, 0, 0, 0, err
} }
if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("cv_")); err != nil { if bufSource, err = dExt.TakeScreenShot(builtin.GenNameWithTimestamp("step_%d_cv")); err != nil {
return 0, 0, 0, 0, err return 0, 0, 0, 0, err
} }
+1 -1
View File
@@ -602,7 +602,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
// take screenshot after each step // take screenshot after each step
_, err := uiDriver.TakeScreenShot( _, err := uiDriver.TakeScreenShot(
builtin.GenNameWithTimestamp("step_") + "_" + step.Name) builtin.GenNameWithTimestamp("step_%d_") + step.Name)
if err != nil { if err != nil {
log.Error().Err(err).Str("step", step.Name).Msg("take screenshot failed on step finished") log.Error().Err(err).Str("step", step.Name).Msg("take screenshot failed on step finished")
} }