Last active
November 24, 2019 16:18
-
-
Save patricksevat/07888a1666384b0ea3479a1f231be60a to your computer and use it in GitHub Desktop.
extended-page-object.ts
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
// ./objects/base/page-object-base.ts | |
export interface IComponentObject { | |
[key: string]: any; | |
isRendered(): Promise<any>; | |
} | |
export abstract class PageObjectBase { | |
// the root element for the page, for example: dashboard-page | |
element: string; | |
// all registered features and UI components (instances of Component Object) | |
// example: this.features = [new BankAccount(), new Navigation()] | |
features: IComponentObject[]; | |
// url for the page | |
url: string; | |
// used runtime to add Promises to waitUntilRendered | |
// possible use case: need to fetch/post data before kicking of tests | |
pageRenderRequirements: (() => Promise<any>)[] = []; | |
verifyRenderRequirements() { | |
if (this.features.length === 0 && this.pageRenderRequirements.length === 0) { | |
return Promise.reject(`${this.element} has no registered features or page render requirements`); | |
} | |
} | |
async waitUntilRendered(options = { skipComponents: [] }): Promise<any> { | |
try { | |
// skipComponent can runtime exclude components | |
const skipComponents = options.skipComponents; | |
await this.verifyRenderRequirements(); | |
const promises = [ | |
...this.pageRenderRequirements, | |
...this.features | |
.filter(feature => !skipComponents.includes(feature.componentName)) | |
.map(feature => feature.render), | |
]; | |
return Promise.all(promises); | |
} catch (e) { | |
return Promise.reject(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment