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