Skip to content

Commit

Permalink
Merge pull request #8 from NimaSoroush/fix-screenshot-default
Browse files Browse the repository at this point in the history
Adding chromy.screenshot()
  • Loading branch information
KamenB authored Jul 13, 2017
2 parents c435f1c + 68ec39c commit 7cd1e0b
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 52 deletions.
52 changes: 28 additions & 24 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
## [0.0.1] - 2017-07-02
## [0.0.10] - 2017-07-07
### Added
- Added chromy.screenshot()

## [0.0.9] - 2017-07-07
### Changed
- Initial release
- Fixed bug

## [0.0.2] - 2017-07-04
## [0.0.8] - 2017-07-07
### Changed
- Fixed screenshot capturing
- Add test functionality
- Examples added
- Fixed bug

## [0.0.3] - 2017-07-05
## [0.0.7] - 2017-07-07
### Changed
- Save differencified screenshots in case mismatch found
- Adding shrinkwrap file to project
- Add option to specify testReportPath
- Enabling option to save differencified image to disk
- Fixed bugs
- Decrease mismatchThreshold
- set default visible to false

## [0.0.4] - 2017-07-06
## [0.0.6] - 2017-07-06
### Changed
- Upgrading chromy to 0.3.2
- Removing shrinkwrap file to project
- fixed logging issue

## [0.0.5] - 2017-07-06
### Changed
Expand All @@ -26,21 +28,23 @@
- Update Readme.md
- Added a Dockerfile for local/CI usage

## [0.0.6] - 2017-07-06
## [0.0.4] - 2017-07-06
### Changed
- fixed logging issue
- Upgrading chromy to 0.3.2
- Removing shrinkwrap file to project

## [0.0.7] - 2017-07-07
## [0.0.3] - 2017-07-05
### Changed
- Enabling option to save differencified image to disk
- Fixed bugs
- Decrease mismatchThreshold
- set default visible to false
- Save differencified screenshots in case mismatch found
- Adding shrinkwrap file to project
- Add option to specify testReportPath

## [0.0.8] - 2017-07-07
## [0.0.2] - 2017-07-04
### Changed
- Fixed bug
- Fixed screenshot capturing
- Add test functionality
- Examples added

