-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathqa-sign-upload-check.mjs
More file actions
52 lines (41 loc) · 1.82 KB
/
Copy pathqa-sign-upload-check.mjs
File metadata and controls
52 lines (41 loc) · 1.82 KB
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
import { chromium } from 'playwright';
const baseUrl = 'http://127.0.0.1:4174';
const pdfPath = '/Users/dhananjaybhosale/Downloads/PDFTools-main/qa-sample.pdf';
const signPath = '/Users/dhananjaybhosale/Downloads/PDFTools-main/qa-sign.png';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
const out = {};
try {
await page.goto(`${baseUrl}/#/sign`, { waitUntil: 'domcontentloaded' });
await page.getByRole('heading', { name: 'Sign PDF' }).waitFor({ timeout: 10000 });
out.navigate = true;
await page.locator('input[type="file"]').first().setInputFiles(pdfPath);
await page.getByText(/Page\s+1\s*\/\s*3/i).first().waitFor({ timeout: 25000 });
out.uploadPdf = true;
await page.getByRole('button', { name: /Add signature/i }).first().click();
await page.getByRole('heading', { name: /Create Signature Stamp/i }).waitFor({ timeout: 10000 });
out.modalOpen = true;
await page.getByRole('button', { name: /^Upload$/i }).click();
const imageInput = page.locator('input[type="file"]').last();
await imageInput.setInputFiles(signPath);
await sleep(700);
const addBtn = page.getByRole('button', { name: /Add Stamp/i });
out.addEnabled = await addBtn.isEnabled();
await addBtn.click();
await page.getByText(/Stamp\s+1/i).first().waitFor({ timeout: 15000 });
out.stampAdded = true;
const select = page.locator('select').first();
await select.selectOption('1');
await sleep(300);
out.selectedPage = await select.inputValue();
await page.getByRole('button', { name: /^Export$/i }).first().click();
await sleep(1200);
out.exportClicked = true;
out.success = true;
} catch (error) {
out.success = false;
out.error = String(error);
}
console.log(JSON.stringify(out, null, 2));
await browser.close();