From a020e6d55ba62d26ee26e6cfd535ae539567d77d Mon Sep 17 00:00:00 2001 From: Lukas Rejman Date: Fri, 12 Apr 2019 11:39:23 +0100 Subject: [PATCH 1/2] feat: Added custom chrome option in scenario configuration --- README.md | 12 ++++++++++++ src/configValidator.js | 7 +++++-- src/configValidator.test.js | 28 ++++++++++++++++++++++++++++ src/getScreenshots.js | 1 + src/snapshotter.js | 17 ++++++++++++++--- 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8a8618f..2aee12a 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,18 @@ Unlike the onReady and onBefore script options, onBeforeSuite script does not ha For scenarios where you need to use a mobile emulator, pass in the device name to the property `mobileDeviceName` on your config. Note that at the moment, this will only work with the chrome browser. +## Chrome Custom Options + +For scenarios where you would like to add chrome custom options for example like different user-agent etc. pass the whole json configuration to the property `chromeCustomCapabilites` on your config. Note this will only work with the chrome browser. +``` + "chromeCustomCapabilites": { + "mobileEmulation": { + "deviceMetrics": { "width": 360, "height": 1600, "pixelRatio": 3.0 }, + "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" + }, + "args": ["incognito"] + } +``` ## Running ### Supported Browsers: Firefox | Chrome diff --git a/src/configValidator.js b/src/configValidator.js index 94322ab..0d13908 100644 --- a/src/configValidator.js +++ b/src/configValidator.js @@ -43,12 +43,15 @@ function isMobileConfigValid(config) { let isMobileConfigCorrect = true; config.scenarios.forEach(scenario => { - if (config.browser !== 'chrome' && scenario.mobileDeviceName) { + if ( + config.browser !== 'chrome' && + (scenario.mobileDeviceName || scenario.chromeCustomCapabilites) + ) { logger.info( 'configValidator', `❗️ ${ config.browser - } not supported on the mobile emulator. Please change your browser to chrome.` + } not supported on the mobile emulator / custom capabilities. Please change your browser to chrome.` ); isMobileConfigCorrect = false; } diff --git a/src/configValidator.test.js b/src/configValidator.test.js index 67651c9..80d86cf 100644 --- a/src/configValidator.test.js +++ b/src/configValidator.test.js @@ -114,6 +114,20 @@ describe('The Config Validator', () => { expect(isMobileConfigValid(config)).toBe(true); }); + it('config returns true for valid chrome custom capabilities', () => { + const config = { + browser: 'chrome', + scenarios: [ + { + url: 'http:/google.com/', + label: 'homepage', + chromeCustomCapabilites: '{args:["incognito"]}}' + } + ] + }; + expect(isMobileConfigValid(config)).toBe(true); + }); + it('config returns false for invalid mobile configs', () => { const config = { browser: 'firefox', @@ -127,4 +141,18 @@ describe('The Config Validator', () => { }; expect(isMobileConfigValid(config)).toBe(false); }); + + it('config returns false for invalid custom google capabilities', () => { + const config = { + browser: 'firefox', + scenarios: [ + { + url: 'http:/google.com/', + label: 'homepage', + chromeCustomCapabilites: '{args:["incognito"]}}' + } + ] + }; + expect(isMobileConfigValid(config)).toBe(false); + }); }); diff --git a/src/getScreenshots.js b/src/getScreenshots.js index dd5f46b..04cf0c0 100644 --- a/src/getScreenshots.js +++ b/src/getScreenshots.js @@ -17,6 +17,7 @@ const generateSnapShotPromises = (SnapShotter, config) => { label: scenario.label, latest: config.latest, browser: config.browser, + chromeCustomCapabilites: scenario.chromeCustomCapabilites, mobileDeviceName: scenario.mobileDeviceName, gridUrl: config.gridUrl, height: viewport.height, diff --git a/src/snapshotter.js b/src/snapshotter.js index 72bb9b6..0f46f15 100644 --- a/src/snapshotter.js +++ b/src/snapshotter.js @@ -14,6 +14,7 @@ export default class SnapShotter { width = 700, height = 1024, browser = 'chrome', + chromeCustomCapabilites, mobileDeviceName, cookies, cropToSelector, @@ -37,6 +38,7 @@ export default class SnapShotter { this._width = width; this._height = height; this._browser = browser; + this._chromeCustomCapabilites = chromeCustomCapabilites; this._mobileDeviceName = mobileDeviceName; this._cookies = cookies; this._cropToSelector = cropToSelector; @@ -59,9 +61,10 @@ export default class SnapShotter { ? this._webdriver.Capabilities.chrome : this._webdriver.Capabilities.firefox; - this._capability = mobileDeviceName - ? this.getMobileBrowserCapability() - : browserCapability(); + if (mobileDeviceName) this._capability = this.getMobileBrowserCapability(); + else if (chromeCustomCapabilites) + this._capability = this.getCustomGoogleCapability(); + else this._capability = browserCapability(); } get driver() { @@ -81,6 +84,14 @@ export default class SnapShotter { }; } + getCustomGoogleCapability() { + return { + browserName: 'chrome', + version: '*', + 'goog:chromeOptions': this._chromeCustomCapabilites + }; + } + async snooze(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } From dee24c0c468869d6b4ddff7cb0765e7e1b0d24b4 Mon Sep 17 00:00:00 2001 From: Lukas Rejman Date: Fri, 12 Apr 2019 16:27:29 +0100 Subject: [PATCH 2/2] feat: Testing E2E scenarios debug added --- e2eTests/docker-compose.yml | 2 ++ .../firefox/hideElements/hideElements.test.js | 19 ------------------- .../removeElements/removeElements.test.js | 19 ------------------- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/e2eTests/docker-compose.yml b/e2eTests/docker-compose.yml index a26ae36..ea238f0 100644 --- a/e2eTests/docker-compose.yml +++ b/e2eTests/docker-compose.yml @@ -48,6 +48,8 @@ services: - chrome networks: - selenium-grid + volumes: + - ./:/home/node/app/e2eTests/ ayespy_report: image: nginx diff --git a/e2eTests/firefox/hideElements/hideElements.test.js b/e2eTests/firefox/hideElements/hideElements.test.js index 4f32829..0090692 100644 --- a/e2eTests/firefox/hideElements/hideElements.test.js +++ b/e2eTests/firefox/hideElements/hideElements.test.js @@ -1,27 +1,8 @@ /* globals expect */ import { execSync } from 'child_process'; -import path from 'path'; -import fs from 'fs'; -import config from './hideElementsConfig'; - -function cleanState(dir) { - if (fs.existsSync(dir)) { - const files = fs.readdirSync(dir); - files.forEach(file => fs.unlinkSync(`${dir}/${file}`)); - fs.rmdirSync(dir); - } -} describe('e2e Tests hide elements', () => { - let latestMockImagesPath; - - beforeEach(() => { - latestMockImagesPath = path.resolve(config.latest); - - cleanState(latestMockImagesPath); - }); - it('hides elements using zero opacity', () => { let exitCode = 0; diff --git a/e2eTests/firefox/removeElements/removeElements.test.js b/e2eTests/firefox/removeElements/removeElements.test.js index d1b5e13..09e22c5 100644 --- a/e2eTests/firefox/removeElements/removeElements.test.js +++ b/e2eTests/firefox/removeElements/removeElements.test.js @@ -1,27 +1,8 @@ /* globals expect */ import { execSync } from 'child_process'; -import path from 'path'; -import fs from 'fs'; -import config from './removeElementsConfig'; - -function cleanState(dir) { - if (fs.existsSync(dir)) { - const files = fs.readdirSync(dir); - files.forEach(file => fs.unlinkSync(`${dir}/${file}`)); - fs.rmdirSync(dir); - } -} describe('e2e Tests remove elements', () => { - let latestMockImagesPath; - - beforeEach(() => { - latestMockImagesPath = path.resolve(config.latest); - - cleanState(latestMockImagesPath); - }); - it('remove elements from webpage and compares', () => { let exitCode = 0;