## [0.0.9] - 2017-07-07
## [0.0.1] - 2017-07-02
### Changed
- Fixed bug
- Initial release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async () => {
|name|type|value|
|----|----|-----|
|`goto`|`string`|Url|
|`capture`|`string`|`document` or selector name|
|`capture`|`string`|`undefiend`, `document` or selector name|

##### Coming steps
- wait
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "differencify",
"version": "0.0.9",
"version": "0.0.10",
"description": "Perceptual diffing tool",
"main": "dist/index.js",
"scripts": {
Expand Down
51 changes: 33 additions & 18 deletions src/chromyRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,45 @@ class ChromyRunner {
}
break;
case actions.capture:
if (action.value === 'document') {
try {
const png = await chromy.screenshotDocument();
await saveImage(test.name, png, test.type, this.options.screenshots, this.options.testReportPath);
} catch (error) {
logger.error(error);
return false;
}
} else {
try {
const png = await chromy.screenshotSelector(action.value);
await saveImage(test.name, png, test.type, this.options.screenshots, this.options.testReportPath);
} catch (error) {
logger.error(error);
return false;
}
switch (action.value) {
case 'document':
try {
logger.log('Capturing screenshot of whole DOM');
const png = await chromy.screenshotDocument();
await saveImage(test.name, png, test.type, this.options.screenshots, this.options.testReportPath);
} catch (error) {
logger.error(error);
return false;
}
break;
case undefined:
try {
logger.log('Capturing screenshot of chrome window');
const png = await chromy.screenshot();
await saveImage(test.name, png, test.type, this.options.screenshots, this.options.testReportPath);
} catch (error) {
logger.error(error);
return false;
}
break;
default:
try {
logger.log(`Capturing screenshot of ${action.value} selector`);
const png = await chromy.screenshotSelector(action.value);
await saveImage(test.name, png, test.type, this.options.screenshots, this.options.testReportPath);
} catch (error) {
logger.error(error);
return false;
}
break;
}
break;
case actions.test:
try {
logger.log(`comparing -> ${this.options.testReportPath}/${test.name}.png
and ${this.options.screenshots}/${test.name}.png`);
const result = await compareImage(this.options, test.name);
logger.log(result);
logger.log(`campare -> ${this.options.testReportPath}/${test.name}.png
and ${this.options.screenshots}/${test.name}.png`);
} catch (error) {
logger.error(error);
return false;
Expand Down
80 changes: 75 additions & 5 deletions src/chromyRunner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jest.mock('chromy', () => jest.fn().mockImplementation(() =>
close: jest.fn(),
screenshotDocument: jest.fn(() => 'png file'),
screenshotSelector: jest.fn(() => 'png file'),
screenshot: jest.fn(() => 'png file'),
}),
));

Expand Down Expand Up @@ -46,7 +47,8 @@ describe('ChromyRunner', () => {
expect(result).toEqual(true);
expect(chromyRunner.currentTestId).toEqual(1);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('screenshot saved in -> ./screenshots/default.png');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./screenshots/default.png');
expect(chromyRunner.options)
.toEqual({
screenshots: './screenshots',
Expand All @@ -65,7 +67,8 @@ describe('ChromyRunner', () => {
expect(result).toEqual(true);
expect(chromyRunner.currentTestId).toEqual(2);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(chromyRunner.options)
.toEqual({
screenshots: './screenshots',
Expand All @@ -87,8 +90,9 @@ describe('ChromyRunner', () => {
testConfig.steps.pop({ name: actions.test, value: globalConfig.testReportPath });
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(loggerCalls[2]).toEqual('Writting the diff image to disk');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(loggerCalls[4]).toEqual('Writting the diff image to disk');
expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']);
});
it('Step runner: update action', async () => {
Expand All @@ -97,8 +101,74 @@ describe('ChromyRunner', () => {
const result = await chromyRunner._stepRunner(chromy, testConfig);
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('screenshot saved in -> ./screenshots/default.png');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./screenshots/default.png');
expect(writeFileSyncCalls).toEqual(['./screenshots/default.png', 'png file']);
});
});
describe('Chromy runner', () => {
it('Capture: screenshot', async () => {
const chromy = new Chromy();
const newConfig = {
name: 'default',
resolution: {
width: 800,
height: 600,
},
steps: [
{ name: 'goto', value: 'www.example.com' },
{ name: 'capture' },
],
};
newConfig.type = configTypes.test;
const result = await chromyRunner._stepRunner(chromy, newConfig);
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('Capturing screenshot of chrome window');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']);
});
it('Capture: screenshotDocument', async () => {
const chromy = new Chromy();
const newConfig = {
name: 'default',
resolution: {
width: 800,
height: 600,
},
steps: [
{ name: 'goto', value: 'www.example.com' },
{ name: 'capture', value: 'document' },
],
};
newConfig.type = configTypes.test;
const result = await chromyRunner._stepRunner(chromy, newConfig);
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']);
});
it('Capture: screenshotDocument', async () => {
const chromy = new Chromy();
const newConfig = {
name: 'default',
resolution: {
width: 800,
height: 600,
},
steps: [
{ name: 'goto', value: 'www.example.com' },
{ name: 'capture', value: '#form' },
],
};
newConfig.type = configTypes.test;
const result = await chromyRunner._stepRunner(chromy, newConfig);
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('Capturing screenshot of #form selector');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']);
});
});
});
8 changes: 5 additions & 3 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ describe('Differencify', () => {
const result = await differencify.update(testConfig);
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('screenshot saved in -> screenshots/default.png');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> screenshots/default.png');
expect(writeFileSyncCalls).toEqual(['screenshots', './differencify_report', 'screenshots/default.png', 'png file']);
});
it('test fn', async () => {
const result = await differencify.test(testConfig);
expect(result).toEqual(true);
expect(loggerCalls[0]).toEqual('goto -> www.example.com');
expect(loggerCalls[1]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(loggerCalls[2]).toEqual('Writting the diff image to disk');
expect(loggerCalls[1]).toEqual('Capturing screenshot of whole DOM');
expect(loggerCalls[2]).toEqual('screenshot saved in -> ./differencify_report/default.png');
expect(loggerCalls[4]).toEqual('Writting the diff image to disk');
expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']);
});
});

0 comments on commit 7cd1e0b

Please sign in to comment.