File size: 2,146 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import { Page } from 'playwright';
import { TestFile } from '../../types';
/**
* Page representing the Blaze Campaign page (/advertising/posts).
*/
export class BlazeCampaignPage {
private page: Page;
/**
* Constructs an instance of the component.
*
* @param {Page} page The underlying page.
*/
constructor( page: Page ) {
this.page = page;
}
/**
* Clicks on a button with the accessible name matching the supplied parameter `name`.
*
* @param {string} name Accessible name of the button.
*/
async clickButton( name: string ) {
await this.page.getByRole( 'button', { name: name } ).click();
}
/**
* Enters text into any text field, except for the secure payment details fields.
*
* @param {string} name Accessible name of the target text field.
* @param {string} text Text to enter.
*/
async enterText( name: string, text: string ) {
// Clear out the field first.
await this.page.getByRole( 'textbox', { name: name } ).clear();
await this.page.getByRole( 'textbox', { name: name } ).fill( text );
}
/**
* Uploads the specified image to the Blaze campaign image.
*
* @param {TestFile} path TestFile object.
*/
async uploadImage( path: TestFile ) {
const timeout = 15_000;
const fileChooserPromise = this.page.waitForEvent( 'filechooser', { timeout } );
const [ fileChooser ] = await Promise.all( [
fileChooserPromise,
this.page
.getByRole( 'region', { name: 'Appearance' } )
.getByRole( 'button', { name: 'Upload' } )
.click( { timeout } ),
] );
await fileChooser.setFiles( path.fullpath );
await this.page.getByRole( 'region', { name: 'Appearance' } ).locator( 'img' ).waitFor();
}
/**
* Validates the expected contents are in the preview.
*
* @param param0 Keyed object parameter.
* @param {string} param0.title Expected title.
* @param {string} param0.snippet Expected snippet.
*/
async validatePreview( { title, snippet }: { title: string; snippet: string } ) {
await this.page.locator( '.ad-preview-section' ).getByText( title ).waitFor();
await this.page.locator( '.ad-preview-section' ).getByText( snippet ).waitFor();
}
}
|