Skip to content

Commit

Permalink
✨ Implement Warning + Disable Percy for unsupported combinations (#1411)
Browse files Browse the repository at this point in the history
* handled error handling cases

* handled errorif status is 200

* revert a small change

* lint fix

* added test cases

* lint fix

* add coverage

* resolved comments

* resolved comments

---------

Co-authored-by: Chinmay Maheshwari <[email protected]>
  • Loading branch information
2 people authored and rishigupta1599 committed Nov 16, 2023
1 parent 9b53f4c commit c244a33
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
15 changes: 14 additions & 1 deletion packages/webdriver-utils/src/providers/automateProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,25 @@ export default class AutomateProvider extends GenericProvider {
percyBuildUrl: this.buildInfo.url,
state: 'begin'
});
// Selenium Hub, set status error Code to 13 if an error is thrown
// Handling error with Selenium dialect is != W3C
if (result?.status === 13) throw new Error(result?.value || 'Got invalid error response');
this._markedPercy = result.success;
return result;
} catch (e) {
log.debug(`[${name}] : Could not mark Automate session as percy`);
log.error(`[${name}] : error: ${e.toString()}`);
return null;
/**
* - Handling Error when dialect is W3C
* ERROR response format from SeleniumHUB `{
* sessionId: ...,
* status: 13,
* value: { error: '', message: ''}
* }
*/
const errResponse = (e?.response?.body && JSON.parse(e?.response?.body)?.value) || {};
const errMessage = errResponse?.message || errResponse?.error || e?.message || e?.error || e?.value || e.toString();
throw new Error(errMessage);
}
});
}
Expand Down
38 changes: 34 additions & 4 deletions packages/webdriver-utils/test/providers/automateProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,50 @@ describe('AutomateProvider', () => {
spyOn(Driver.prototype, 'getCapabilites');
});

it('supresses exception and does not throw', async () => {
it('throw error', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
automateProvider.driver.executeScript = jasmine.createSpy().and.rejectWith(new Error('Random network error'));
await automateProvider.percyScreenshotBegin('abc');
spyOn(Driver.prototype, 'executeScript').and.returnValue(Promise.reject(new Error('Random network error')));
await expectAsync(automateProvider.percyScreenshotBegin('abc')).toBeRejectedWithError('Random network error');
});

it('marks the percy session as success', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
automateProvider.driver.executeScript = jasmine.createSpy().and.returnValue(Promise.resolve({ success: true }));
spyOn(Driver.prototype, 'executeScript').and.returnValue(Promise.resolve({ success: true }));
await automateProvider.percyScreenshotBegin('abc');
expect(automateProvider._markedPercy).toBeTruthy();
});

it('throw error if statusCode:13', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
spyOn(Driver.prototype, 'executeScript').and.returnValue(Promise.resolve({ status: 13, value: 'OS/Browser/Selenium combination is not supported' }));
await expectAsync(automateProvider.percyScreenshotBegin('abc')).toBeRejectedWithError('OS/Browser/Selenium combination is not supported');
});

it('throw "Got invalid error resposne" if result.value does not exists', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
spyOn(Driver.prototype, 'executeScript').and.returnValue(Promise.resolve({ status: 13 }));
await expectAsync(automateProvider.percyScreenshotBegin('abc')).toBeRejectedWithError('Got invalid error response');
});

it('mark percy sesssion as failure', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
// eslint-disable-next-line prefer-promise-reject-errors
spyOn(Driver.prototype, 'executeScript').and.returnValue(Promise.reject({ response: { body: JSON.stringify({ value: { error: 'OS/Browser/Selenium combination is not supported', message: 'OS/Browser/Selenium combination is not supported' } }) } }));
await expectAsync(automateProvider.percyScreenshotBegin('abc')).toBeRejectedWithError('OS/Browser/Selenium combination is not supported');
});

it('catch direct response error', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
// eslint-disable-next-line prefer-promise-reject-errors
spyOn(Driver.prototype, 'executeScript').and.returnValue(Promise.reject('Random Error'));
await expectAsync(automateProvider.percyScreenshotBegin('abc')).toBeRejectedWithError('Random Error');
});
});

describe('percyScreenshotEnd', () => {
Expand Down

0 comments on commit c244a33

Please sign in to comment.