PDF Validation with UI

You are here:
< All Topics

Step 1:- Click on Add Test Case and create a new testcase.

create a new testcase in TestGrid Automation Testing tool

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

Add the steps to the testcase for PDF Validation with UI

Step 3 :-  Declare the empty variables on Test case writer to save values that are extracted from PDF using custom script.

Declare the empty variables on Test case writer for PDF Validation with UI

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

Add a custom script  in TestGrid Automation Testing tool

Step 5:- Call the custom script to extract values from the PDF.

  • In the custom script you can access the data from the PDF, which are further assigned to the variables declared by the user in the previous step.
  • Following is the 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 6:- Declare the variables on the test case writer in which values are retrieved from the UI elements.

Step 7:- Add steps to check if the values retrieved from UI is the same as the value obtained from the PDF.

Step 8:- Click on ‘Save’ to save the testcase.

Step 9:- Once testcase is ready select the testcase and click on ‘Run’.

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

Step 11:- 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 out from PDF using custom script.

 

  • If the test run is successfully executed, the user can see the message of “Completed” and “Test success” in the Detailed Log.

Table of Contents