Wednesday, July 1

Playwright automation using TypeScript

  I implemented PDF content validation in Playwright automation using TypeScript, with the support of AI coding assistants.


How it works:
1. Download the PDF file using Playwright's download event
2. Save the file to a local downloads folder
3. Verify that the file was downloaded successfully
4. Read the PDF file and extract its text content using the pdf-parse library
5. Validate that the expected text exists in the PDF using assertions

// Wait for download event before clicking const downloadPromise = documentObjectPage.page.waitForEvent('download'); // Click on download button await documentObjectPage.downloadButton.click(); // Download Promise const download await downloadPromise; // save file to known path const savePath = path.join(downloadsDir, download.suggestedFilename()); await download.saveAs (savePath); // Store path for use in other methods downloadedFilePath = savePath; // Extract text from the downloaded PDF expect(fs.existssync (downloadedFilePath)).toBeTruthy(); const dataBuffer = fs.readFileSync (downloadedFilePath); const parser = new PDFParse({ data: dataBuffer }); const pdfData = await parser.getText(); console.log('Extracted PDF text:', pdfData.text); // verify text content expect(pdfData.text).toContain (Dummy PDF'); await parser.destroy();

No comments:

Post a Comment

𝗡𝗮𝗴𝗮𝗿𝗿𝗼 𝗤𝗔 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀

  𝗡𝗮𝗴𝗮𝗿𝗿𝗼 𝗤𝗔 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 - Write a Java Program to find the Maximum Sum Subarray.   ...