Skip to content

Commit

Permalink
✨ Percy on Automate Support (#1292)
Browse files Browse the repository at this point in the history
* ✨ Integrate selenium and appium session support (#1239)

* [PPLT-2008] POC CLI

* [refactor] remove selenium-webdriver dependency in poa

* [refactor] rename driver2 -> driver

* [refactor] remove all usage of metaData

* [refactor] rename getTag1 -> getTag

* [chore] remove unused metaData resolvers

* [feat] add screenshot feature for driverWrapper

* [refactor] use await in function calls + use fs/promises

* [refactor] remove un-necessary async-await in metadata resolvers

* [wip] added genericProvider

* [feat] added support for automateprovider + debugUrl

* [chore] update packages.json

* [chore] remove snapshotName from constructor initialization

* [chore] rename endpoint driverWrapper -> automateScreenshot

* [refactor] move driverResolver/driverWrapper -> driver.js

* [refactor] use cli-poa/main.js only for import and export, use AutomateProvider in percy.js

* [chore] lint using --fix flag

* [chore] remove constructor from automateProvider as it is just initializing parent

* [test] instantiate tests

* [test] verify browserstackExecutor passed correct arguments

* [fix] await on response.json()

* [chore] add test and test:coverage scripts

* [test] update automateProvider coverage to 100%

* [test] add tests for providerResolver

* [test] add commonMetaDataResolver.test.js

* [test] added driver check for commonMetaDataResolver

* [test] added desktop and mobile metadata resolver tests

* [chore] lint using lint:fix

* [test] added genericProvider tests

* [chore] lint using lint:fix

* [refactor] move automateScreenshot to poa

* [refactor] rename cli-poa to selenium-utils

* [refactor] rename selenium-utils -> webdriver-utils

* [refactor] instantiate logging in individual files

* [chore] updated webdriver-utils package.json

* [feat] updated getTag as per BYOS contract

* [feat] update test.yml + move from main.js to index.js for tests to run smoothly

* [chore] lint using yarn lint --fix

* [chore] fix lint errors

* [feat] add support for adding individual coverage threshold levels

* [chore] rename commonMetadata to Metadata

* [fix] update content-type headers for executeScript call

* [fix] handle embedded url

* [feat] use sdk-utils/requests instead of node-fetch

* [feat] call percy.upload(...) directly which skips latency due to serialise and deserialise

* [refactor] pass base64 data directly instead of writing to temp files

* [chore] yarn lint fix

* [refactor] use ternary opeartor instead of if-else

* [fix] refactor conditional imports

* [refactor] switch to importing default and extract props from it

* [test] added tests for webdriver-utils/driver

* [test] added genericProvider tests

* [chore] removed fallback parameters as we always pass some capabilities

* [refactor] remove customized threshold support for nyc

* [chore] lint using fix

* [feat] added cache support

* [test] add cache, genericProvider tests for webdriver-utils

* [refactor] webdriverutils to class based structure for better testability

* [test] added api.test.js

* [test] setup https server + tests for requests

* [chore] lint using lint --fix

---------

Co-authored-by: amit3200 <[email protected]>

* POA Ignore Region changes (#1250)

* [PPLT-2008] POC CLI

* [refactor] remove selenium-webdriver dependency in poa

* [refactor] rename driver2 -> driver

* [refactor] remove all usage of metaData

* [refactor] rename getTag1 -> getTag

* [chore] remove unused metaData resolvers

* [feat] add screenshot feature for driverWrapper

* [refactor] use await in function calls + use fs/promises

* [refactor] remove un-necessary async-await in metadata resolvers

* [wip] added genericProvider

* [feat] added support for automateprovider + debugUrl

* [chore] update packages.json

* [chore] remove snapshotName from constructor initialization

* [chore] rename endpoint driverWrapper -> automateScreenshot

* [refactor] move driverResolver/driverWrapper -> driver.js

* [refactor] use cli-poa/main.js only for import and export, use AutomateProvider in percy.js

* [chore] lint using --fix flag

* [chore] remove constructor from automateProvider as it is just initializing parent

* [test] instantiate tests

* [test] verify browserstackExecutor passed correct arguments

* [fix] await on response.json()

* [chore] add test and test:coverage scripts

* [test] update automateProvider coverage to 100%

* [test] add tests for providerResolver

* [test] add commonMetaDataResolver.test.js

* [test] added driver check for commonMetaDataResolver

* [test] added desktop and mobile metadata resolver tests

* [chore] lint using lint:fix

* [test] added genericProvider tests

* [chore] lint using lint:fix

* [refactor] move automateScreenshot to poa

* [refactor] rename cli-poa to selenium-utils

* [refactor] rename selenium-utils -> webdriver-utils

* [refactor] instantiate logging in individual files

* [chore] updated webdriver-utils package.json

* [feat] updated getTag as per BYOS contract

* [feat] update test.yml + move from main.js to index.js for tests to run smoothly

* [chore] lint using yarn lint --fix

* [chore] fix lint errors

* [feat] add support for adding individual coverage threshold levels

* [chore] rename commonMetadata to Metadata

* [fix] update content-type headers for executeScript call

* [fix] handle embedded url

* [feat] use sdk-utils/requests instead of node-fetch

* [feat] call percy.upload(...) directly which skips latency due to serialise and deserialise

* [refactor] pass base64 data directly instead of writing to temp files

* [chore] yarn lint fix

* [refactor] use ternary opeartor instead of if-else

* [fix] refactor conditional imports

* [refactor] switch to importing default and extract props from it

* [test] added tests for webdriver-utils/driver

* [test] added genericProvider tests

* [chore] removed fallback parameters as we always pass some capabilities

* [refactor] remove customized threshold support for nyc

* [chore] lint using fix

* [feat] added cache support

* Changes for js sdk POA

* [test] add cache, genericProvider tests for webdriver-utils

* Changes for ignoreRegion

* Fix testcase and edge case

* Fix test case

* Added test for ignore region

* Test case for driver

* Add testcase for postScreenshot

* Fixed tests and addressed comments

* Updated name as per suggestion

* Fix test case

* Changes according to comments

* Changes acc to comment

* rename ignore region selenium element to generic name

---------

Co-authored-by: amit3200 <[email protected]>
Co-authored-by: nilshah98 <[email protected]>

* Feat: Send domInfoSha & PoA optimizations (#1270)

* Adding Optimizations for Screenshot and all

* Adding major poa v2 changes

* Updating tests for cli v2

* [lint fix] Updating lint

* [add tests, few feats] + tokentype, + misc

* Addressing few changes

* Adding percyCSS options for PoA [Snapshot level] (#1281)

* Adding percyCSS options for PoA

* [addressing comments]

* Addressing comments on test

* fixing tests

* [Refactor], Resolving comments

* Increase Statement Coverage

* fixing tests and small comments

* fixing core tests

* Making backward compatability

* make sdk-utils like before

* making timin.test.js less strict

* making import changes as per comment

* adding changes as per suggestion

* increase coverage for client

* adding param to getToken

* adding tests for getToken

---------

Co-authored-by: amit3200 <[email protected]>

* Appium JS SDK related cli changes (#1282)

* Adding Optimizations for Screenshot and all

* Adding major poa v2 changes

* Updating tests for cli v2

* [lint fix] Updating lint

* [add tests, few feats] + tokentype, + misc

* Addressing few changes

* Adding percyCSS options for PoA [Snapshot level] (#1281)

* Adding percyCSS options for PoA

* [addressing comments]

* Addressing comments on test

* fixing tests

* Added logic for session type for js sdk

* [Refactor], Resolving comments

* Increase Statement Coverage

* fixing tests and small comments

* fixing core tests

* Fix type logic for js sdk

* Added test

* Fix test case

* Ignore region fix

* Feat: Send domInfoSha & PoA optimizations (#1270)

* Adding Optimizations for Screenshot and all

* Adding major poa v2 changes

* Updating tests for cli v2

* [lint fix] Updating lint

* [add tests, few feats] + tokentype, + misc

* Addressing few changes

* Adding percyCSS options for PoA [Snapshot level] (#1281)

* Adding percyCSS options for PoA

* [addressing comments]

* Addressing comments on test

* fixing tests

* [Refactor], Resolving comments

* Increase Statement Coverage

* fixing tests and small comments

* fixing core tests

* Making backward compatability

* make sdk-utils like before

* making timin.test.js less strict

* making import changes as per comment

* adding changes as per suggestion

* increase coverage for client

* adding param to getToken

* adding tests for getToken

---------

Co-authored-by: amit3200 <[email protected]>

* undo changes

* Pplt 2118 resolution and desktop tweaks (#1291)

* Making backward compatability

* make sdk-utils like before

* making timin.test.js less strict

* making import changes as per comment

* adding changes as per suggestion

* increase coverage for client

* adding param to getToken

* adding tests for getToken

* Adding resolution details

* Adding default resolutions and making timings

* Adding Tests

---------

Co-authored-by: amit3200 <[email protected]>
Co-authored-by: Neel Shah <[email protected]>

* [PER-2063] Percy upload for BYOS (#1288)

* PER-2063 percy-upload-logic-change

* PR comments resolve

* added stripExtension test

* fix tests

* fix test

* error message fix

* update error message

* update name

---------

Co-authored-by: “Shahid <“[email protected]”>
Co-authored-by: Samarjeet <[email protected]>

* making webutils package access public

* 🔖 v1.27.0-alpha.0

* Mark tag as alpha on sub-packages

* Poa/start support (#1302)

* Adding Start Stop Support for PoA

* Adding tests to improve coverage

* Make Freeze Animation false by default (#1309)

* Make Freeze Animation false by default

* Updating Unit Test + More Check

* Adding Dpr fixes (#1303)

* feat: added support for extracting and passing header and footer heights (#1305)

* feat: added support for extracting and passing header and footer heights

* test: getHeaderFooter

* chore: lint using fix

* fix: use header and footer height for calculating tag

* test: updated percy-cli tests

* test: update expectations for header and footer heights for getTiles;

* feat: updated getTiles function to use header and footer params, so that it is more testable

* feat: update comparison tag logic

* test: updated getTag spec

* chore: lint using yarn

* feat: add support for header and footer extraction;

* test: update test for extracting header and footer

* chore: lint using fix

* fix: use metadata.osName to detect android

* test: update generaticProvider tests

* chore: added some logging

* fix: webdriver-utils/index logging

* chore: lint using fix

* feat: added caching support for devicesJson

* chore: lint using fix

* test: updated getHeaderFooter spec

* chore: lint fix

* feat: change desktop deviceName format

* test: increase coverage

* chore: add comments around skipping request.test from browser tests

* chore: add webdriver-utils as dependency for core package

* chore: resolve TODO comments

* chore: add percy/webdriver-utils to windows ci workflow

* :bookmark v1.27.0-beta.0 (#1313)

* :bookmark v1.27.0-beta.0

* Update publishConfig tag as well

* Support Old App Percy Tokens (#1321)

* Support Old App Percy Tokens

* Adding logs and tests for branch

* Fixing broken tests

* Increase coverage

* Increase coverage - 1

* Increase coverage - 2

* Increase coverage - 3

* [PER-2277] Add consider regions (#1318)

* Add consider regions

* consider regions client changes

* update schema

* lint fix

* Consider region schema fix (#1328)

* Consider region schema fix

* selector name fix

* [PPLT-2230] Add anchor comment to executeScript (#1334)

* feat: add anchor comment

* fix: do not add anchor_comment for browserstack_executor

* Adding support for legacy protocol (#1323)

* feat: publichConfig -> beta

---------

Co-authored-by: Neel Shah <[email protected]>
Co-authored-by: chinmay-browserstack <[email protected]>
Co-authored-by: shahidk8 <[email protected]>
Co-authored-by: “Shahid <“[email protected]”>
Co-authored-by: Samarjeet <[email protected]>
Co-authored-by: Samarjeet <[email protected]>
  • Loading branch information
7 people authored Aug 7, 2023
1 parent 24150e9 commit 413671b
Show file tree
Hide file tree
Showing 69 changed files with 3,443 additions and 127 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- '@percy/cli-build'
- '@percy/cli-config'
- '@percy/sdk-utils'
- '@percy/webdriver-utils'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
- '@percy/cli-build'
- '@percy/cli-config'
- '@percy/sdk-utils'
- '@percy/webdriver-utils'
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion karma.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ module.exports = async config => {
{ pattern: 'test/**/*.test.js', type: 'module', watched: false },
{ pattern: 'test/assets/**', watched: false, included: false }
],

// NOTE: Although sdk-utils test run in browser as well, we do not run sdk-utils/request test in browsers as we require creation of https server for this test
exclude: [
'**/test/request.test.js',
],
proxies: {
// useful when the contents of a fake asset do not matter
'/_/': 'localhost/'
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.26.3",
"version": "1.27.0-beta.0",
"packages": [
"packages/*"
],
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-app",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.26.3",
"@percy/cli-exec": "1.26.3"
"@percy/cli-command": "1.27.0-beta.0",
"@percy/cli-exec": "1.27.0-beta.0"
}
}
6 changes: 3 additions & 3 deletions packages/cli-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-build",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"engines": {
"node": ">=14"
Expand All @@ -33,6 +33,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.26.3"
"@percy/cli-command": "1.27.0-beta.0"
}
}
10 changes: 5 additions & 5 deletions packages/cli-command/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-command",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"files": [
"dist",
Expand All @@ -36,8 +36,8 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/config": "1.26.3",
"@percy/core": "1.26.3",
"@percy/logger": "1.26.3"
"@percy/config": "1.27.0-beta.0",
"@percy/core": "1.27.0-beta.0",
"@percy/logger": "1.27.0-beta.0"
}
}
6 changes: 3 additions & 3 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-config",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"engines": {
"node": ">=14"
Expand All @@ -33,6 +33,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.26.3"
"@percy/cli-command": "1.27.0-beta.0"
}
}
6 changes: 3 additions & 3 deletions packages/cli-exec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-exec",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.26.3",
"@percy/cli-command": "1.27.0-beta.0",
"cross-spawn": "^7.0.3",
"which": "^2.0.2"
}
Expand Down
8 changes: 8 additions & 0 deletions packages/cli-exec/src/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export const exec = command('exec', {
log.warn('Percy is disabled');
} else {
try {
// Skip this for app because they are triggered as app:exec
// Remove this once they move to exec command as well
if (percy.projectType !== 'app') {
percy.projectType = percy.client.tokenType();
percy.skipDiscovery = percy.shouldSkipAssetDiscovery(percy.projectType);
} else {
log.debug('Skipping percy project attribute calculation');
}
yield* percy.yield.start();
} catch (error) {
if (error.name === 'AbortError') throw error;
Expand Down
10 changes: 9 additions & 1 deletion packages/cli-exec/src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ export const start = command('start', {
server: true,
projectType: 'web'
}
}, async function*({ percy, exit }) {
}, async function*({ percy, log, exit }) {
if (!percy) exit(0, 'Percy is disabled');
let { yieldFor } = await import('@percy/cli-command/utils');
// Skip this for app because they are triggered as app:exec
// Remove this once they move to exec command as well
if (percy.projectType !== 'app') {
percy.projectType = percy.client.tokenType();
percy.skipDiscovery = percy.shouldSkipAssetDiscovery(percy.projectType);
} else {
log.debug('Skipping percy project attribute calculation');
}

// start percy
yield* percy.yield.start();
Expand Down
27 changes: 27 additions & 0 deletions packages/cli-exec/test/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ describe('percy exec', () => {
delete process.env.PERCY_PARTIAL_BUILD;
});

describe('projectType is app', () => {
const type = exec.definition.percy.projectType;
const logInfo = logger.loglevel();

beforeEach(() => {
exec.definition.percy.projectType = 'app';
logger.loglevel('debug');
process.env.PERCY_LOGLEVEL = 'debug';
});

afterEach(() => {
exec.definition.percy.projectType = type;
logger.loglevel(logInfo);
logger.reset(true);
delete process.env.PERCY_LOGLEVEL;
});

it('does not call override function', async () => {
await exec(['--', 'node', '--eval', '']);
expect(logger.stderr).toEqual(
jasmine.arrayContaining([
'[percy:cli] Skipping percy project attribute calculation'
])
);
});
});

it('logs an error when no command is provided', async () => {
await expectAsync(exec()).toBeRejected();

Expand Down
25 changes: 25 additions & 0 deletions packages/cli-exec/test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ describe('percy exec:start', () => {
await started;
});

describe('projectType is app', () => {
const type = start.definition.percy.projectType;
const logInfo = logger.loglevel();
beforeAll(() => {
start.definition.percy.projectType = 'app';
logger.loglevel('debug');
process.env.PERCY_LOGLEVEL = 'debug';
});

afterAll(() => {
start.definition.percy.projectType = type;
logger.loglevel(logInfo);
logger.reset(true);
delete process.env.PERCY_LOGLEVEL;
});

it('does not call override function', () => {
expect(logger.stderr).toEqual(
jasmine.arrayContaining([
'[percy:cli] Skipping percy project attribute calculation'
])
);
});
});

it('starts a long-running percy process', async () => {
let response = await request('http://localhost:5338/percy/healthcheck');
expect(response).toHaveProperty('success', true);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-snapshot",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.26.3",
"@percy/cli-command": "1.27.0-beta.0",
"yaml": "^2.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/cli-upload/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-upload",
"version": "1.26.3",
"version": "1.27.0-beta.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "beta"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.26.3",
"@percy/cli-command": "1.27.0-beta.0",
"fast-glob": "^3.2.11",
"image-size": "^1.0.0"
}
Expand Down
41 changes: 33 additions & 8 deletions packages/cli-upload/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import command from '@percy/cli-command';
import * as UploadConfig from './config.js';

const ALLOWED_FILE_TYPES = /\.(png|jpg|jpeg)$/i;
const ALLOWED_TOKEN_TYPES = ['web', 'generic'];

// All BYOS screenshots have a fixed comparison tag
export const BYOS_TAG = {
name: 'Uploaded Screenshot',
width: 1,
height: 1
};

export const upload = command('upload', {
description: 'Upload a directory of images to Percy',
Expand Down Expand Up @@ -71,6 +79,12 @@ export const upload = command('upload', {
exit(1, `No matching files found in '${args.dirname}'`);
}

const tokenType = percy.client.tokenType();

if (!ALLOWED_TOKEN_TYPES.includes(tokenType)) {
exit(1, 'Invalid Token Type. Only "web" and "self-managed" token types are allowed.');
}

let { default: imageSize } = await import('image-size');
let { getImageResources } = await import('./utils.js');

Expand All @@ -87,15 +101,26 @@ export const upload = command('upload', {
let { dir, name, ext } = path.parse(relativePath);
img.type = ext === '.png' ? 'png' : 'jpeg';
img.name = path.join(dir, name);
let snapshotName = config.stripExtensions ? img.name : relativePath;

percy.upload({
name: config.stripExtensions ? img.name : relativePath,
// width and height is clamped to API min and max
widths: [Math.max(10, Math.min(img.width, 2000))],
minHeight: Math.max(10, Math.min(img.height, 2000)),
// resources are read from the filesystem as needed
resources: () => getImageResources(img)
});
if (tokenType === 'generic') {
percy.upload({
name: snapshotName,
tag: BYOS_TAG,
tiles: [
{ filepath: img.absolutePath }
]
});
} else {
percy.upload({
name: snapshotName,
// width and height is clamped to API min and max
widths: [Math.max(10, Math.min(img.width, 2000))],
minHeight: Math.max(10, Math.min(img.height, 2000)),
// resources are read from the filesystem as needed
resources: () => getImageResources(img)
});
}
}
}

Expand Down
Loading

0 comments on commit 413671b

Please sign in to comment.