Forum Discussion

BMD's avatar
BMD
Contributor
3 years ago

Comparing part of a .pdf with a Store.Region

Team,

I have a Store.Region of an image of a .pdf that looks like:

and I have a generated .pdf from my web application that looks like:

I'm trying to verify that the Logo is found on the .pdf and have tried all different kinds of:

 

With FindRegion is the StarsLogo found in the Sys.Process("Acrobat")

LogoFound2 = Regions.FindRegion(Regions.StarsLogo, Sys.Process("Acrobat"));

- returned "Cannot get a picture object from the input parameter."

 

I took a second image of the logo just to see if TC could compare two Store.Regions

Pict3 = Regions.StarsLogo2;
LogoFound1 = Regions.StarsLogo.Check(Pict3, false, false, 1, 1);

- returned "The region checkpoint "StarsLogo" failed. See Details for additional information." and Details is "Cannot get a picture object from the input parameter.".  

 
I'm beginning to believe that TC can't actually do a compare of two images even if they are the same.
At least TC can't compare a stored image to any part of an opened adobe .pdf.
Any pointers (even wrong ones) to help me find the solution are welcome.
Thank you, BMD

5 Replies

  • I do not agree that "Region Checkpoint" does not work, look at my screenshots I made specifically for you.

    I want to immediately note that for correct work you need a license for "Intelligent Quality Add-On".

     

    1. add region checkpoint to test2. select window region in pdf3. auto generated checkpoint with coordinates4. result

    • BMD's avatar
      BMD
      Contributor

      So can you region a small part of any .pdf that you have on your network and save that small part in TC as a store, and script (we use JavaScript) opening the same .pdf and comparing the small part of the .pdf that is in the TC store to the opened full .pdf document and get a pass?  Then open a different .pdf and get a failure? 

      This is my objective and what I can't seems to get to work.

      I did this instead.

      var ManualResults = UserForms.ManualStarsLogoImageCheck.ShowModal();
      if ( ManualResults == 6 ) /*Success */
      {
      Log.Message("AR9 meets ER9 'PASS' - The PDF will have a title of 'Checklist'");
      ProjectSuite.Variables.ARcount++;
      }
      else if ( ManualResults == 2 ) /*View Log */
      {
      Log.Warning("AR9 COULD meet ER9 'WARNING' – Unable top verify that the PDF HAD a title of 'Checklist'");
      ProjectSuite.Variables.ERRORcount++;
      }
      else if ( ManualResults == 7 ) /*Failure */
      {
      Log.Error("AR9 did NOT meet ER9 'FAILED' - The PDF DID NOT have a title of 'Checklist'");
      ProjectSuite.Variables.ERRORcount++;
      }
      else
      {
      Log.Error("The ManualResults value was not set by the UserForms.ManualReportImageCheck.ShowModal.");
      }

       

      Thank you, BMD

      • hkim5's avatar
        hkim5
        Staff

        A_Roskoshnyi I stand corrected! thank you for the clarification

         

        BMD ,  it looks like the solution above is using Regions.YOURPICTURE.Check() method to check precisely within the prescribed coordinates of your open pdf doc to find the region as described. This will behave as a checkpoint and fail your tests if it does not find it within that region. 

        While the solution above is using a Keyword test, you can follow the steps shown in the screenshots and right-click convert to script the KDT to get your javascript sample. 

         

        Another option would be to use the Regions.Find() method. In this case, you will describe a picture to search in (the open pdf page in question) and the picture you want to find (the logo you stored in the Stores.Region test item). I work the fastest in python so heres my sample (but the syntax should be similar so you can convert most of it into javascript if needed):

         

         

        def Test3():
            #assuming you have the pdf you want to check open on screen, and the "pdf" variable below is referring to that on screen element
            
            pdf = Aliases.AcroRd32.wndAcrobatSDIWindow.AVFlipContainerView.AVDocumentMainView.AVFlipContainerView.AVSplitterView.AVSplitationPageView.AVSplitterView.AVScrolledPageView.AVScrollView.AVPageView
            #param1 = picture to search in (in my case entire page of PDF on my screen, aka variable called pdf
            #param2 = picture to search for (within the above pdf, aka the logo stored in my Stores-region item as "Logo")
            rect = Regions.Find(pdf, "Logo")
            if rect != None:
              x = rect.Left
              y = rect.Top
              width = rect.Width
              height = rect.Height
              pic = pdf.Picture(x,y,width,height)
              Log.Picture(pic, "found this image of the Logo")
            else:
              Log.Error("could not find the logo in your pdf")

         

         

        the resulting logs will show you:

         

        One final note is that if you change the DPI or resolution of the monitor that the test is created on vs the test being run on, this test will break (which is just the nature of using a pixel based Region method).

        Otherwise, hope this helps, and once again, thanks A_Roskoshnyi !

         

         

  • your assumptions are correct

    TC cannot compare images via the Regions comparison using stores objects on images on PDFs

    TC can only compare images using the methods you are using when TC can recognize the images as an object themselves

    At this time I am not aware of any other workarounds - the closest thing that you could potentially do is check the string value of your logo using an OCR checkpoint.