How To Test PDF Files Using Selenium Automation?

Image for post
Image for post

Note: The code samples may be displayed improperly because of markdown. I recommend continuing to read the original article on our blog to make sure all the examples are displayed properly.

Why Is It Important To Test A PDF File?

How To Handle PDF In Selenium Webdriver?

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.20</version>
</dependency>
Image for post
Image for post

Verify The Content In The PDF

Image for post
Image for post
Image for post
Image for post

Download PDF file

Image for post
Image for post
Image for post
Image for post

Set The Start Of The PDF Document

Image for post
Image for post
pdfStrip.setStartPage(2);
pdfStrip.setEndPage(3);
pdfStrip.setStartPage(2);
pdfStrip.setEndPage(2);

PDF Testing Using Selenium LambdaTest Grid

Image for post
Image for post
<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd">
<suite name=”PDF Handling”>
<test name=”Verify Pdf content”>
<classes>
<class name=”Automation.PdfHandlingInGrid”/>
</classes>
</test>
</suite>
Image for post
Image for post

How To View Your Tests In LambdaTest Dashboard?

Image for post
Image for post
Image for post
Image for post
capabilities.setCapability(“build”, “PdfTestLambdaTest”); //To identify the test
Image for post
Image for post

Wrapping Up!

Author Shalini Baskaran

Written by

Product Growth at @lambdatesting (www.lambdatest.com)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store