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

Commit

Permalink
Merge pull request #890 from gemini-testing/refactor/ScreenShooter
Browse files Browse the repository at this point in the history
 refactor: use 'ScreenShooter' from 'gemini-core'
  • Loading branch information
eGavr authored Mar 13, 2018
2 parents 0aded26 + 72be7db commit ee1e695
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 251 deletions.
2 changes: 1 addition & 1 deletion lib/browser/new-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ module.exports = class NewBrowser extends Browser {
}

buildScripts() {
return ClientBridge.build(this, {calibration: this._calibration, coverage: this._coverageEnabled})
return ClientBridge.build(this, {calibration: this._calibration, coverage: this._coverageEnabled, supportDeprecated: true})
.then((clientBridge) => this._clientBridge = clientBridge);
}

Expand Down
58 changes: 6 additions & 52 deletions lib/capture-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const debug = require('debug');

const ActionsBuilder = require('./tests-api/actions-builder');
const Browser = require('./browser');
const {temp, Viewport, errors: {HeightViewportError}} = require('gemini-core');
const StateError = require('./errors/state-error');
const {temp, ScreenShooter} = require('gemini-core');

module.exports = class CaptureSession {
static create(browser) {
Expand All @@ -24,6 +23,8 @@ module.exports = class CaptureSession {
this.log = debug('gemini:capture:' + this.browser.id);

this._postActions = [];

this._screenShooter = ScreenShooter.create(browser);
}

runActions(actions) {
Expand All @@ -37,13 +38,9 @@ module.exports = class CaptureSession {
}

capture(page) {
return this.browser.captureViewportImage(page)
.then((screenImage) => {
const viewport = page.viewport;
const pixelRatio = page.pixelRatio;

return this._cropImage(Viewport.create(viewport, screenImage, pixelRatio), page);
});
return this._screenShooter.capture(page)
.catch((e) => this.extendWithPageScreenshot(e).thenThrow(e))
.then((image) => ({image, canHaveCaret: page.canHaveCaret}));
}

runPostActions() {
Expand All @@ -65,47 +62,4 @@ module.exports = class CaptureSession {
browser: this.browser.serialize()
};
}

_cropImage(viewport, page) {
this.log('capture data:', page);

const captureArea = page.captureArea;

try {
viewport.validate(captureArea, this.browser);
} catch (e) {
return e instanceof HeightViewportError && this.browser.config.compositeImage
? this._extendImage(viewport, page)
: this._handleValidateImageError(e, viewport);
}

viewport.ignoreAreas(page.ignoreAreas);

return viewport.crop(captureArea)
.then((image) => ({image, canHaveCaret: page.canHaveCaret}));
}

_handleValidateImageError(e, viewport) {
const path = temp.path({suffix: '.png'});
const error = new StateError(e.message);

return viewport.save(path)
.then(() => error.imagePath = path).thenThrow(error);
}

_extendImage(viewport, page) {
const scrollHeight = Math.min(
viewport.getVerticalOverflow(page.captureArea),
page.viewport.height
);

return this.browser
.scrollBy(0, scrollHeight)
.then(() => {
page.viewport.top += scrollHeight;
return this.browser.captureViewportImage(page);
})
.then((newImage) => viewport.extendBy(scrollHeight, newImage))
.then(() => this._cropImage(viewport, page));
}
};
28 changes: 13 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"gemini-configparser": "^1.0.0",
"gemini-core": "^2.8.1",
"gemini-core": "^2.9.0",
"gemini-coverage": "^2.0.0",
"graceful-fs": "^4.1.11",
"handlebars": "^4.0.5",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/browser/new-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ describe('browser/new-browser', () => {
calibrator.calibrate.resolves({foo: 'bar'});

return browser.launch(calibrator)
.then(() => assert.calledOnceWith(ClientBridge.build, browser, {calibration: {foo: 'bar'}, coverage: true}));
.then(() => assert.calledOnceWith(ClientBridge.build, browser, {calibration: {foo: 'bar'}, coverage: true, supportDeprecated: true}));
});
});

Expand Down
Loading

0 comments on commit ee1e695

Please sign in to comment.