Skip to content

Commit

Permalink
feat: add 'screenshotDelay' option
Browse files Browse the repository at this point in the history
adds the ability to specify delay before a screenshot is made
  • Loading branch information
DudaGod committed Jun 29, 2018
1 parent 4038fe9 commit ced8e9f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 63 deletions.
128 changes: 67 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,69 @@ Hermione is a utility for integration testing of web pages using [WebdriverIO](h
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Why you should choose hermione](#why-you-should-choose-hermione)
- [Easy to use](#easy-to-use)
- [Runs tests in parallel](#runs-tests-in-parallel)
- [Runs tests in subprocesses](#runs-tests-in-subprocesses)
- [Extensible](#extensible)
- [Retries failed tests](#retries-failed-tests)
- [Executes separate tests](#executes-separate-tests)
- [Skips tests in specific browsers](#skips-tests-in-specific-browsers)
- [Offers flexible test configuration](#offers-flexible-test-configuration)
- [Automatically initializes and closes grid sessions](#automatically-initializes-and-closes-grid-sessions)
- [Prerequisites](#prerequisites)
- [Hooks](#hooks)
- [Skip](#skip)
- [Only](#only)
- [WebdriverIO extensions](#webdriverio-extensions)
- [Sharable meta info](#sharable-meta-info)
- [Execution context](#execution-context)
- [Quick start](#quick-start)
- [.hermione.conf.js](#hermioneconfjs)
- [sets](#sets)
- [browsers](#browsers)
- [gridUrl](#gridurl)
- [baseUrl](#baseurl)
- [httpTimeout](#httptimeout)
- [sessionRequestTimeout](#sessionrequesttimeout)
- [sessionQuitTimeout](#sessionquittimeout)
- [waitTimeout](#waittimeout)
- [sessionsPerBrowser](#sessionsperbrowser)
- [screenshotOnReject](#screenshotonreject)
- [screenshotOnRejectTimeout](#screenshotonrejecttimeout)
- [testsPerSession](#testspersession)
- [retry](#retry)
- [shouldRetry](#shouldretry)
- [calibrate](#calibrate)
- [meta](#meta)
- [windowSize](#windowsize)
- [system](#system)
- [debug](#debug)
- [mochaOpts](#mochaopts)
- [ctx](#ctx)
- [patternsOnReject](#patternsonreject)
- [workers](#workers)
- [testsPerWorker](#testsperworker)
- [plugins](#plugins)
- [prepareBrowser](#preparebrowser)
- [prepareEnvironment](#prepareenvironment)
- [CLI](#cli)
- [Reporters](#reporters)
- [Overriding settings](#overriding-settings)
- [Tests API](#tests-api)
- [AssertView](#assertview)
- [Programmatic API](#programmatic-api)
- [init](#init)
- [run](#run)
- [readTests](#readtests)
- [isFailed](#isfailed)
- [isWorker](#isworker)
- [halt](#halt)
- [Environment variables](#environment-variables)
- [HERMIONE_SKIP_BROWSERS](#hermione_skip_browsers)
- [Test Collection](#test-collection)
- [Hermione](#hermione)
- [Why you should choose hermione](#why-you-should-choose-hermione)
- [Easy to use](#easy-to-use)
- [Runs tests in parallel](#runs-tests-in-parallel)
- [Runs tests in subprocesses](#runs-tests-in-subprocesses)
- [Extensible](#extensible)
- [Retries failed tests](#retries-failed-tests)
- [Executes separate tests](#executes-separate-tests)
- [Skips tests in specific browsers](#skips-tests-in-specific-browsers)
- [Offers flexible test configuration](#offers-flexible-test-configuration)
- [Automatically initializes and closes grid sessions](#automatically-initializes-and-closes-grid-sessions)
- [Prerequisites](#prerequisites)
- [Hooks](#hooks)
- [Skip](#skip)
- [Only](#only)
- [WebdriverIO extensions](#webdriverio-extensions)
- [Sharable meta info](#sharable-meta-info)
- [Execution context](#execution-context)
- [Quick start](#quick-start)
- [.hermione.conf.js](#hermioneconfjs)
- [sets](#sets)
- [browsers](#browsers)
- [gridUrl](#gridurl)
- [baseUrl](#baseurl)
- [httpTimeout](#httptimeout)
- [sessionRequestTimeout](#sessionrequesttimeout)
- [sessionQuitTimeout](#sessionquittimeout)
- [waitTimeout](#waittimeout)
- [sessionsPerBrowser](#sessionsperbrowser)
- [screenshotOnReject](#screenshotonreject)
- [screenshotOnRejectTimeout](#screenshotonrejecttimeout)
- [testsPerSession](#testspersession)
- [retry](#retry)
- [shouldRetry](#shouldretry)
- [calibrate](#calibrate)
- [meta](#meta)
- [windowSize](#windowsize)
- [screenshotDelay](#screenshotdelay)
- [system](#system)
- [debug](#debug)
- [mochaOpts](#mochaopts)
- [ctx](#ctx)
- [patternsOnReject](#patternsonreject)
- [workers](#workers)
- [testsPerWorker](#testsperworker)
- [plugins](#plugins)
- [prepareBrowser](#preparebrowser)
- [prepareEnvironment](#prepareenvironment)
- [CLI](#cli)
- [Reporters](#reporters)
- [Overriding settings](#overriding-settings)
- [Tests API](#tests-api)
- [AssertView](#assertview)
- [Programmatic API](#programmatic-api)
- [init](#init)
- [run](#run)
- [readTests](#readtests)
- [isFailed](#isfailed)
- [isWorker](#isworker)
- [halt](#halt)
- [Environment variables](#environment-variables)
- [HERMIONE_SKIP_BROWSERS](#hermione-skip-browsers)
- [Test Collection](#test-collection)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -477,6 +479,7 @@ Option name | Description
`screenshotPath` | Directory to save screenshots by Webdriverio. Default value is `null`.
`meta` | Additional data that can be obtained via .getMeta() method
`windowSize` | Browser window dimensions. Default value is `null`.
`screenshotDelay` | Allows to specify a delay (in milliseconds) before making any screenshot.

### gridUrl
Selenium grid URL. Default value is `http://localhost:4444/wd/hub`.
Expand Down Expand Up @@ -543,6 +546,9 @@ are the same.

:warning: You can't set specific resolutions for browser Opera or mobile platforms. They use only full-screen resolution.

### screenshotDelay
Allows to specify a delay (in milliseconds) before making any screenshot. This is useful when the page has elements which are animated or if you do not want to screen a scrollbar. Default value is `0`.

### system

#### debug
Expand Down
3 changes: 2 additions & 1 deletion lib/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ module.exports = class ExistingBrowser extends Browser {
}

captureViewportImage(page) {
return this._camera.captureViewportImage(page);
return Promise.delay(this.config.screenshotDelay)
.then(() => this._camera.captureViewportImage(page));
}

scrollBy(x, y) {
Expand Down
2 changes: 2 additions & 0 deletions lib/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ function buildBrowserOptions(defaultFactory, extra) {
}
}),

screenshotDelay: options.nonNegativeInteger('screenshotDelay'),

tolerance: option({
defaultValue: defaultFactory('tolerance'),
parseEnv: Number,
Expand Down
1 change: 1 addition & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
tolerance: 2.3,
calibrate: false,
screenshotMode: 'auto',
screenshotDelay: 0,
compositeImage: false,
prepareBrowser: null,
prepareEnvironment: null,
Expand Down
12 changes: 12 additions & 0 deletions test/lib/browser/existing-browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const Promise = require('bluebird');
const {Calibrator, clientBridge, browser: {Camera}} = require('gemini-core');
const webdriverio = require('webdriverio');
const Browser = require('lib/browser/existing-browser');
Expand Down Expand Up @@ -327,6 +328,17 @@ describe('NewBrowser', () => {
describe('captureViewportImage', () => {
beforeEach(() => {
sandbox.stub(Camera.prototype, 'captureViewportImage');
sandbox.stub(Promise, 'delay').returns(Promise.resolve());
});

it('should delay capturing by the configured amount of time', () => {
Camera.prototype.captureViewportImage.withArgs({foo: 'bar'}).resolves({some: 'image'});

return mkBrowser_({screenshotDelay: 100500}).captureViewportImage({foo: 'bar'})
.then(() => {
assert.calledOnceWith(Promise.delay, 100500);
assert.callOrder(Promise.delay, Camera.prototype.captureViewportImage);
});
});

it('should delegate actual capturing to camera object', () => {
Expand Down
1 change: 1 addition & 0 deletions test/lib/browser/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function createBrowserConfig_(opts = {}) {
sessionQuitTimeout: null,
screenshotOnReject: true,
screenshotOnRejectTimeout: 3000,
screenshotDelay: 0,
windowSize: null,
getScreenshotPath: () => '/some/path',
system: opts.system || {}
Expand Down
5 changes: 4 additions & 1 deletion test/lib/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,10 @@ describe('config browser-options', () => {
});
});

['retry', 'httpTimeout', 'sessionRequestTimeout', 'sessionQuitTimeout', 'screenshotOnRejectTimeout'].forEach((option) => {
[
'retry', 'httpTimeout', 'sessionRequestTimeout', 'sessionQuitTimeout',
'screenshotOnRejectTimeout', 'screenshotDelay'
].forEach((option) => {
describe(`${option}`, () => {
it(`should throw error if ${option} is not a number`, () => {
const readConfig = {
Expand Down

0 comments on commit ced8e9f

Please sign in to comment.