Skip to content

Commit

Permalink
Added wdio support with ts (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-browserstack authored Oct 30, 2023
1 parent 7a6d784 commit 9ffc1c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion driverMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DriverMetadata {
constructor(driver) {
this.driver = driver;
this.sessionId = null;
if (this.driver.constructor.name === 'Browser') {
if (this.driver.constructor.name.includes('Browser')) {
this.type = 'wdio';
} else {
this.type = 'wd';
Expand Down
16 changes: 13 additions & 3 deletions test/driverMetadata.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { DriverMetadata } from '../driverMetadata.js';
import { Cache } from '../cache.js';

describe('DriverMetadata', () => {

class Browser { // Mocking WDIO driver
constructor() {
this.sessionId = '123';
this.capabilities = { browserName: 'chrome' };
this.options = { protocol: 'https', path: '/wd/hub', hostname: 'hub-cloud.browserstack.com' };
}
}
class BoundBrowser { // Mocking ts WDIO driver
constructor() {
this.sessionId = '123';
this.capabilities = { browserName: 'chrome' };
this.options = { protocol: 'https', path: '/wd/hub', hostname: 'hub-cloud.browserstack.com' };
}
}
let driver;

beforeAll(async function() {
Expand All @@ -28,12 +34,16 @@ describe('DriverMetadata', () => {
Cache.reset();
});


describe('getSessionId', () => {
it ('returns the sessionId', async () => {
it('returns the sessionId', async () => {
const driverMetadata = new DriverMetadata(driver);
await expectAsync(driverMetadata.getSessionId()).toBeResolvedTo('123');
});

it('Should work with typescript wdio', async () => {
const driverMetadata = new DriverMetadata(new BoundBrowser());
await expectAsync(driverMetadata.getSessionId()).toBeResolvedTo('123');
});
});

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

0 comments on commit 9ffc1c6

Please sign in to comment.