From fa4629d6fc4a65ecb83fb126fdcbca2cd139047d Mon Sep 17 00:00:00 2001 From: Nima Soroush Haddadi Date: Wed, 12 Jul 2017 17:24:16 +0100 Subject: [PATCH 1/3] Adding chromy.screenshot() --- CHANGELOG.md | 52 ++++++++++++++------------ README.md | 2 +- package.json | 2 +- src/chromyRunner.js | 47 +++++++++++++++-------- src/chromyRunner.test.js | 80 +++++++++++++++++++++++++++++++++++++--- src/index.test.js | 8 ++-- 6 files changed, 141 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bf9ff3..97f8384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index dacb8da..133bf63 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index b45e6d5..26905c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "differencify", - "version": "0.0.9", + "version": "0.0.10", "description": "Perceptual diffing tool", "main": "dist/index.js", "scripts": { diff --git a/src/chromyRunner.js b/src/chromyRunner.js index 421c221..0b26bbb 100644 --- a/src/chromyRunner.js +++ b/src/chromyRunner.js @@ -39,22 +39,37 @@ 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: diff --git a/src/chromyRunner.test.js b/src/chromyRunner.test.js index 073c19e..65385c0 100644 --- a/src/chromyRunner.test.js +++ b/src/chromyRunner.test.js @@ -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'), }), )); @@ -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', @@ -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', @@ -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[3]).toEqual('Writting the diff image to disk'); expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']); }); it('Step runner: update action', async () => { @@ -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']); + }); + }); }); diff --git a/src/index.test.js b/src/index.test.js index 85378ae..64b1ca8 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -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[3]).toEqual('Writting the diff image to disk'); expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']); }); }); From 51d115c2d4cbaed42ae080078697b8a329a893bb Mon Sep 17 00:00:00 2001 From: Nima Soroush Haddadi Date: Wed, 12 Jul 2017 17:30:47 +0100 Subject: [PATCH 2/3] Updating logging message --- src/chromyRunner.js | 4 ++-- src/chromyRunner.test.js | 2 +- src/index.test.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chromyRunner.js b/src/chromyRunner.js index 0b26bbb..36c0bce 100644 --- a/src/chromyRunner.js +++ b/src/chromyRunner.js @@ -74,10 +74,10 @@ class ChromyRunner { break; case actions.test: try { + logger.log(`camparing -> ${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; diff --git a/src/chromyRunner.test.js b/src/chromyRunner.test.js index 65385c0..d7db9a5 100644 --- a/src/chromyRunner.test.js +++ b/src/chromyRunner.test.js @@ -92,7 +92,7 @@ describe('ChromyRunner', () => { 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(loggerCalls[3]).toEqual('Writting the diff image to disk'); + 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 () => { diff --git a/src/index.test.js b/src/index.test.js index 64b1ca8..10bd2ae 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -73,7 +73,7 @@ describe('Differencify', () => { 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(loggerCalls[3]).toEqual('Writting the diff image to disk'); + expect(loggerCalls[4]).toEqual('Writting the diff image to disk'); expect(writeFileSyncCalls).toEqual(['./differencify_report/default.png', 'png file']); }); }); From 68ec39c40ef3196acbc248dab6caf94102f66174 Mon Sep 17 00:00:00 2001 From: Nima Date: Wed, 12 Jul 2017 20:45:48 +0100 Subject: [PATCH 3/3] Fixing typo --- src/chromyRunner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chromyRunner.js b/src/chromyRunner.js index 36c0bce..b879941 100644 --- a/src/chromyRunner.js +++ b/src/chromyRunner.js @@ -74,7 +74,7 @@ class ChromyRunner { break; case actions.test: try { - logger.log(`camparing -> ${this.options.testReportPath}/${test.name}.png + 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);