playwright: Add togglePreview helper function
This adds a helper function that switches into preview. Heavily inspired by and all credit due to `content-sources-playwright`.
This commit is contained in:
parent
01efb93ff6
commit
cd5daade6b
1 changed files with 17 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { type Page, type FrameLocator } from '@playwright/test';
|
import { type Page, type FrameLocator, expect } from '@playwright/test';
|
||||||
|
|
||||||
export const ibFrame = (page: Page): FrameLocator | Page => {
|
export const ibFrame = (page: Page): FrameLocator | Page => {
|
||||||
if (isHosted()) {
|
if (isHosted()) {
|
||||||
|
|
@ -9,6 +9,21 @@ export const ibFrame = (page: Page): FrameLocator | Page => {
|
||||||
.contentFrame();
|
.contentFrame();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const togglePreview = async (page: Page) => {
|
||||||
|
const toggleSwitch = page.locator('#preview-toggle');
|
||||||
|
|
||||||
|
if (!(await toggleSwitch.isChecked())) {
|
||||||
|
await toggleSwitch.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
const turnOnButton = page.getByRole('button', { name: 'Turn on' });
|
||||||
|
if (await turnOnButton.isVisible()) {
|
||||||
|
await turnOnButton.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
await expect(toggleSwitch).toBeChecked();
|
||||||
|
};
|
||||||
|
|
||||||
export const login = async (page: Page) => {
|
export const login = async (page: Page) => {
|
||||||
if (!process.env.USER || !process.env.PASSWORD) {
|
if (!process.env.USER || !process.env.PASSWORD) {
|
||||||
throw new Error('user or password not set in environment');
|
throw new Error('user or password not set in environment');
|
||||||
|
|
@ -49,7 +64,7 @@ const loginConsole = async (page: Page, user: string, password: string) => {
|
||||||
await page.getByRole('textbox', { name: 'Password' }).fill(password);
|
await page.getByRole('textbox', { name: 'Password' }).fill(password);
|
||||||
await page.getByRole('button', { name: 'Log in' }).click();
|
await page.getByRole('button', { name: 'Log in' }).click();
|
||||||
await closePopupsIfExist(page);
|
await closePopupsIfExist(page);
|
||||||
await page.locator('#preview-toggle').check();
|
await togglePreview(page);
|
||||||
await page.getByRole('heading', { name: 'All images' });
|
await page.getByRole('heading', { name: 'All images' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue