platform/qms-tests/sanity/tests/model/documents/pdf-pages.ts
JasminMus 1d3299e384
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Visual check for PDF (#6599)
Signed-off-by: Jasmin <jasmin@hardcoreeng.com>
2024-10-16 14:18:38 +04:00

35 lines
1.1 KiB
TypeScript

import { type Locator, type Page, expect } from '@playwright/test'
export class PdfPages {
readonly page: Page
readonly printToPdf: Locator
readonly printToPdfHeader: Locator
readonly downloadPdf: Locator
readonly showFullScreenPdf: Locator
constructor (page: Page) {
this.page = page
this.printToPdf = page.getByRole('button', { name: 'Print to PDF' })
this.printToPdfHeader = page.getByText('PDF PDF print preview')
this.downloadPdf = page.locator('form').getByRole('link').getByRole('button')
this.showFullScreenPdf = page.locator('form').getByRole('button').nth(2)
}
async printToPdfClick (): Promise<void> {
await this.printToPdf.click()
await expect(this.printToPdfHeader).toBeVisible()
}
async showFullScreenPdfClick (): Promise<void> {
await this.showFullScreenPdf.click()
}
async downloadAndVerifyPdf (): Promise<void> {
const [download] = await Promise.all([this.page.waitForEvent('download'), this.downloadPdf.click()])
const filePath = await download.path()
expect(filePath).toBeTruthy()
const fileName = download.suggestedFilename()
console.log(`Downloaded file: ${fileName}`)
}
}