mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-31 02:37:28 +08:00
fix: driver tests
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2502181444
|
v5.0.0+2502181539
|
||||||
|
|||||||
@@ -140,16 +140,16 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
ACTION_SwipeToTapApp, action.Params)
|
ACTION_SwipeToTapApp, action.Params)
|
||||||
case ACTION_SwipeToTapText:
|
case ACTION_SwipeToTapText:
|
||||||
if text, ok := action.Params.(string); ok {
|
if text, ok := action.Params.(string); ok {
|
||||||
return dExt.swipeToTapTexts([]string{text}, action.GetOptions()...)
|
return dExt.SwipeToTapTexts([]string{text}, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
||||||
ACTION_SwipeToTapText, action.Params)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
case ACTION_SwipeToTapTexts:
|
case ACTION_SwipeToTapTexts:
|
||||||
if texts, ok := action.Params.([]string); ok {
|
if texts, ok := action.Params.([]string); ok {
|
||||||
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
return dExt.SwipeToTapTexts(texts, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
if texts, err := builtin.ConvertToStringSlice(action.Params); err == nil {
|
if texts, err := builtin.ConvertToStringSlice(action.Params); err == nil {
|
||||||
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
return dExt.SwipeToTapTexts(texts, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
||||||
case ACTION_AppTerminate:
|
case ACTION_AppTerminate:
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func prepareSwipeAction(dExt *XTDriver, params interface{}, opts ...option.Actio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) swipeToTapTexts(texts []string, opts ...option.ActionOption) error {
|
func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOption) error {
|
||||||
if len(texts) == 0 {
|
if len(texts) == 0 {
|
||||||
return errors.New("no text to tap")
|
return errors.New("no text to tap")
|
||||||
}
|
}
|
||||||
@@ -152,12 +152,9 @@ func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption)
|
|||||||
}
|
}
|
||||||
|
|
||||||
opts = append(opts, option.WithDirection("left"))
|
opts = append(opts, option.WithDirection("left"))
|
||||||
|
opts = append(opts, option.WithMaxRetryTimes(5))
|
||||||
|
|
||||||
actionOptions := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
// default to retry 5 times
|
|
||||||
if actionOptions.MaxRetryTimes == 0 {
|
|
||||||
opts = append(opts, option.WithMaxRetryTimes(5))
|
|
||||||
}
|
|
||||||
// tap app icon above the text
|
// tap app icon above the text
|
||||||
if len(actionOptions.Offset) == 0 {
|
if len(actionOptions.Offset) == 0 {
|
||||||
opts = append(opts, option.WithTapOffset(0, -25))
|
opts = append(opts, option.WithTapOffset(0, -25))
|
||||||
@@ -167,5 +164,5 @@ func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption)
|
|||||||
opts = append(opts, option.WithInterval(1))
|
opts = append(opts, option.WithInterval(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
return dExt.swipeToTapTexts([]string{appName}, opts...)
|
return dExt.SwipeToTapTexts([]string{appName}, opts...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,27 +3,29 @@
|
|||||||
package uixt
|
package uixt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/internal/config"
|
|
||||||
"github.com/httprunner/httprunner/v5/pkg/uixt/ai"
|
"github.com/httprunner/httprunner/v5/pkg/uixt/ai"
|
||||||
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
|
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewDriver1(t *testing.T) {
|
func TestDriverExt_NewMethod1(t *testing.T) {
|
||||||
device, _ := NewAndroidDevice(option.WithUIA2(true))
|
device, err := NewAndroidDevice(option.WithUIA2(true))
|
||||||
driver, _ := device.NewDriver()
|
require.Nil(t, err)
|
||||||
|
driver, err := device.NewDriver()
|
||||||
|
require.Nil(t, err)
|
||||||
driverExt := NewXTDriver(driver,
|
driverExt := NewXTDriver(driver,
|
||||||
ai.WithCVService(ai.CVServiceTypeVEDEM))
|
ai.WithCVService(ai.CVServiceTypeVEDEM))
|
||||||
driverExt.TapByOCR("推荐")
|
driverExt.TapByOCR("推荐")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewDriver2(t *testing.T) {
|
func TestDriverExt_NewMethod2(t *testing.T) {
|
||||||
device, _ := NewAndroidDevice()
|
device, err := NewAndroidDevice()
|
||||||
driver, _ := NewUIA2Driver(device)
|
require.Nil(t, err)
|
||||||
|
driver, err := NewUIA2Driver(device)
|
||||||
|
require.Nil(t, err)
|
||||||
driverExt := NewXTDriver(driver,
|
driverExt := NewXTDriver(driver,
|
||||||
ai.WithCVService(ai.CVServiceTypeVEDEM))
|
ai.WithCVService(ai.CVServiceTypeVEDEM))
|
||||||
driverExt.TapByOCR("推荐")
|
driverExt.TapByOCR("推荐")
|
||||||
@@ -80,7 +82,13 @@ func setupDriverExt(t *testing.T) *XTDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAndroidSwipeAction(t *testing.T) {
|
func TestDriverExt_TapByOCR(t *testing.T) {
|
||||||
|
driver := setupDriverExt(t)
|
||||||
|
err := driver.TapByOCR("天气")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDriverExt_prepareSwipeAction(t *testing.T) {
|
||||||
driver := setupDriverExt(t)
|
driver := setupDriverExt(t)
|
||||||
|
|
||||||
swipeAction := prepareSwipeAction(driver, "up", option.WithDirection("down"))
|
swipeAction := prepareSwipeAction(driver, "up", option.WithDirection("down"))
|
||||||
@@ -92,69 +100,37 @@ func TestAndroidSwipeAction(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAndroidSwipeToTapApp(t *testing.T) {
|
func TestDriverExt_SwipeToTapApp(t *testing.T) {
|
||||||
driver := setupDriverExt(t)
|
driver := setupDriverExt(t)
|
||||||
err := driver.SwipeToTapApp("抖音")
|
err := driver.SwipeToTapApp("抖音")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAndroidSwipeToTapTexts(t *testing.T) {
|
func TestDriverExt_SwipeToTapTexts(t *testing.T) {
|
||||||
driver := setupDriverExt(t)
|
driver := setupDriverExt(t)
|
||||||
err := driver.AppLaunch("com.ss.android.ugc.aweme")
|
err := driver.AppLaunch("com.ss.android.ugc.aweme")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
err = driver.swipeToTapTexts([]string{"点击进入直播间", "直播中"}, option.WithDirection("up"))
|
err = driver.SwipeToTapTexts(
|
||||||
|
[]string{"点击进入直播间", "直播中"},
|
||||||
|
option.WithDirection("up"),
|
||||||
|
option.WithMaxRetryTimes(10))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetScreenShot(t *testing.T) {
|
func TestDriverExt_CheckPopup(t *testing.T) {
|
||||||
driver := setupADBDriverExt(t)
|
|
||||||
|
|
||||||
imagePath := filepath.Join(config.ScreenShotsPath, "test_screenshot")
|
|
||||||
_, err := driver.ScreenShot(option.WithScreenShotFileName(imagePath))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("GetScreenShot failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Logf("screenshot saved at: %s", imagePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCheckPopup(t *testing.T) {
|
|
||||||
driver := setupADBDriverExt(t)
|
driver := setupADBDriverExt(t)
|
||||||
popup, err := driver.CheckPopup()
|
popup, err := driver.CheckPopup()
|
||||||
if err != nil {
|
require.Nil(t, err)
|
||||||
t.Logf("check popup failed, err: %v", err)
|
if popup == nil {
|
||||||
} else if popup == nil {
|
|
||||||
t.Log("no popup found")
|
t.Log("no popup found")
|
||||||
} else {
|
} else {
|
||||||
t.Logf("found popup: %v", popup)
|
t.Logf("found popup: %v", popup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClosePopup(t *testing.T) {
|
func TestDriverExt_ClosePopupsHandler(t *testing.T) {
|
||||||
driver := setupADBDriverExt(t)
|
driver := setupADBDriverExt(t)
|
||||||
if err := driver.ClosePopupsHandler(); err != nil {
|
err := driver.ClosePopupsHandler()
|
||||||
t.Fatal(err)
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func matchPopup(text string) bool {
|
|
||||||
for _, popup := range popups {
|
|
||||||
if regexp.MustCompile(popup[1]).MatchString(text) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMatchRegex(t *testing.T) {
|
|
||||||
testData := []string{
|
|
||||||
"以后再说", "我知道了", "同意", "拒绝", "稍后",
|
|
||||||
"始终允许", "继续使用", "仅在使用中允许",
|
|
||||||
}
|
|
||||||
for _, text := range testData {
|
|
||||||
if !matchPopup(text) {
|
|
||||||
t.Fatal(text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user