locked
PDF Validation by Coded UI RRS feed

  • Question

  • Hi,

    I want to validate PDF contents by Coded UI, is it Possible, if coded UI not possible to validate PDF Reports, How to Validate PDF contents?

    Monday, August 22, 2011 9:51 AM

Answers

  • Franklin,

    1. Download IKVM from their website and follow the instructions to use it in your VSTS solution.
    2. Add reference to the Apache Pdfbox v1.5 library which you can download here : http://www.2shared.com/file/NPhshhVX/pdfbox-app-150.html
    3. Use the following method to get the PDF contents:

    Public Function readPDFContents(strPdfFilePath As String) As String

            Dim strFileContents As String = ""

            Dim objPDFDoc As PDDocument = Nothing

            Dim objTextStripper As PDFTextStripper = Nothing

            Try

                objPDFDoc = PDDocument.load(strPdfFilePath)

                strFileContents = New PDFTextStripper().getText(objPDFDoc)

            Catch objException As Exception

                Throw New System.Exception("Unhandled exception while retrieving pdf contents. Exception Details: " + objException.Message + objException.StackTrace)

            Finally

                If (Not IsNothing(objPDFDoc)) Then

                    objPDFDoc.close()

                End If

            End Try

            Return strFileContents

        End Function

    Let me know if you face issues.

    Regards,

    Tushar Palande

    Wednesday, August 24, 2011 6:48 AM

All replies

  •    Using Coded UI Test you can't validate PDF content.  Currently I am not aware of tools for testing PDF docs, but I am sure you can find many references for that in the Web

     

     


    Aditya Kumar Agrawal (MSFT)
    • Proposed as answer by Aditya_msft Monday, August 22, 2011 10:22 AM
    Monday, August 22, 2011 10:22 AM
  • thanks for your update, let me know , if you know any other tool supported
    Monday, August 22, 2011 10:56 AM
  • Franklin Dennis,

    Although you can not directly interact with a .pdf you could do one of the following:

    1.  Import the pdf to MS Word where you can then interact with the text directly.

    or

    2. Leverage the image comparison capabilities of the Coded UI framework to compare based on a known image of the pdf in question.

    See:

    How To: Do image comparison in Coded UI Test

    http://blogs.msdn.com/b/gautamg/archive/2010/04/08/how-to-do-image-comparison-in-coded-ui-test.aspx

    Cheers,

    Paul

    Monday, August 22, 2011 1:37 PM
  • Hi Franklin,

    In my last PoC we had PDF verification as part of the tests. The nature of this verification was textual i.e. I had to verify the text contents inside the PDF. I achieved this within Coded-UI tests.

    What exactly is the nature of the verification in your test ? Maybe I can then provide pointers.

    Regards,

    Tushar Palande

     

    Monday, August 22, 2011 5:17 PM
  • Hi Tushar,

    In my application, in the report page, we can enter value in text box, this value will be updated in the report PDF, this PDF also display in the same page, this entered text will be updated in the PDF particular area. I need to validate entered text is correctly updated in the PDF by Coded UI

    M. Franklin Dennis

    Tuesday, August 23, 2011 6:54 AM
  • Hi Franklin,

    You can take screenshots of the expected PDF and take the screenshot of the actual PDF page during playback and compare both of them.

    Refer this blog and see if this is helpful for ur task

    http://automatingflow.blogspot.com/2011/05/assert-two-screenshots-hack-in-visual.html


    ---Mark this post if this Answers or Helps---
    Cheers
    FunnyFox
    Tuesday, August 23, 2011 6:59 AM
  • Hi Franklin,

    The solution I used was:

    1. Get the contents of the PDF as a string. This can done for the pdf as a whole or page wise.

    2. Verfiy the text either independently or relative to other text within the pdf, either through string operations or through Regex.

    Do you think this will help ? If yes, I can point out the libraries to you.

    Regards,

    Tushar Palande

     



    • Edited by Tushar P Tuesday, August 23, 2011 10:38 AM
    Tuesday, August 23, 2011 7:54 AM
  • Hi Tushar,

    Yes, this will help to me, can you share libraries and guidence to proceed further.

     

    M. Franklin Dennis

     

    Tuesday, August 23, 2011 9:47 AM
  • Franklin,

    I used IKVM and Apache PDFBox for the purpose.

    I do not have the libraries handy at the moment, but can post them by tomorrow (IST).

    Meanwhile can you try using libraries mentioned above and let me know in case of queries.

    Regards,

    Tushar Palande

    Tuesday, August 23, 2011 10:45 AM
  • Hi Moderators,

    Is it OK to share links of uploaded libraries on this forum ?

    If no, Franklin pls provide your email id and I will send you the link to the pdfbox library. Use IKVM library from the respective website.

    Regards,

    Tushar Palande

    Tuesday, August 23, 2011 7:12 PM
  • Hi Tushar,

    You can share the libraries in forum itself.


    M. Franklin Dennis
    Wednesday, August 24, 2011 6:37 AM
  • Franklin,

    1. Download IKVM from their website and follow the instructions to use it in your VSTS solution.
    2. Add reference to the Apache Pdfbox v1.5 library which you can download here : http://www.2shared.com/file/NPhshhVX/pdfbox-app-150.html
    3. Use the following method to get the PDF contents:

    Public Function readPDFContents(strPdfFilePath As String) As String

            Dim strFileContents As String = ""

            Dim objPDFDoc As PDDocument = Nothing

            Dim objTextStripper As PDFTextStripper = Nothing

            Try

                objPDFDoc = PDDocument.load(strPdfFilePath)

                strFileContents = New PDFTextStripper().getText(objPDFDoc)

            Catch objException As Exception

                Throw New System.Exception("Unhandled exception while retrieving pdf contents. Exception Details: " + objException.Message + objException.StackTrace)

            Finally

                If (Not IsNothing(objPDFDoc)) Then

                    objPDFDoc.close()

                End If

            End Try

            Return strFileContents

        End Function

    Let me know if you face issues.

    Regards,

    Tushar Palande

    Wednesday, August 24, 2011 6:48 AM
  • Hi Franklin,

    Did the solution work for you ?

    It worked well for my PoC and would like to know your experience as well for the benefit of the community.

    Regards,

    Tushar Palande

    • Edited by Tushar P Wednesday, September 7, 2011 6:28 AM
    Wednesday, September 7, 2011 6:13 AM
  • Hi Tushar,

    Sorry for the late reply, I couldn't test your code in my application, I have assigned to work some other task, but I am sure about your code will get work. After I apply in coded UI application, I will update my experience.

    Thanks.

     

    M. Franklin Dennis

     

    Monday, September 19, 2011 9:10 AM