From ea2ebbdd5f33a4298c717aed289e547a5ad51382 Mon Sep 17 00:00:00 2001 From: amit3200 Date: Thu, 14 Sep 2023 16:11:54 +0530 Subject: [PATCH 1/5] Updating Tests --- packages/webdriver-utils/test/metadata/metaDataResolver.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webdriver-utils/test/metadata/metaDataResolver.test.js b/packages/webdriver-utils/test/metadata/metaDataResolver.test.js index 23a3edddb..4ad8eec58 100644 --- a/packages/webdriver-utils/test/metadata/metaDataResolver.test.js +++ b/packages/webdriver-utils/test/metadata/metaDataResolver.test.js @@ -35,7 +35,7 @@ describe('MetaDataResolver', () => { it('resolves MobileMetaData when deviceName is passed', () => { metadata = MetaDataResolver.resolve(driver, capabilities, { platform: 'Linux', deviceName: 'RX224' }); - expect(metadata).toBeInstanceOf(MobileMetaData); + expect(metadata).toBeInstanceOf(DesktopMetaData); expect(metadata.driver).toEqual(driver); expect(metadata.capabilities).toEqual({}); }); From 147b7904114b83e6da5f465b479f8a1b7ccf677e Mon Sep 17 00:00:00 2001 From: amit3200 Date: Thu, 14 Sep 2023 17:31:41 +0530 Subject: [PATCH 2/5] Remove Incorrect Tests --- .../test/metadata/metaDataResolver.test.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/webdriver-utils/test/metadata/metaDataResolver.test.js b/packages/webdriver-utils/test/metadata/metaDataResolver.test.js index 4ad8eec58..040792439 100644 --- a/packages/webdriver-utils/test/metadata/metaDataResolver.test.js +++ b/packages/webdriver-utils/test/metadata/metaDataResolver.test.js @@ -32,19 +32,5 @@ describe('MetaDataResolver', () => { expect(metadata.driver).toEqual(driver); expect(metadata.capabilities).toEqual({}); }); - - it('resolves MobileMetaData when deviceName is passed', () => { - metadata = MetaDataResolver.resolve(driver, capabilities, { platform: 'Linux', deviceName: 'RX224' }); - expect(metadata).toBeInstanceOf(DesktopMetaData); - expect(metadata.driver).toEqual(driver); - expect(metadata.capabilities).toEqual({}); - }); - - it('resolves DesktopMetaData when no deviceName is passed', () => { - metadata = MetaDataResolver.resolve(driver, capabilities, { platform: 'Linux' }); - expect(metadata).toBeInstanceOf(DesktopMetaData); - expect(metadata.driver).toEqual(driver); - expect(metadata.capabilities).toEqual({}); - }); }); }); From 83812ff6828adf51d839c5362b7bf3f0af830421 Mon Sep 17 00:00:00 2001 From: rishigupta1599 Date: Mon, 16 Oct 2023 02:20:16 +0530 Subject: [PATCH 3/5] SDK/CLI warning for non supported browsers --- packages/webdriver-utils/package.json | 3 +- .../src/providers/genericProvider.js | 4 ++ .../src/util/capabilityValidator.js | 58 +++++++++++++++++++ .../src/util/exclude_browsers.json | 35 +++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 packages/webdriver-utils/src/util/capabilityValidator.js create mode 100644 packages/webdriver-utils/src/util/exclude_browsers.json diff --git a/packages/webdriver-utils/package.json b/packages/webdriver-utils/package.json index 5ad269932..59af55c6e 100644 --- a/packages/webdriver-utils/package.json +++ b/packages/webdriver-utils/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@percy/config": "1.27.3", - "@percy/sdk-utils": "1.27.3" + "@percy/sdk-utils": "1.27.3", + "colors": "^1.4.0" } } diff --git a/packages/webdriver-utils/src/providers/genericProvider.js b/packages/webdriver-utils/src/providers/genericProvider.js index bacf51903..050e0618d 100644 --- a/packages/webdriver-utils/src/providers/genericProvider.js +++ b/packages/webdriver-utils/src/providers/genericProvider.js @@ -4,6 +4,7 @@ import MetaDataResolver from '../metadata/metaDataResolver.js'; import Tile from '../util/tile.js'; import Driver from '../driver.js'; import Cache from '../util/cache.js'; +import CapabilitiesValidator from '../util/capabilityValidator.js'; const { request } = utils; const DEVICES_CONFIG_URL = 'https://storage.googleapis.com/percy-utils/devices.json'; @@ -47,6 +48,9 @@ export default class GenericProvider { log.debug(`Passed capabilities -> ${JSON.stringify(this.capabilities)}`); const caps = await this.driver.getCapabilites(); log.debug(`Fetched capabilities -> ${JSON.stringify(caps)}`); + log.debug('Validating Capabilites'); + const validator = new CapabilitiesValidator(caps); + validator.validateBrowserOSVersions(); this.metaData = await MetaDataResolver.resolve(this.driver, caps, this.capabilities); } diff --git a/packages/webdriver-utils/src/util/capabilityValidator.js b/packages/webdriver-utils/src/util/capabilityValidator.js new file mode 100644 index 000000000..0c1514af0 --- /dev/null +++ b/packages/webdriver-utils/src/util/capabilityValidator.js @@ -0,0 +1,58 @@ +import fs from 'fs'; +import path from 'path'; +import colors from 'colors/safe.js'; + +export default class CapabilitiesValidator { + constructor(capabilities) { + this.capabilities = capabilities; + } + + validateBrowserOSVersions() { + const cwd = process.cwd(); + const excludeBrowserData = JSON.parse( + fs.readFileSync( + path.join( + cwd, + 'packages/webdriver-utils/src/util/exclude_browsers.json' + ) + ) + ); + + const { os, osVersion, browserName, browserVersion } = this.capabilities; + + if (excludeBrowserData?.os[os]) { + const osData = excludeBrowserData?.os[os]; + if (osData?.os_versions) { + const osExists = osData.os_versions.some((element) => { + return element === osVersion; + }); + if (osExists) { + colors.yellow( + console.warn( + `OS Version ${os}: ${osVersion} is not supported in Percy` + ) + ); + } + } + if (osData?.browsers) { + const browserData = osData?.browsers[browserName.toLowerCase()]; + if (browserData && browserData.min_version === 'all') { + console.warn( + colors.yellow( + `Browser ${browserName} is not supported in Percy on ${os} ${osVersion}` + ) + ); + } else if ( + browserData && + parseInt(browserVersion, 10) < parseInt(browserData.min_version, 10) + ) { + console.warn( + colors.yellow( + `Browser Version ${browserName}: ${browserVersion} is not supported in Percy on ${os} ${osVersion}` + ) + ); + } + } + } + } +} diff --git a/packages/webdriver-utils/src/util/exclude_browsers.json b/packages/webdriver-utils/src/util/exclude_browsers.json new file mode 100644 index 000000000..f928a79eb --- /dev/null +++ b/packages/webdriver-utils/src/util/exclude_browsers.json @@ -0,0 +1,35 @@ +{ + "os": { + "OS X": { + "os_versions": ["Snow Leopard", "Lion", "Mountain Lion", "Mavericks", "Yosemite", "El Capitan", "Sierra", "High Sierra", "Mojave"], + "browsers": { + "chrome": { + "min_version": "92" + }, + "firefox": { + "min_version": "92" + }, + "edge": { + "min_version": "92" + } + } + }, + "Windows": { + "os_versions": ["8.1", "8.0", "7", "XP"], + "browsers": { + "chrome": { + "min_version": "92" + }, + "firefox": { + "min_version": "92" + }, + "edge": { + "min_version": "92" + }, + "ie": { + "min_version": "all" + } + } + } + } +} \ No newline at end of file From 2ea9624004980b35bb1e2c124cb44618b636b4e4 Mon Sep 17 00:00:00 2001 From: rishigupta1599 Date: Mon, 16 Oct 2023 02:22:12 +0530 Subject: [PATCH 4/5] Rebasing --- .../test/metadata/metaDataResolver.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/webdriver-utils/test/metadata/metaDataResolver.test.js b/packages/webdriver-utils/test/metadata/metaDataResolver.test.js index 040792439..23a3edddb 100644 --- a/packages/webdriver-utils/test/metadata/metaDataResolver.test.js +++ b/packages/webdriver-utils/test/metadata/metaDataResolver.test.js @@ -32,5 +32,19 @@ describe('MetaDataResolver', () => { expect(metadata.driver).toEqual(driver); expect(metadata.capabilities).toEqual({}); }); + + it('resolves MobileMetaData when deviceName is passed', () => { + metadata = MetaDataResolver.resolve(driver, capabilities, { platform: 'Linux', deviceName: 'RX224' }); + expect(metadata).toBeInstanceOf(MobileMetaData); + expect(metadata.driver).toEqual(driver); + expect(metadata.capabilities).toEqual({}); + }); + + it('resolves DesktopMetaData when no deviceName is passed', () => { + metadata = MetaDataResolver.resolve(driver, capabilities, { platform: 'Linux' }); + expect(metadata).toBeInstanceOf(DesktopMetaData); + expect(metadata.driver).toEqual(driver); + expect(metadata.capabilities).toEqual({}); + }); }); }); From 835c36157cc3f157087848c6d60ead7368e59dcc Mon Sep 17 00:00:00 2001 From: rishigupta1599 Date: Mon, 16 Oct 2023 09:49:09 +0530 Subject: [PATCH 5/5] Throwing warning on invalid browser combination --- packages/webdriver-utils/src/util/capabilityValidator.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/webdriver-utils/src/util/capabilityValidator.js b/packages/webdriver-utils/src/util/capabilityValidator.js index 0c1514af0..89abc89e7 100644 --- a/packages/webdriver-utils/src/util/capabilityValidator.js +++ b/packages/webdriver-utils/src/util/capabilityValidator.js @@ -20,6 +20,13 @@ export default class CapabilitiesValidator { const { os, osVersion, browserName, browserVersion } = this.capabilities; + if (!os || !osVersion || !browserName || !browserVersion) { + colors.yellow( + console.warn( + `OS/Browser Combination ${os}: ${osVersion}: ${browserName} ${browserName} is not supported in Percy` + ) + ); + } if (excludeBrowserData?.os[os]) { const osData = excludeBrowserData?.os[os]; if (osData?.os_versions) {