add simple PDF test

This commit is contained in:
2024-03-27 22:46:51 +01:00
parent af76646322
commit ef8fa8ef37
9 changed files with 106 additions and 460 deletions
+21 -9
View File
@@ -1,18 +1,30 @@
import { test, expect } from '@playwright/test';
import * as fs from "fs";
import { PDFDocument } from 'pdf-lib'
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.goto("/");
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
await expect(page).toHaveTitle("Kém Karakter App");
});
test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
test('simple PDF', async ({ page }) => {
await page.goto("/");
await page.getByTestId("nev").fill("Playwright");
await page.getByTestId("isten").fill("nincs");
// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();
// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
const downloadPromise = page.waitForEvent('download');
await page.getByText("PDF").click()
const download = await downloadPromise;
const path = "./downloads/" + download.suggestedFilename()
await download.saveAs(path)
const actBuf = fs.readFileSync(path);
const actualDoc = await PDFDocument.load(actBuf);
const testBuf = fs.readFileSync('./expectations/Playwright_1.pdf');
const expectedDoc = await PDFDocument.load(testBuf);
expectedDoc.setModificationDate(actualDoc.getModificationDate())
const expectedBase64 = await expectedDoc.saveAsBase64()
const actualBase64 = await actualDoc.saveAsBase64()
expect(actualBase64).toEqual(expectedBase64)
});