PDF Validation with UI
Step 1: Click on Add Test Case and create a new test case.

Step 2: Add the steps to the test case to navigate to the screen where elements are visible, which we need to validate in the PDF document.

Step 3: Declare the empty variables in the test case writer to save values that are extracted from the PDF using a custom script.

Step 4: Add a custom script to access the data from the PDF document.

- In the custom script you can access the data from the PDF, which is further assigned to the variables declared by the user in the previous step.
- The following is an example script to draw out value from the PDF.
try {
URL url = new URL("https://devtestos.testgrid.io/assets/pdf/ToolsQA.pdf");
System.out.println("PDFURL2 == :-");
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
String output = null;
try {
document = PDDocument.load(fileToParse);
output = new org.apache.pdfbox.text.PDFTextStripper().getText(document);
String lines[] = output.split("\\r?\\n");
for (int i = 0; i < lines.length; i++) {
var_ISBNFromPDF = lines[15];
var_TitleFromPDF = lines[16];
var_SubTitleFromPDF = lines[17];
var_AuthorFromPDF = lines[18];
var_TotalPagesFromPDF = lines[20];
System.out.println("line ====== :"+i +"Value of lines" + lines[i]);
}
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
}catch (Exception e){
e.printStackTrace();
}
- Once the custom script is executed, the next step is to take the UI element values and save them in the variables declared by them.
Step 5: Declare the variables in the test case writer in which values are retrieved from the UI elements.

Step 6 : Add steps to check if the values retrieved from the UI are the same as the values obtained from the PDF.

Step 7: Click on ‘Save’ to save the testcase.
Step 8: Once the testcase is ready, select the testcase and click on ‘Run’.

Step 9: Enter the URL of the website you want to test and tap ‘Next.’

Step 10: Select the browser and tap ‘Run Test’.

- As the test case starts to run, you can see the logs of the test case execution.

- You can also see the values printed in logs, which are taken from a PDF using a custom script.

- If the test run is successfully executed, the user can see the messages “Completed” and “Test success” in the detailed log.

Happy Testing!!
