Methods
onSnapDefinitionsFromWindow() → {Promise}
Enables executing code at to compute SnapDefintions at runtime.
Returns:
- Type:
-
Promise
Type Definitions
onPostSnap()
Run code after a snap has been captured. See onPreSnap.
onPreSnap(snapDefinition, browserName, browserDriver) → {Promise}
Run arbitrary code before snapDefinition.selector
is
captured.
WARNING this code must be serializable, or serialized in advanced. This is because this code is run by a different process--a docker processes. Because we execute in a docker context, the docker process is responsible for calling the method. Therefore, make this code as simple as possible, or if you absolutely must have complexity here (please don't), you can bundle your JS into a string and eval it in. PRs welcome if folks want to build in rollup/webpack/etc to do this automatically.
Parameters:
Name | Type | Description |
---|---|---|
snapDefinition |
SnapDefinition
|
snap definition for element about to be captured |
browserName |
string
|
chrome, firefox, etc |
browserDriver |
*
|
browser adapter used to perform screenshots |
Returns:
- Type:
-
Promise
can be async or sync.
Example
// example: run code in the browser context to ready it for snapping
// https://github.com/GoogleChrome/puppeteer/blob/6512ce768ddce790095e2201d8ada3c24407fc57/docs/api.md#pageevaluatepagefunction-args
{
selector: '#test',
name: 'test',
onPreSnap: function revealElement (snapDefinition, browserName, browserDriver) {
if (browserName.match(/chrome/i)) {
browserDriver.evaluate(function revealElement (selector) {
return window.myApp.show(selector)
}, snapDefinition.selector)
}
}
}
SnapDefinition
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
selector |
string
|
css selector for single element to capture |
|
name |
string
|
basename for .png file |
|
onPreSnap |
onPreSnap
|
<optional> |
run code before a capture |
onPostSnap |
onPostSnap
|
<optional> |
run code after a capture |
SnapsConfig
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
staticDirectory |
string
|
|||
runId |
Number
|
<optional> |
Date.now() | |
url |
string
|
<optional> |
||
snapDefinitions |
Array.<SnapDefinition>
|
<optional> |
||
snapDefinitionsFromWindow |
onSnapDefinitionsFromWindow
|
<optional> |
||
snapRunRoot |
string
|
<optional> |
`pwd`/snaps/run | |
snapRefRoot |
string
|
<optional> |
`pwd`/snaps/ref | |
report |
boolean
|
<optional> |
true | generate a static web-application to
highlight image changes. report will be placed into snaps/run/ |