Skip to content

Commit

Permalink
Rename WDIO adapter filename to match class name
Browse files Browse the repository at this point in the history
  • Loading branch information
NiGhTTraX committed May 21, 2019
1 parent 0dab633 commit f64da13
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
37 changes: 2 additions & 35 deletions packages/webdriverio/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
import { Browser } from 'mugshot';
import WebdriverIOAdapter from './lib/webdriverio-adapter';

/* istanbul ignore next because this will get stringified and sent to the browser */
function getBoundingRect(selector: string): DOMRect {
// @ts-ignore because querySelector can be null and we don't
// care about browsers that don't support it.
return document.querySelector(selector).getBoundingClientRect();
}

/**
* API adapter for WebdriverIO to make working with it saner.
*/
export default class WebdriverIOAdapter implements Browser {
private browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser;

constructor(browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser) {
this.browser = browser;
}

takeScreenshot = async () => this.browser.takeScreenshot();

getElementRect = async (selector: string) => {
// @ts-ignore because the return type is not properly inferred
const rect: DOMRect = await this.browser.execute(
getBoundingRect,
selector
);

return {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height
};
};
}
export default WebdriverIOAdapter;
36 changes: 36 additions & 0 deletions packages/webdriverio/src/lib/webdriverio-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Browser } from 'mugshot';

/* istanbul ignore next because this will get stringified and sent to the browser */
function getBoundingRect(selector: string): DOMRect {
// @ts-ignore because querySelector can be null and we don't
// care about browsers that don't support it.
return document.querySelector(selector).getBoundingClientRect();
}

/**
* API adapter for WebdriverIO to make working with it saner.
*/
export default class WebdriverIOAdapter implements Browser {
private browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser;

constructor(browser: WebDriver.ClientAsync & WebdriverIOAsync.Browser) {
this.browser = browser;
}

takeScreenshot = async () => this.browser.takeScreenshot();

getElementRect = async (selector: string) => {
// @ts-ignore because the return type is not properly inferred
const rect: DOMRect = await this.browser.execute(
getBoundingRect,
selector
);

return {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height
};
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, loadFixture, expectIdenticalScreenshots } from '../../../../../tests/gui/suite';
import WebdriverIOAdapter from '../../../src';
import { expect } from 'chai';
import WebdriverIOAdapter from '../../../src/lib/webdriverio-adapter';

describe('WebdriverIOAdapter', () => {
it('should take a full page screenshot', async browser => {
Expand Down

0 comments on commit f64da13

Please sign in to comment.