Webtest WebTest GitHub Home

Available PDF Steps

This is the syntax documentation for the PDF steps.

The PDF Steps allow various tests to be performed on PDF files that may be referenced by your web pages. There are steps which let you verify text content, verify fonts used, verify links, verify bookmarks, verify security information, verify form information and document metadata as well as various filters which allow you to further manipulate the extracted information.

Simple Usage Example

Canoo WebTest automatically stores away web pages that you visit as the current response. When you visit non-web page resources (such as PDFs) Canoo WebTest doesn't automatically store away the response unless the saveresponse attribute of your config element is set to "true". The PDF document to test will then become the current response by invoking a URL that refers to your PDF document, or by submitting a form that will return the PDF document as its result, or by any other scenario that generates a request and has the PDF document as its response. Once the PDF document is available, you can perform different verifications on it using any of the available PDF or base steps.

sampleSimpleUsageExample.xml
<project name="Sample: SimplePDFTestbasedir=".default="main">

  <import file="${webtest.home}/lib/taskdef.xml"/>

  <target name="main">
    <webtest name="myPdfTest">
      <config
        host="www.myserver.com"
        port="8080"
        protocol="http"
        basepath="myApp"
        saveresponse="true"/>
      <steps>
        <invoke
          description="get overview page"
          url="overview.html" />
        <invoke
          description="get PDF document"
          url="publicData.pdf"/>
        <pdfVerifyTitle
          title=".+public.*"
          regex="true"/>
        <pdfVerifyPageCount
          count="2"/>
      </steps>
    </webtest>
  </target>
</project>

Encrypted Document Example

In order to test encrypted PDF documents you might want to decrypt it first. Otherwise, some content cannot be verified properly, e.g. AcroForm fields.

sampleEncryptedUsageExample.xml
<project name="Sample: EncryptedPDFTestbasedir=".default="main">

  <import file="${webtest.home}/lib/taskdef.xml"/>

  <target name="main">
    <webtest name="myPdfTest">
      <config
        host="www.myserver.com"
        port="8080"
        protocol="http"
        basepath="myApp"
        saveresponse="true"/>
      <steps>
        <invoke
          description="get overview page"
          url="overview.html" />
        <invoke
          description="get PDF document"
          url="privateData.pdf"/>
        <pdfDecryptDocument
          password="mymaster"/>
        <pdfVerifyText
          startPage="2"
          endPage="3"
          text="All rights reserved."/>
      </steps>
    </webtest>
  </target>
</project>

Debugging PDF documents

Sometimes it is helpful to debug PDF documents on a very low-level. The included pdfUnit library comes with a Swing PDF Object Browser allowing low-level analysis of PDF documents.

.../WEBTEST_HOME/lib/java -jar pdfUnit.jar

Note that when you start the PDF Object Browser, the log4j, pdfbox, and pdfUnit libraries must all be in the same directory.

Additional Setup Information

You have three ways to incorporate the PDF steps into your tests:

Import all steps approach:
Simply use <import file="${webtest.home}/lib/taskdef.xml"/> as illustrated in the Samples.
Specific plugins approach:
You can explicitly define the base and PDF tasks: <taskdef resource="webtest_base_strict.taskdef" classpathref="webtest.all" loaderref="webtest.loader"/> <taskdef resource="webtest_pdftest_relaxed.taskdef" classpathref="webtest.all" loaderref="webtest.loader"/>
Antlib approach:
You can use namespaces as follows: <target xmlns:pdftest="antlib:com.canoo.webtest.plugins.pdftest" name="main"> then simply refer to the steps using the namespace you defined, pdftest in this case, e.g. <pdftest:verifyPageCount count="1"/> <pdftest:verifyText text="Some text on page"/> Note that the pdf prefix is stripped off any tasks starting with pdf.