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

Commit

Permalink
feat: improve adapter api
Browse files Browse the repository at this point in the history
  • Loading branch information
clebert committed Nov 28, 2017
1 parent 3cbcc99 commit e8354a4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
2 changes: 0 additions & 2 deletions @pageobject/class/src/AdapterMock.ts
Expand Up @@ -6,7 +6,5 @@ export class AdapterMock<TElement> implements Adapter<TElement> {
public readonly evaluate: jest.Mock<Promise<any>> = jest.fn();
public readonly findElements: jest.Mock<Promise<TElement[]>> = jest.fn();
public readonly isVisible: jest.Mock<Promise<boolean>> = jest.fn();
public readonly open: jest.Mock<Promise<void>> = jest.fn();
public readonly quit: jest.Mock<Promise<void>> = jest.fn();
public readonly type: jest.Mock<Promise<void>> = jest.fn();
}
11 changes: 6 additions & 5 deletions @pageobject/class/src/AdapterTestSuite.ts
Expand Up @@ -26,12 +26,13 @@ export abstract class AdapterTestSuite<
TElement,
TAdapter extends Adapter<TElement>
> {
public abstract createAdapter(): Promise<TAdapter>;
public abstract setUp(url: string): Promise<TAdapter>;
public abstract tearDown(adapter: TAdapter): Promise<void>;

public async runTests(): Promise<void> {
const adapter = await this.createAdapter();

await adapter.open(`file://${join(__dirname, '../fixtures/index.html')}`);
const adapter = await this.setUp(
`file://${join(__dirname, '../fixtures/index.html')}`
);

try {
const allElements = await adapter.findElements('p');
Expand Down Expand Up @@ -73,7 +74,7 @@ export abstract class AdapterTestSuite<
'foo bar baz'
);
} finally {
await adapter.quit();
await this.tearDown(adapter);
}
}
}
2 changes: 0 additions & 2 deletions @pageobject/class/src/PageObject.ts
Expand Up @@ -9,8 +9,6 @@ export interface Adapter<TElement> {
/* tslint:enable no-any */

findElements(selector: string, parent?: TElement): Promise<TElement[]>;
open(url: string): Promise<void>;
quit(): Promise<void>;
type(element: TElement, text: string, delay: number): Promise<void>;
}

Expand Down
8 changes: 0 additions & 8 deletions @pageobject/puppeteer-adapter/src/PuppeteerAdapter.ts
Expand Up @@ -68,14 +68,6 @@ export class PuppeteerAdapter implements Adapter<ElementHandle> {
return elements;
}

public async open(url: string): Promise<void> {
await this.page.goto(url);
}

public async quit(): Promise<void> {
await this.browser.close();
}

public async type(
element: ElementHandle,
text: string,
Expand Down
Expand Up @@ -6,8 +6,16 @@ class PuppeteerAdapterTestSuite extends AdapterTestSuite<
ElementHandle,
PuppeteerAdapter
> {
public async createAdapter(): Promise<PuppeteerAdapter> {
return PuppeteerAdapter.launchChrome();
public async setUp(url: string): Promise<PuppeteerAdapter> {
const adapter = await PuppeteerAdapter.launchChrome();

await adapter.page.goto(url);

return adapter;
}

public async tearDown(adapter: PuppeteerAdapter): Promise<void> {
await adapter.browser.close();
}
}

Expand Down
8 changes: 0 additions & 8 deletions @pageobject/selenium-adapter/src/SeleniumAdapter.ts
Expand Up @@ -49,14 +49,6 @@ export class SeleniumAdapter implements Adapter<WebElement> {
return (parent || this.driver).findElements(By.css(selector));
}

public async open(url: string): Promise<void> {
await this.driver.navigate().to(url);
}

public async quit(): Promise<void> {
await this.driver.quit();
}

public async type(
element: WebElement,
text: string,
Expand Down
12 changes: 10 additions & 2 deletions @pageobject/selenium-adapter/src/__tests__/SeleniumAdapter.test.ts
Expand Up @@ -9,8 +9,16 @@ class SeleniumAdapterTestSuite extends AdapterTestSuite<
WebElement,
SeleniumAdapter
> {
public async createAdapter(): Promise<SeleniumAdapter> {
return SeleniumAdapter.launchHeadlessChrome();
public async setUp(url: string): Promise<SeleniumAdapter> {
const adapter = await SeleniumAdapter.launchHeadlessChrome();

await adapter.driver.navigate().to(url);

return adapter;
}

public async tearDown(adapter: SeleniumAdapter): Promise<void> {
await adapter.driver.quit();
}
}

Expand Down

0 comments on commit e8354a4

Please sign in to comment.