Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
feat: introduce option to specify delay before a screenshot is made
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Lau committed Jan 19, 2018
1 parent 084c7a0 commit ec52a5e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ Settings list:

:warning: Option does not work in Opera@12.16.

* `screenshotDelay` — allows to specify a delay (in milliseconds) before making any screenshot.
By default there is no delay.

This is useful when the page has elements which are animated.

## Sets

You can link some set of tests with certain browsers using `sets`.
Expand Down
6 changes: 4 additions & 2 deletions lib/browser/browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const _ = require('lodash');
const Promise = require('bluebird');
const wd = require('./wd-bluebird');

const Camera = require('./camera');
Expand All @@ -17,11 +18,12 @@ module.exports = class Browser {
}

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

serialize() {
const props = ['id', 'gridUrl', 'httpTimeout', 'screenshotMode', 'compositeImage'];
const props = ['id', 'gridUrl', 'httpTimeout', 'screenshotMode', 'screenshotDelay', 'compositeImage'];

return {
config: _.pick(this.config, props),
Expand Down
12 changes: 11 additions & 1 deletion lib/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const getTopLevel = () => {
windowSize: null,
retry: 0,
screenshotMode: 'auto',
compositeImage: false
compositeImage: false,
screenshotDelay: 0
};

const provideDefault = (key) => defaults[key];
Expand Down Expand Up @@ -207,6 +208,15 @@ function buildBrowserOptions(defaultFactory, extra) {
}
}),

screenshotDelay: option({
defaultValue: defaultFactory('screenshotDelay'),
parseEnv: Number,
parseCli: Number,
validate: (value) => {
assertNonNegative(value, 'screenshotDelay');
}
}),

compositeImage: booleanOption(defaultFactory('compositeImage'))
});
}
Expand Down
17 changes: 13 additions & 4 deletions test/unit/browser/new-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,25 @@ describe('browser/new-browser', () => {
});

describe('captureViewportImage', () => {
let browser;

beforeEach(() => {
sandbox.stub(Camera.prototype, 'captureViewportImage');
sandbox.stub(Promise, 'delay').returns(Promise.resolve());
});

browser = makeBrowser({browserName: 'browser', version: '1.0'}, {calibrate: true});
it('should delay capturing by the configured amount', () => {
const browser = makeBrowser({browserName: 'browser', version: '1.0'}, {calibrate: false, screenshotDelay: 42});

return browser.launch()
.then(() => browser.captureViewportImage())
.then(() => {
assert.calledOnce(Promise.delay);
assert.calledWith(Promise.delay, 42);
assert.callOrder(Promise.delay, Camera.prototype.captureViewportImage);
});
});

it('should delegate actual capturing to camera object', () => {
browser = makeBrowser({browserName: 'browser', version: '1.0'}, {calibrate: false});
const browser = makeBrowser({browserName: 'browser', version: '1.0'}, {calibrate: false});

Camera.prototype.captureViewportImage.returns(Promise.resolve({some: 'image'}));

Expand Down

0 comments on commit ec52a5e

Please sign in to comment.