File size: 1,214 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import { Page } from 'playwright';
import { EditorComponent } from './editor-component';
const selectors = {
acceptCookie: '.a8c-cookie-banner__ok-button, .a8c-cookie-banner__accept-all-button',
};
/**
* Represents the cookie banner shown on pages when not logged in.
*/
export class CookieBannerComponent {
private page: Page;
private editor: EditorComponent;
/**
* Constructs an instance of the component.
*
* @param {Page} page The underlying page.
* @param {EditorComponent} editor The EditorComponent instance.
*/
constructor( page: Page, editor: EditorComponent ) {
this.page = page;
this.editor = editor;
}
/**
* Accept and clear the cookie notice.
*/
async acceptCookie(): Promise< void > {
const editorParent = await this.editor.parent();
const locator = editorParent.locator( selectors.acceptCookie );
// Whether the cookie banner appears is not deterministic.
// If it is not present, exit early.
try {
await locator.waitFor( { timeout: 100 } );
} catch ( e ) {
// Probably doesn't exist. That's ok.
}
if ( ( await locator.count() ) === 0 ) {
return;
}
if ( await locator.isVisible() ) {
await locator.dispatchEvent( 'click' );
}
}
}
|