Documentation
¶
Overview ¶
Package screenshot supports taking and examining screenshots; contains helper utils to work with screenshot files.
Index ¶
- Variables
- func Capture(ctx context.Context, path string) error
- func CaptureCDP(ctx context.Context, conn *ash.DevtoolsConn, path string) error
- func CaptureChrome(ctx context.Context, cr *chrome.Chrome, path string) error
- func CaptureChromeForDisplay(ctx context.Context, cr *chrome.Chrome, displayID, path string) error
- func CaptureChromeImage(ctx context.Context, cr *chrome.Chrome) (image.Image, error)
- func CaptureChromeImageWithTestAPI(ctx context.Context, tconn *chrome.TestConn) (image.Image, error)
- func CaptureWithStderr(ctx context.Context, path string) error
- func DiffPerConfig(ctx context.Context, state screenshotState, configs []Config, fn func(Differ)) error
- func GrabAndCropScreenshot(ctx context.Context, cr *chrome.Chrome, bounds coords.Rect) (image.Image, error)
- func GrabScreenshot(ctx context.Context, cr *chrome.Chrome) (image.Image, error)
- func HasScreenshots() (bool, error)
- func RemoveScreenshots() error
- type Config
- type Differ
- type Option
- func PixelDeltaThreshold(pixelDeltaThreshold int) Option
- func RemoveElements(removeElements []*nodewith.Finder) Option
- func Retries(retries int) Option
- func RetryInterval(retryInterval time.Duration) Option
- func SkipWindowMove(skipWindowMove bool) Option
- func SkipWindowResize(skipWindowResize bool) Option
- func Timeout(timeout time.Duration) Option
- func WindowBorderWidthDP(windowBorderWidthDP int) Option
- func WindowHeightDP(windowHeightDP int) Option
- func WindowWidthDP(windowWidthDP int) Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var ScreenDiffVars = []string{
goldServiceAccountKeyVar,
screendiffDebugVar,
screendiffDryrunVar,
}
ScreenDiffVars contains a list of all variables used by the screendiff library.
Functions ¶
func Capture ¶
Capture takes a screenshot and saves it as a PNG image to the specified file path. It will use the CLI screenshot command to perform the screen capture.
func CaptureCDP ¶
CaptureCDP takes a screenshot and saves it as a PNG image at path, similar to CaptureChrome. The diff from CaptureChrome is that this function takes *cdputil.Conn, which is used by chrome.Conn. Thus, CaptureChrome records logs in case of error, while this does not. XXX
func CaptureChrome ¶
CaptureChrome takes a screenshot of the primary display and saves it as a PNG image to the specified file path. It will use Chrome to perform the screen capture.
func CaptureChromeForDisplay ¶
CaptureChromeForDisplay takes a screenshot for a given displayID and saves it as a PNG image to the specified file path. It will use Chrome to perform the screen capture.
func CaptureChromeImage ¶
CaptureChromeImage takes a screenshot of the primary display and returns it as an image.Image. It will use Chrome to perform the screen capture.
func CaptureChromeImageWithTestAPI ¶
func CaptureChromeImageWithTestAPI(ctx context.Context, tconn *chrome.TestConn) (image.Image, error)
CaptureChromeImageWithTestAPI takes a screenshot of the primary display and returns it as an image.Image. It will use Test API to perform the screen capture.
func CaptureWithStderr ¶
CaptureWithStderr differs from Capture in that it returns the stderr when capturing a screenshot fails. This is useful for verification on whether turning display on/off is successful by matching with the message, "CRTC not found. Is the screen on?".
func DiffPerConfig ¶
func DiffPerConfig(ctx context.Context, state screenshotState, configs []Config, fn func(Differ)) error
DiffPerConfig takes a function that performs a set of screenshot diff tests, and a set of configurations to run it on, and runs that screenshot test on each configuration.
func GrabAndCropScreenshot ¶
func GrabAndCropScreenshot(ctx context.Context, cr *chrome.Chrome, bounds coords.Rect) (image.Image, error)
GrabAndCropScreenshot grabs a screenshot and crops it to the specified bounds.
func GrabScreenshot ¶
GrabScreenshot creates a screenshot and returns an image.Image. The path of the image is generated ramdomly in /tmp.
func HasScreenshots ¶
HasScreenshots returns whether Download folder has screenshots.
func RemoveScreenshots ¶
func RemoveScreenshots() error
RemoveScreenshots removes screenshots from Download folder.
Types ¶
type Config ¶
type Config struct {
// The set of default options to use for diff tests.
DefaultOptions Options
// The region chrome should be started in. Should correspond to an entry in
// /usr/share/misc/cros-regions.json.
Region string
// The display.Info.ID for the display you want to take screenshots on.
// Required iff you have multiple displays.
DisplayID string
// Whether to skip attempting to scale the DPI so that all images are
// as similar as possible.
SkipDpiNormalization bool
// If DryRun is true, instead of running the goldctl imgtest, logs it.
DryRun bool
// Whether to output the UI tree for each screenshot.
OutputUITrees bool
// A suffix to add to the name. Might be a version number (eg. "V2"), or a
// human-readable label.
NameSuffix string
}
Config controls how the screen is rendered during screenshot tests.
func ThoroughConfigs ¶
func ThoroughConfigs() []Config
ThoroughConfigs is a set of configurations that should test most use cases.
type Differ ¶
type Differ interface {
Chrome() *chrome.Chrome
Tconn() *chrome.TestConn
Diff(context.Context, string, *nodewith.Finder, ...Option) uiauto.Action
DiffWindow(context.Context, string, ...Option) uiauto.Action
GetFailedDiffs() error
DieOnFailedDiffs()
}
Differ is a type for running screendiffs.
type Option ¶
type Option = func(*Options)
Option is a modifier to apply to Options.
func PixelDeltaThreshold ¶
PixelDeltaThreshold controls the screenshot test option PixelDeltaThreshold.
func RemoveElements ¶
RemoveElements controls the screenshot test option RemoveElements.
func RetryInterval ¶
RetryInterval controls the screenshot test option RetryInterval.
func SkipWindowMove ¶
SkipWindowMove controls the screenshot test option SkipWindowMove.
func SkipWindowResize ¶
SkipWindowResize controls the screenshot test option SkipWindowResize.
func WindowBorderWidthDP ¶
WindowBorderWidthDP controls the screenshot test option WindowBorderWidthDP.
func WindowHeightDP ¶
WindowHeightDP controls the screenshot test option WindowHeightDP.
func WindowWidthDP ¶
WindowWidthDP controls the screenshot test option WindowWidthDP.
type Options ¶
type Options struct {
// The time to spend looking for a node
Timeout time.Duration
// The minimum difference required to treat two pixels as different.
// Specifically, this is dr + dg + db (the sum of the difference in each channel).
PixelDeltaThreshold int
// The width and height requested of a window, in DP.
// You probably don't want to set this yourself - the screen diffing
// framework will tell you what to set this to.
WindowWidthDP int
WindowHeightDP int
// Whether to skip window resizing and moving respectively.
// If SkipWindowResize is true, WindowHeightDP and WindowWidthDP won't be required.
SkipWindowResize bool
SkipWindowMove bool
// Density independent pixels within this distance to a border (top / bottom / sides)
// of the window will not be considered when determining difference.
WindowBorderWidthDP int
// Elements that will be removed from the screenshot. For example, if you have
// some dynamic content interlaced with static content (eg. file modification
// times in the files app).
RemoveElements []*nodewith.Finder
// The number of times and interval between retries when taking screenshots.
// We retry for two reasons:
// 1) Check that any animations have completed (eg. attempting to move the
// window can be slow, and the ui tree updates before the window has
// finished moving).
// 2) Try and pick up on any ongoing animations during execution rather
// than in gold.
Retries int
RetryInterval time.Duration
}
Options provides all of the ways which you can configure the Diff method.
func (*Options) FillDefaults ¶
FillDefaults fills any unfilled fields in o with values from d.