From a0beebc17629f1ba6cceaed08a0245ff26e6b609 Mon Sep 17 00:00:00 2001 From: prklm10 Date: Wed, 5 Apr 2023 13:44:19 +0530 Subject: [PATCH] ignored element support implementation --- packages/client/src/client.js | 5 ++-- packages/client/test/client.test.js | 34 +++++++++++++++++++++--- packages/core/src/config.js | 40 +++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/packages/client/src/client.js b/packages/client/src/client.js index f1b58df20..4b7343c62 100644 --- a/packages/client/src/client.js +++ b/packages/client/src/client.js @@ -360,7 +360,7 @@ export class PercyClient { return snapshot; } - async createComparison(snapshotId, { tag, tiles = [], externalDebugUrl } = {}) { + async createComparison(snapshotId, { tag, tiles = [], externalDebugUrl, ignoredElementsData } = {}) { validateId('snapshot', snapshotId); this.log.debug(`Creating comparision: ${tag.name}...`); @@ -379,7 +379,8 @@ export class PercyClient { data: { type: 'comparisons', attributes: { - 'external-debug-url': externalDebugUrl || null + 'external-debug-url': externalDebugUrl || null, + 'ignore-elements-data': ignoredElementsData || null }, relationships: { tag: { diff --git a/packages/client/test/client.test.js b/packages/client/test/client.test.js index 3649e5e73..db8d464c2 100644 --- a/packages/client/test/client.test.js +++ b/packages/client/test/client.test.js @@ -770,6 +770,28 @@ describe('PercyClient', () => { .withArgs('foo/bar').and.resolveTo('bar'); let tile1Content = 'screenshot'; + let ignoredElementsData = { + ignoreElementsData: [ + { + selector: 'xpaths', + 'co-ordinates': { + top: 1042, + bottom: 1147, + left: 108, + right: 972 + } + }, + { + selector: 'appiumWebElement', + 'co-ordinates': { + top: 1199, + bottom: 1304, + left: 108, + right: 972 + } + } + ] + }; await expectAsync(client.createComparison(4567, { tag: { @@ -802,14 +824,16 @@ describe('PercyClient', () => { fullscreen: true, sha: sha256hash('somesha') }], - externalDebugUrl: 'http://debug.localhost' + externalDebugUrl: 'http://debug.localhost', + ignoredElementsData: ignoredElementsData })).toBeResolved(); expect(api.requests['/snapshots/4567/comparisons'][0].body).toEqual({ data: { type: 'comparisons', attributes: { - 'external-debug-url': 'http://debug.localhost' + 'external-debug-url': 'http://debug.localhost', + 'ignore-elements-data': ignoredElementsData }, relationships: { tag: { @@ -872,7 +896,8 @@ describe('PercyClient', () => { data: { type: 'comparisons', attributes: { - 'external-debug-url': null + 'external-debug-url': null, + 'ignore-elements-data': null }, relationships: { tag: { @@ -1120,7 +1145,8 @@ describe('PercyClient', () => { data: { type: 'comparisons', attributes: { - 'external-debug-url': null + 'external-debug-url': null, + 'ignore-elements-data': null }, relationships: { tag: { diff --git a/packages/core/src/config.js b/packages/core/src/config.js index ea6c782d3..5778ba623 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -453,6 +453,46 @@ export const comparisonSchema = { } } } + }, + ignoredElementsData: { + type: 'object', + additionalProperties: false, + required: ['ignoreElementsData'], + properties: { + ignoreElementsData: { + type: 'array', + items: { + type: 'object', + additionalProperties: false, + properties: { + selector: { + type: 'string' + }, + coOrdinates: { + type: 'object', + properties: { + top: { + type: 'integer', + minimum: 0 + }, + left: { + type: 'integer', + minimum: 0 + }, + bottom: { + type: 'integer', + minimum: 0 + }, + right: { + type: 'integer', + minimum: 0 + } + } + } + } + } + } + } } } };