-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from efuller/update-pom
Update POM
- Loading branch information
Showing
12 changed files
with
256 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,11 @@ | ||
import puppeteer, { Browser, Page, PuppeteerLaunchOptions } from 'puppeteer'; | ||
|
||
export class PuppeteerPageDriver { | ||
private constructor(private instance: Browser, private page: Page) {} | ||
private constructor(public browser: Browser, public page: Page) {} | ||
|
||
/** | ||
* Creates a new instance of PuppeteerPageDriver | ||
* @param opts | ||
*/ | ||
public static async create(opts: PuppeteerLaunchOptions) { | ||
const instance = await puppeteer.launch(opts); | ||
const page = await instance.newPage(); | ||
return new PuppeteerPageDriver(instance, page); | ||
} | ||
|
||
/** | ||
* Closes the instance of PuppeteerPageDriver | ||
*/ | ||
public async close() { | ||
await this.instance.close(); | ||
} | ||
|
||
/** | ||
* Get the page. | ||
*/ | ||
public getPage() { | ||
return this.page; | ||
} | ||
|
||
/** | ||
* Pause the test for 3 seconds. | ||
*/ | ||
async pause() { | ||
await new Promise(r => setTimeout(r, 3000)) | ||
static async create(driverProps: PuppeteerLaunchOptions) { | ||
const browser = await puppeteer.launch(driverProps); | ||
const page = await browser.newPage(); | ||
return new PuppeteerPageDriver(browser, page); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { PuppeteerPageDriver } from "../driver/pupeteerPageDriver"; | ||
|
||
export type ComponentElementsConfig = { | ||
[key: string]: { selector: string }; | ||
}; | ||
|
||
export class BasePageComponent<T extends ComponentElementsConfig> { | ||
constructor( | ||
protected pageDriver: PuppeteerPageDriver, | ||
protected componentConfig: T | ||
) {} | ||
|
||
async isValid() { | ||
const errors: string[] = []; | ||
|
||
const promises = Object.keys(this.componentConfig).map(async (key) => { | ||
const component = this.componentConfig[key]; | ||
return await this.pageDriver.page.waitForSelector(component.selector) | ||
.then(() => true) | ||
.catch(() => { | ||
errors.push(component.selector); | ||
return false; | ||
}); | ||
}); | ||
|
||
const result = await Promise.all(promises); | ||
|
||
if (result.includes(false)) { | ||
throw new Error(`These selectors are not valid for the ${this.constructor.name}: ${errors.join(', ')}`); | ||
} | ||
return true; | ||
} | ||
|
||
async $(key: keyof T) { | ||
if (!this.componentConfig?.[key]) { | ||
throw new Error(`Page component ${String(key)} does not exist`); | ||
} | ||
|
||
const result = await this.pageDriver.page.waitForSelector(this.componentConfig[key].selector); | ||
|
||
if (!result) { | ||
throw new Error(`There was a problem selecting the page component ${String(key)}`); | ||
} | ||
return result; | ||
} | ||
|
||
async waitAndType(key: keyof T, text: string) { | ||
const input = await this.$(key); | ||
await input.type(text); | ||
} | ||
|
||
async waitAndClick(key: keyof T) { | ||
const input = await this.$(key); | ||
await input.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { BasePageComponent } from "../basePageComponent"; | ||
import { PuppeteerPageDriver } from "../../driver/pupeteerPageDriver"; | ||
|
||
type AddJournalFormElements = { | ||
titleInput: { selector: string }; | ||
submitBtn: { selector: string }; | ||
}; | ||
|
||
export class AddJournalFormComponent extends BasePageComponent<AddJournalFormElements> { | ||
constructor( | ||
protected pageDriver: PuppeteerPageDriver, | ||
protected componentConfig: AddJournalFormElements, | ||
) { | ||
super(pageDriver, componentConfig); | ||
} | ||
|
||
async addAndSubmit({ title }: { title: string }) { | ||
await this.waitAndType('titleInput', title); | ||
await this.waitAndClick('submitBtn'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { BasePageComponent } from '../basePageComponent'; | ||
import { PuppeteerPageDriver } from "../../driver/pupeteerPageDriver"; | ||
|
||
type JournalListFormElements = { | ||
journalList: { selector: string }; | ||
journalEntries: { selector: string }; | ||
journalTitle: { selector: string }; | ||
}; | ||
|
||
export class JournalList extends BasePageComponent<JournalListFormElements> { | ||
constructor( | ||
protected pageDriver: PuppeteerPageDriver, | ||
protected componentConfig: JournalListFormElements, | ||
) { | ||
super(pageDriver, componentConfig); | ||
} | ||
|
||
async getFirstJournal() { | ||
const journalList = await this.$('journalList'); | ||
|
||
if (!journalList) { | ||
throw new Error('Add journal form is not visible'); | ||
} | ||
|
||
const journalEntries = await journalList.$$(this.componentConfig.journalEntries.selector); | ||
|
||
if (journalEntries.length < 1) { | ||
throw new Error('Journal entries are not visible'); | ||
} | ||
|
||
const [firstJournal] = journalEntries; | ||
|
||
const title = await firstJournal.$eval(this.componentConfig.journalTitle.selector, (el) => el.textContent); | ||
|
||
return { | ||
title, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { PuppeteerPageDriver } from "../driver/pupeteerPageDriver"; | ||
|
||
export abstract class BasePage<T> { | ||
public pageComponents: T | undefined; | ||
|
||
protected constructor( | ||
protected pageDriver: PuppeteerPageDriver, | ||
protected url: string | ||
) { | ||
} | ||
|
||
$<K extends keyof T>(key: K): T[K] { | ||
if (!this.pageComponents?.[key]) { | ||
throw new Error(`Page component ${String(key)} does not exist`); | ||
} | ||
return this.pageComponents[key]; | ||
} | ||
|
||
abstract generatePageComponents(): Promise<T>; | ||
|
||
async navigate() { | ||
await this.pageDriver.page.goto(this.url); | ||
} | ||
} |
Oops, something went wrong.