Skip to content

Commit

Permalink
Fixing constructor in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishigupta1599 committed Nov 3, 2023
1 parent 1bb7101 commit ef0fe54
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/webdriver-utils/test/providers/automateProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ describe('AutomateProvider', () => {
});

it('throws Error when called without initializing driver', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await expectAsync(automateProvider.browserstackExecutor('getSessionDetails'))
.toBeRejectedWithError('Driver is null, please initialize driver with createDriver().');
});

it('calls browserstackExecutor with correct arguemnts for actions only', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
await automateProvider.browserstackExecutor('getSessionDetails');
expect(executeScriptSpy)
.toHaveBeenCalledWith({ script: 'browserstack_executor: {"action":"getSessionDetails"}', args: [] });
});

it('calls browserstackExecutor with correct arguemnts for actions + args', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
await automateProvider.browserstackExecutor('getSessionDetails', 'new');
expect(executeScriptSpy)
Expand All @@ -65,7 +65,7 @@ describe('AutomateProvider', () => {
});

it('sets automate url', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
await automateProvider.screenshot('abc', { });

Expand All @@ -74,7 +74,7 @@ describe('AutomateProvider', () => {
});

it('throws error if driver is not initialized', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await expectAsync(automateProvider.setDebugUrl())
.toBeRejectedWithError('Driver is null, please initialize driver with createDriver().');
});
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('AutomateProvider', () => {
id: '123',
url: 'https://percy.io/abc/123'
};
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);

beforeEach(async () => {
percyScreenshotBeginSpy = spyOn(AutomateProvider.prototype,
Expand Down Expand Up @@ -149,14 +149,14 @@ describe('AutomateProvider', () => {
});

it('supresses exception and does not throw', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
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');
});

it('marks the percy session as success', async () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
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 }));
await automateProvider.percyScreenshotBegin('abc');
Expand All @@ -171,7 +171,7 @@ describe('AutomateProvider', () => {
};

let errorObj = new Error('Random network error');
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);

beforeEach(async () => {
spyOn(Driver.prototype, 'getCapabilites');
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('AutomateProvider', () => {
id: '123',
url: 'https://percy.io/abc/123'
};
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);

beforeEach(async () => {
spyOn(Driver.prototype, 'getCapabilites');
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('AutomateProvider', () => {
};

describe('for desktop', () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
beforeEach(async () => {
percyScreenshotBeginSpy = spyOn(AutomateProvider.prototype,
'percyScreenshotBegin').and.returnValue({ value: '{"buildHash":"12e3","sessionHash":"abc1d","capabilities":{"browserName":"chrome","browserVersion":"113.0","os":"win11","os_version":"11","deviceOrientation":false,"resolution":["1920","1080"]},"success":true,"deviceName":"x.x.x.x"}' });
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('AutomateProvider', () => {
});

describe('for devices', () => {
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'android' }, {}, {}, 'client', 'environment', percyBuildInfo);
const automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
beforeEach(async () => {
percyScreenshotBeginSpy = spyOn(AutomateProvider.prototype,
'percyScreenshotBegin').and.returnValue({ value: '{"buildHash":"12e3","sessionHash":"abc1d","capabilities":{"browserName":"chrome_android","browserVersion":"chrome_android","os":"android","os_version":"11","deviceOrientation":"portrait","resolution":["1920","1080"]},"success":true,"deviceName":"Samsung Galaxy S21"}' });
Expand Down Expand Up @@ -344,15 +344,15 @@ describe('AutomateProvider', () => {

describe('driver is null', () => {
it('throws Error when called without initializing driver', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await expectAsync(automateProvider.getTag())
.toBeRejectedWithError('Driver is null, please initialize driver with createDriver().');
});
});

describe('automateResults is null', () => {
it('throws Error automateResults are not available', async () => {
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, {}, 'client', 'environment', percyBuildInfo);
let automateProvider = new AutomateProvider('1234', 'https://localhost/command-executor', { platform: 'win' }, {}, 'client', 'environment', {}, percyBuildInfo);
await automateProvider.createDriver();
await expectAsync(automateProvider.getTag())
.toBeRejectedWithError('Comparison tag details not available');
Expand Down

0 comments on commit ef0fe54

Please sign in to comment.