mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
refactor: pass ui type params to WithScreenShotUITypes
This commit is contained in:
+11
-10
@@ -113,10 +113,10 @@ type ActionOptions struct {
|
|||||||
Custom map[string]interface{} `json:"custom,omitempty" yaml:"custom,omitempty"`
|
Custom map[string]interface{} `json:"custom,omitempty" yaml:"custom,omitempty"`
|
||||||
|
|
||||||
// screenshot related
|
// screenshot related
|
||||||
ScreenShotWithOCR bool `json:"screenshot_with_ocr,omitempty" yaml:"screenshot_with_ocr,omitempty"`
|
ScreenShotWithOCR bool `json:"screenshot_with_ocr,omitempty" yaml:"screenshot_with_ocr,omitempty"`
|
||||||
ScreenShotWithUpload bool `json:"screenshot_with_upload,omitempty" yaml:"screenshot_with_upload,omitempty"`
|
ScreenShotWithUpload bool `json:"screenshot_with_upload,omitempty" yaml:"screenshot_with_upload,omitempty"`
|
||||||
ScreenShotWithLiveType bool `json:"screenshot_with_live_type,omitempty" yaml:"screenshot_with_live_type,omitempty"`
|
ScreenShotWithLiveType bool `json:"screenshot_with_live_type,omitempty" yaml:"screenshot_with_live_type,omitempty"`
|
||||||
ScreenShotWithUIType bool `json:"screenshot_with_ui_type,omitempty" yaml:"screenshot_with_ui_type,omitempty"`
|
ScreenShotWithUITypes []string `json:"screenshot_with_ui_types,omitempty" yaml:"screenshot_with_ui_types,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ActionOptions) Options() []ActionOption {
|
func (o *ActionOptions) Options() []ActionOption {
|
||||||
@@ -201,14 +201,14 @@ func (o *ActionOptions) Options() []ActionOption {
|
|||||||
if o.ScreenShotWithLiveType {
|
if o.ScreenShotWithLiveType {
|
||||||
options = append(options, WithScreenShotLiveType(true))
|
options = append(options, WithScreenShotLiveType(true))
|
||||||
}
|
}
|
||||||
if o.ScreenShotWithUIType {
|
if len(o.ScreenShotWithUITypes) > 0 {
|
||||||
options = append(options, WithScreenShotUIType(true))
|
options = append(options, WithScreenShotUITypes(o.ScreenShotWithUITypes...))
|
||||||
}
|
}
|
||||||
|
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ActionOptions) screenshotOptions() screenshotActionOptions {
|
func (o *ActionOptions) screenshotActionOptions() screenshotActionOptions {
|
||||||
options := screenshotActionOptions{}
|
options := screenshotActionOptions{}
|
||||||
if o.ScreenShotWithOCR {
|
if o.ScreenShotWithOCR {
|
||||||
options = append(options, "ocr")
|
options = append(options, "ocr")
|
||||||
@@ -219,7 +219,8 @@ func (o *ActionOptions) screenshotOptions() screenshotActionOptions {
|
|||||||
if o.ScreenShotWithLiveType {
|
if o.ScreenShotWithLiveType {
|
||||||
options = append(options, "liveType")
|
options = append(options, "liveType")
|
||||||
}
|
}
|
||||||
if o.ScreenShotWithUIType {
|
// UI detection
|
||||||
|
if len(o.ScreenShotWithUITypes) > 0 {
|
||||||
options = append(options, "ui")
|
options = append(options, "ui")
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
@@ -418,9 +419,9 @@ func WithScreenShotLiveType(liveTypeOn bool) ActionOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithScreenShotUIType(uiTypeOn bool) ActionOption {
|
func WithScreenShotUITypes(uiTypes ...string) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.ScreenShotWithUIType = uiTypeOn
|
o.ScreenShotWithUITypes = uiTypes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -342,10 +342,12 @@ type IImageService interface {
|
|||||||
|
|
||||||
// GetScreenResult takes a screenshot, returns the image recognization result
|
// GetScreenResult takes a screenshot, returns the image recognization result
|
||||||
func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) {
|
func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) {
|
||||||
screenshotOptions := NewActionOptions(options...).screenshotOptions()
|
actionOptions := NewActionOptions(options...)
|
||||||
|
screenActionOptions := actionOptions.screenshotActionOptions()
|
||||||
|
screenUITypeOptions := screenshotUITypeOptions(actionOptions.ScreenShotWithUITypes)
|
||||||
|
|
||||||
var fileName string
|
var fileName string
|
||||||
if len(screenshotOptions) == 0 {
|
if len(screenActionOptions) == 0 {
|
||||||
fileName = builtin.GenNameWithTimestamp("%d_screenshot")
|
fileName = builtin.GenNameWithTimestamp("%d_screenshot")
|
||||||
} else {
|
} else {
|
||||||
fileName = builtin.GenNameWithTimestamp("%d_cv")
|
fileName = builtin.GenNameWithTimestamp("%d_cv")
|
||||||
@@ -366,8 +368,9 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
|||||||
}
|
}
|
||||||
|
|
||||||
var imageUrl string
|
var imageUrl string
|
||||||
if len(screenshotOptions) > 0 {
|
if len(screenActionOptions) > 0 {
|
||||||
imageResult, err := dExt.ImageService.GetImage(bufSource, screenshotOptions)
|
imageResult, err := dExt.ImageService.GetImage(bufSource,
|
||||||
|
screenActionOptions, screenUITypeOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("GetImage from ImageService failed")
|
log.Error().Err(err).Msg("GetImage from ImageService failed")
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user