Read Saved PDF File
The automation scenario requires a saved PDF file to be opened, then to read its content and to validate it.
The described approach using a 3rd party and open source dll is applicable for WPF and Desktop tests. Test Studio web tests let's you validate the PDF file in the browser out-of-the-box.
Solution
-
We prepared a sample using the third party dll iTextSharp.dll. It can be downloaded from its official page here.
Note
You can choose any other external library with similar functionality and implement the proper code for the actions that suits your needs. Copy the unzipped dll into the project root folder and add reference to it in the Test Studio project from that location.
-
Create a coded step in your test and add the following usings, or Imports for VB.Net, on top:
-
The below snippet opens a PDF file, which is stored locally on the disc, then reads and outputs its content to the test execution log file. The sample uses C# StringBuidler Class to append the text from the PDF file.