Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
feat(all): rename interface driver to adapter (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
clebert committed Apr 4, 2018
1 parent 99a93a4 commit 307f3fa
Show file tree
Hide file tree
Showing 75 changed files with 601 additions and 607 deletions.
14 changes: 7 additions & 7 deletions @pageobject/base/src/Component.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, Driver, Effect, Locator, Operator} from '.';
import {Adapter, Component, Effect, Locator, Operator} from '.';

class TestDriver implements Driver<HTMLElement> {
class TestAdapter implements Adapter<HTMLElement> {
public async findElements(
selector: string,
parent?: HTMLElement
Expand Down Expand Up @@ -54,19 +54,19 @@ class Descriptor<TComponent extends TestComponent> {

class A extends TestComponent {
public static create(
driver: Driver<HTMLElement>,
adapter: Adapter<HTMLElement>,
locator?: Locator<HTMLElement, A>
): A {
return new A(driver, locator, A, '.a');
return new A(adapter, locator, A, '.a');
}
}

class B extends TestComponent {
public static create(
driver: Driver<HTMLElement>,
adapter: Adapter<HTMLElement>,
locator?: Locator<HTMLElement, B>
): B {
return new B(driver, locator, B, '.b');
return new B(adapter, locator, B, '.b');
}
}

Expand Down Expand Up @@ -287,7 +287,7 @@ describe('Component', () => {
<div class="a" id="A2">3</div>
`;

const a = A.create(new TestDriver());
const a = A.create(new TestAdapter());

describeTests(a, undefined, 1);
describeTests(a, undefined, 2);
Expand Down
18 changes: 9 additions & 9 deletions @pageobject/base/src/Component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Describable, Effect, Operator} from '.';

export interface Driver<TElement> {
export interface Adapter<TElement> {
findElements(selector: string, parent?: TElement): Promise<TElement[]>;
}

Expand Down Expand Up @@ -30,26 +30,26 @@ export interface ComponentFactory<
TComponent extends Component<TElement>
> {
create(
driver: Driver<TElement>,
adapter: Adapter<TElement>,
locator?: Locator<TElement, TComponent>
): TComponent;
}

export class Component<TElement> implements Describable {
public readonly description: string;

private readonly _driver: Driver<TElement>;
private readonly _adapter: Adapter<TElement>;
private readonly _locator: Locator<TElement, this>;
private readonly _ownFactory: ComponentFactory<TElement, this>;
private readonly _selector: string;

protected constructor(
driver: Driver<TElement>,
adapter: Adapter<TElement>,
locator: Locator<TElement, any> = {}, // tslint:disable-line no-any
ownFactory: ComponentFactory<TElement, any>, // tslint:disable-line no-any
selector: string
) {
this._driver = driver;
this._adapter = adapter;
this._locator = locator;
this._ownFactory = ownFactory;
this._selector = selector;
Expand All @@ -60,15 +60,15 @@ export class Component<TElement> implements Describable {
public select<TDescendant extends Component<TElement>>(
descendantFactory: ComponentFactory<TElement, TDescendant>
): TDescendant {
return descendantFactory.create(this._driver, {parent: this});
return descendantFactory.create(this._adapter, {parent: this});
}

public nth(position: number): this {
if (position < 1) {
throw new Error('Position must be one-based');
}

return this._ownFactory.create(this._driver, {...this._locator, position});
return this._ownFactory.create(this._adapter, {...this._locator, position});
}

public where<TValue>(
Expand All @@ -77,7 +77,7 @@ export class Component<TElement> implements Describable {
): this {
const {filters} = this._locator;

return this._ownFactory.create(this._driver, {
return this._ownFactory.create(this._adapter, {
...this._locator,
filters: [...(filters || []), {accessor, operator}]
});
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Component<TElement> implements Describable {
private async _filterElements(): Promise<TElement[]> {
const {filters, parent} = this._locator;

const elements = await this._driver.findElements(
const elements = await this._adapter.findElements(
this._selector,
parent ? await parent.findElement() : undefined
);
Expand Down
9 changes: 9 additions & 0 deletions @pageobject/protractor/src/ProtractorAdapter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {WebAdapterTest} from '@pageobject/web';
import {browser} from 'protractor';
import {ProtractorAdapter} from '.';

describe('ProtractorAdapter', () => {
it('should pass the WebAdapterTest successfully', async () => {
await new WebAdapterTest(new ProtractorAdapter(browser)).run();
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// tslint:disable no-redundant-jsdoc

import {Argument, Key, WebDriver, WebElement} from '@pageobject/web';
import {Argument, Key, WebAdapter, WebElement} from '@pageobject/web';
import * as protractor from 'protractor';

class ProtractorWebElement implements WebElement {
class ProtractorElement implements WebElement {
public readonly adaptee: protractor.WebElement;

public constructor(adaptee: protractor.WebElement) {
Expand Down Expand Up @@ -33,9 +33,9 @@ class ProtractorWebElement implements WebElement {
}

/**
* @implements https://pageobject.js.org/api/web/interfaces/webdriver.html
* @implements https://pageobject.js.org/api/web/interfaces/webadapter.html
*/
export class ProtractorWebDriver implements WebDriver {
export class ProtractorAdapter implements WebAdapter {
private readonly _browser: protractor.ProtractorBrowser;

/**
Expand All @@ -56,11 +56,11 @@ export class ProtractorWebDriver implements WebDriver {
selector: string,
parent?: WebElement
): Promise<WebElement[]> {
const parentElement = parent && (parent as ProtractorWebElement).adaptee;
const parentElement = parent && (parent as ProtractorElement).adaptee;

return (await (parentElement || this._browser.driver).findElements(
protractor.By.css(selector)
)).map(element => new ProtractorWebElement(element));
)).map(element => new ProtractorElement(element));
}

public async navigateTo(url: string): Promise<void> {
Expand Down
9 changes: 0 additions & 9 deletions @pageobject/protractor/src/ProtractorWebDriver.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion @pageobject/protractor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ProtractorWebDriver';
export * from './ProtractorAdapter';
21 changes: 21 additions & 0 deletions @pageobject/puppeteer/src/PuppeteerAdapter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {WebAdapterTest} from '@pageobject/web';
import {PuppeteerAdapter} from '.';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

describe('PuppeteerAdapter', () => {
it('should pass the WebAdapterTest successfully', async () => {
const chromeArgs =
process.env.CI === 'true'
? [
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-sandbox'
]
: [];

await new WebAdapterTest(
await PuppeteerAdapter.create({args: chromeArgs})
).run();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable no-redundant-jsdoc

import {Argument, Key, WebDriver, WebElement} from '@pageobject/web';
import {Argument, Key, WebAdapter, WebElement} from '@pageobject/web';
import {
Browser,
ElementHandle,
Expand All @@ -10,7 +10,7 @@ import {
launch
} from 'puppeteer';

class PuppeteerWebElement implements WebElement {
class PuppeteerElement implements WebElement {
public readonly adaptee: ElementHandle;
public readonly page: Page;

Expand All @@ -37,20 +37,20 @@ class PuppeteerWebElement implements WebElement {
}

/**
* @implements https://pageobject.js.org/api/web/interfaces/webdriver.html
* @implements https://pageobject.js.org/api/web/interfaces/webadapter.html
*/
export class PuppeteerWebDriver implements WebDriver {
export class PuppeteerAdapter implements WebAdapter {
/**
* @param launchOptions https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
* @param navigationOptions https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagegotourl-options
*/
public static async create(
launchOptions?: LaunchOptions,
navigationOptions?: NavigationOptions
): Promise<PuppeteerWebDriver> {
): Promise<PuppeteerAdapter> {
const browser = await launch(launchOptions);

return new PuppeteerWebDriver(
return new PuppeteerAdapter(
browser,
await browser.newPage(),
navigationOptions
Expand Down Expand Up @@ -92,7 +92,7 @@ export class PuppeteerWebDriver implements WebDriver {
(_selector: string, _parent: Element | undefined) =>
(_parent || document).querySelectorAll(_selector),
selector,
parent && (parent as PuppeteerWebElement).adaptee
parent && (parent as PuppeteerElement).adaptee
);

const lengthHandle = await elementsHandle.getProperty('length');
Expand All @@ -116,9 +116,7 @@ export class PuppeteerWebDriver implements WebDriver {

await elementsHandle.dispose();

return elements.map(
element => new PuppeteerWebElement(element, this._page)
);
return elements.map(element => new PuppeteerElement(element, this._page));
}

public async navigateTo(url: string): Promise<void> {
Expand Down
21 changes: 0 additions & 21 deletions @pageobject/puppeteer/src/PuppeteerWebDriver.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion @pageobject/puppeteer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './PuppeteerWebDriver';
export * from './PuppeteerAdapter';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {WebDriverTest} from '@pageobject/web';
import {WebAdapterTest} from '@pageobject/web';
import {ChildProcess, spawn} from 'child_process';
import getPort from 'get-port';
import {SeleniumWebDriver} from '.';
import {SeleniumAdapter} from '.';

const updateConfig = require('webdriver-manager/selenium/update-config.json');

Expand Down Expand Up @@ -36,7 +36,7 @@ class ChromeDriver {

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

describe('SeleniumWebDriver', () => {
describe('SeleniumAdapter', () => {
const chromeDriver = new ChromeDriver();

beforeAll(async () => {
Expand All @@ -47,7 +47,7 @@ describe('SeleniumWebDriver', () => {
chromeDriver.stop();
});

it('should pass the WebDriverTest successfully', async () => {
it('should pass the WebAdapterTest successfully', async () => {
const chromeArgs =
process.env.CI === 'true'
? [
Expand All @@ -59,8 +59,8 @@ describe('SeleniumWebDriver', () => {
]
: ['--headless', '--disable-gpu'];

await new WebDriverTest(
await SeleniumWebDriver.create({
await new WebAdapterTest(
await SeleniumAdapter.create({
browserName: 'chrome',
chromeOptions: {args: chromeArgs}
})
Expand Down

0 comments on commit 307f3fa

Please sign in to comment.