mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
change: DriverExt WindowSize
This commit is contained in:
@@ -522,10 +522,10 @@ func (dExt *DriverExt) ParseActionOptions(options ...ActionOption) []ActionOptio
|
|||||||
|
|
||||||
func (dExt *DriverExt) GenAbsScope(x1, y1, x2, y2 float64) AbsScope {
|
func (dExt *DriverExt) GenAbsScope(x1, y1, x2, y2 float64) AbsScope {
|
||||||
// convert relative scope to absolute scope
|
// convert relative scope to absolute scope
|
||||||
absX1 := int(x1 * float64(dExt.windowSize.Width))
|
absX1 := int(x1 * float64(dExt.WindowSize.Width))
|
||||||
absY1 := int(y1 * float64(dExt.windowSize.Height))
|
absY1 := int(y1 * float64(dExt.WindowSize.Height))
|
||||||
absX2 := int(x2 * float64(dExt.windowSize.Width))
|
absX2 := int(x2 * float64(dExt.WindowSize.Width))
|
||||||
absY2 := int(y2 * float64(dExt.windowSize.Height))
|
absY2 := int(y2 * float64(dExt.WindowSize.Height))
|
||||||
return AbsScope{absX1, absY1, absX2, absY2}
|
return AbsScope{absX1, absY1, absX2, absY2}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -52,7 +52,7 @@ func WithThreshold(threshold float64) CVOption {
|
|||||||
type ScreenResult struct {
|
type ScreenResult struct {
|
||||||
bufSource *bytes.Buffer // raw image buffer bytes
|
bufSource *bytes.Buffer // raw image buffer bytes
|
||||||
imagePath string // image file path
|
imagePath string // image file path
|
||||||
imageResult *ImageResult // image result
|
ImageResult *ImageResult // image result
|
||||||
|
|
||||||
Resolution Size `json:"resolution"`
|
Resolution Size `json:"resolution"`
|
||||||
UploadedURL string `json:"uploaded_url"` // uploaded image url
|
UploadedURL string `json:"uploaded_url"` // uploaded image url
|
||||||
@@ -110,7 +110,7 @@ type DriverExt struct {
|
|||||||
CVArgs
|
CVArgs
|
||||||
Device Device
|
Device Device
|
||||||
Driver WebDriver
|
Driver WebDriver
|
||||||
windowSize Size
|
WindowSize Size
|
||||||
frame *bytes.Buffer
|
frame *bytes.Buffer
|
||||||
doneMjpegStream chan bool
|
doneMjpegStream chan bool
|
||||||
ImageService IImageService // used to extract image data
|
ImageService IImageService // used to extract image data
|
||||||
@@ -146,7 +146,7 @@ func newDriverExt(device Device, driver WebDriver, plugin funplugin.IPlugin) (dE
|
|||||||
dExt.doneMjpegStream = make(chan bool, 1)
|
dExt.doneMjpegStream = make(chan bool, 1)
|
||||||
|
|
||||||
// get device window size
|
// get device window size
|
||||||
dExt.windowSize, err = dExt.Driver.WindowSize()
|
dExt.WindowSize, err = dExt.Driver.WindowSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "get screen resolution failed")
|
return nil, errors.Wrap(err, "get screen resolution failed")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
|||||||
bufSource: bufSource,
|
bufSource: bufSource,
|
||||||
imagePath: imagePath,
|
imagePath: imagePath,
|
||||||
Tags: nil,
|
Tags: nil,
|
||||||
Resolution: dExt.windowSize,
|
Resolution: dExt.WindowSize,
|
||||||
ScreenshotTakeElapsed: screenshotTakeElapsed,
|
ScreenshotTakeElapsed: screenshotTakeElapsed,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +413,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
|||||||
return screenResult, err
|
return screenResult, err
|
||||||
}
|
}
|
||||||
if imageResult != nil {
|
if imageResult != nil {
|
||||||
screenResult.imageResult = imageResult
|
screenResult.ImageResult = imageResult
|
||||||
screenResult.ScreenshotCVElapsed = time.Since(startTime).Milliseconds() - screenshotTakeElapsed
|
screenResult.ScreenshotCVElapsed = time.Since(startTime).Milliseconds() - screenshotTakeElapsed
|
||||||
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
||||||
screenResult.UploadedURL = imageResult.URL
|
screenResult.UploadedURL = imageResult.URL
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ func assertRelative(p float64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUpUtil(count int64, options ...ActionOption) error {
|
func (dExt *DriverExt) SwipeUpUtil(count int64, options ...ActionOption) error {
|
||||||
width := dExt.windowSize.Width
|
width := dExt.WindowSize.Width
|
||||||
height := dExt.windowSize.Height
|
height := dExt.WindowSize.Height
|
||||||
|
|
||||||
fromX := float64(width) * directionSlice[count%3][0]
|
fromX := float64(width) * directionSlice[count%3][0]
|
||||||
fromY := float64(height) * directionSlice[count%3][1]
|
fromY := float64(height) * directionSlice[count%3][1]
|
||||||
@@ -35,8 +35,8 @@ func (dExt *DriverExt) SwipeUpUtil(count int64, options ...ActionOption) error {
|
|||||||
|
|
||||||
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
||||||
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
width := dExt.windowSize.Width
|
width := dExt.WindowSize.Width
|
||||||
height := dExt.windowSize.Height
|
height := dExt.WindowSize.Height
|
||||||
orientation, err := dExt.Driver.Orientation()
|
orientation, err := dExt.Driver.Orientation()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) get orientation failed, use default orientation",
|
log.Warn().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) get orientation failed, use default orientation",
|
||||||
|
|||||||
+8
-8
@@ -24,11 +24,11 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error {
|
|||||||
orientation = OrientationPortrait
|
orientation = OrientationPortrait
|
||||||
}
|
}
|
||||||
if orientation == OrientationPortrait {
|
if orientation == OrientationPortrait {
|
||||||
x = x * float64(dExt.windowSize.Width)
|
x = x * float64(dExt.WindowSize.Width)
|
||||||
y = y * float64(dExt.windowSize.Height)
|
y = y * float64(dExt.WindowSize.Height)
|
||||||
} else {
|
} else {
|
||||||
x = x * float64(dExt.windowSize.Height)
|
x = x * float64(dExt.WindowSize.Height)
|
||||||
y = y * float64(dExt.windowSize.Width)
|
y = y * float64(dExt.WindowSize.Width)
|
||||||
}
|
}
|
||||||
return dExt.TapAbsXY(x, y, options...)
|
return dExt.TapAbsXY(x, y, options...)
|
||||||
}
|
}
|
||||||
@@ -105,11 +105,11 @@ func (dExt *DriverExt) DoubleTapXY(x, y float64) error {
|
|||||||
orientation = OrientationPortrait
|
orientation = OrientationPortrait
|
||||||
}
|
}
|
||||||
if orientation == OrientationPortrait {
|
if orientation == OrientationPortrait {
|
||||||
x = x * float64(dExt.windowSize.Width)
|
x = x * float64(dExt.WindowSize.Width)
|
||||||
y = y * float64(dExt.windowSize.Height)
|
y = y * float64(dExt.WindowSize.Height)
|
||||||
} else {
|
} else {
|
||||||
x = x * float64(dExt.windowSize.Height)
|
x = x * float64(dExt.WindowSize.Height)
|
||||||
y = y * float64(dExt.windowSize.Width)
|
y = y * float64(dExt.WindowSize.Width)
|
||||||
}
|
}
|
||||||
return dExt.Driver.DoubleTapFloat(x, y)
|
return dExt.Driver.DoubleTapFloat(x, y)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -228,8 +228,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
// enter live room
|
// enter live room
|
||||||
entryPoint := PointF{
|
entryPoint := PointF{
|
||||||
X: float64(dExt.windowSize.Width / 2),
|
X: float64(dExt.WindowSize.Width / 2),
|
||||||
Y: float64(dExt.windowSize.Height / 2),
|
Y: float64(dExt.WindowSize.Height / 2),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msg("tap screen center to enter live room")
|
log.Info().Msg("tap screen center to enter live room")
|
||||||
@@ -265,10 +265,10 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add live type
|
// add live type
|
||||||
if screenResult.imageResult != nil &&
|
if screenResult.ImageResult != nil &&
|
||||||
screenResult.imageResult.LiveType != "" &&
|
screenResult.ImageResult.LiveType != "" &&
|
||||||
screenResult.imageResult.LiveType != "NoLive" {
|
screenResult.ImageResult.LiveType != "NoLive" {
|
||||||
currentVideo.LiveType = screenResult.imageResult.LiveType
|
currentVideo.LiveType = screenResult.ImageResult.LiveType
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulation watch live video
|
// simulation watch live video
|
||||||
@@ -276,7 +276,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
sleepStrict(swipeFinishTime, int64(simulationPlayDuration))
|
sleepStrict(swipeFinishTime, int64(simulationPlayDuration))
|
||||||
|
|
||||||
screenResult.Video = currentVideo
|
screenResult.Video = currentVideo
|
||||||
screenResult.Resolution = dExt.windowSize
|
screenResult.Resolution = dExt.WindowSize
|
||||||
screenResult.SwipeStartTime = swipeStartTime.UnixMilli()
|
screenResult.SwipeStartTime = swipeStartTime.UnixMilli()
|
||||||
screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli()
|
screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli()
|
||||||
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||||
@@ -314,7 +314,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
log.Info().Interface("video", currentVideo).Msg(FOUND_FEED_SUCCESS)
|
log.Info().Interface("video", currentVideo).Msg(FOUND_FEED_SUCCESS)
|
||||||
|
|
||||||
screenResult := &ScreenResult{
|
screenResult := &ScreenResult{
|
||||||
Resolution: dExt.windowSize,
|
Resolution: dExt.WindowSize,
|
||||||
Video: currentVideo,
|
Video: currentVideo,
|
||||||
|
|
||||||
// log swipe timelines
|
// log swipe timelines
|
||||||
@@ -351,6 +351,7 @@ const (
|
|||||||
VideoType_PreviewLive VideoType = "PREVIEW-LIVE" // 直播预览流
|
VideoType_PreviewLive VideoType = "PREVIEW-LIVE" // 直播预览流
|
||||||
VideoType_Live VideoType = "LIVE"
|
VideoType_Live VideoType = "LIVE"
|
||||||
VideoType_Image VideoType = "IMAGE"
|
VideoType_Image VideoType = "IMAGE"
|
||||||
|
VideoType_AD VideoType = "AD"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Video struct {
|
type Video struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user