platform/qms-tests/sanity/tests/model/documents/pdf-pages.ts
JasminMus 9095853f7b
Add test for downloading PDF (#6541)
Signed-off-by: Jasmin <jasmin@hardcoreeng.com>
Co-authored-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
2024-09-16 11:31:27 +07:00

29 lines
965 B
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
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')
}
async printToPdfClick (): Promise<void> {
await this.printToPdf.click()
await expect(this.printToPdfHeader).toBeVisible()
}
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}`)
}
}