Forum Discussion

ajitkumar163's avatar
ajitkumar163
Occasional Contributor
11 years ago

Finding one Image inside other image is Failing

Hi,



While finding an image inside another image the script is getting failed.

Steps to reproduce



1> I saved an image in the desktop and copied the same image in the Regions folder under Store(store/regions) of testcomplete



Dim picture1,pict,w,win

sub testdesktop()

 set win=Aliases.explorer.Window("CabinetWClass", "Desktop", 1)

 win.Maximize

 win.Activate

 Set w = Sys.Desktop.ActiveWindow '.Picture()

 Set picture1 = w.Picture

 log.Picture(picture1)

 

' Loads the sought-for image

  Set pict = Utils.Picture

  pict.LoadFromFile(ProjectSuite.Path&"TestProject1\Stores\Regions\pic1.png")

 

  Set rect = picture1.Find(pict)

 

  If rect Is Nothing Then

    Call Log.Warning("The image was not found.")

    Exit Sub

      else

   log.Message "required image was found"  

  End If

 

  win.Restore

 

end sub



While running the above program the control always goes to the "Image was not found".I took help of http://support.smartbear.com/viewarticle/57040/.



NOTE: While I am trying to find the image saved in Store/regions inside the webpage,the same scenario works for me, below is the program



Public Function Find_Picture_Program(URL,ImageName)

  'Dim url, page, picture, pict, rect, img, x, y



  ' Launches the web browser and opens the web page

  Browsers.Item(btIexplorer).Run(URL)

  Set page = Sys.Browser.Page("*")



  ' Obtains the image of the browser window

  Set picture = page.PagePicture

 

  ' Loads the sought-for image

  Set pict = Utils.Picture

  pict.LoadFromFile(ProjectSuite.Path&"TestProject1\Stores\Regions\"&ImageName)



'  ' Loads the sought-for image

'  Set pict = Utils.Picture

'  pict.LoadFromFile("D:\googlepageImage.png")



  ' Searches for the image within the browser window

  Set rect = picture.Find(pict)

  If rect Is Nothing Then

    Call Log.Warning("The image was not found on the page.")

    Exit Function

    else

   log.Message "required image was found with in the Web Page"  

  End If



End Function





I have attached the image which I used.

Requesting to provide the solution to the above problem.Plase ignore the other thread which I have created under the testcomplete developers forum.



Thanks,

Ajit

3 Replies

  • Not sure why your comparisons are failing. As mentioned above, image compares are notoriously fickle.



    But one thing I will add, is where you are capturing a screenshot of a webpage .... you are not controlling the size of the browser. If someone manually re-sizes the browser, it may well open at that size the next time your test starts a browser.



    So I would suggest you add some extra code to control the browser size. It can be a problem causing visibility failures and accessing controls. But for image compares, in my book, controlling the browser size if pretty much essential if you want accurate results. All my scripted tests open browsers of very specific sizes so I always know what I'm dealing with during a run.



    (Note - the way you control the size of IE vs Chrome in code - VBScript in my case - is different. So you'll need to know the browser in use and apply the sizing code to each accordingly. No idea about FireFox, I don't use that at work.)
    • ajitkumar163's avatar
      ajitkumar163
      Occasional Contributor

      Hi Colin,

       

      Thanks for your useful comments,In my application there is one option to Control the size of the Image to search for.After increasing the size of the image this test is working fine for me.I guess the test was getting failed due the very small size of that Image to search for.I used

      "Regions.FindRegion(PictureToSearchForPictureToSearchInLeftTopTransparentMousePixelTolerance)" to find the required Image.

       

      Thanks,

      Ajit

       

       

  • There are a lot of variables in play when comparing images. The Find method takes many more parameters than what you are providing. You might want to include something for the pixel tolerance, make sure the mouse isn't included, and possibly a color tolerance. Resolution differences can make a difference (between the saved image and the newly rendered image).



     http://support.smartbear.com/viewarticle/55152/



    That page also has helpful links to Why image comparisons fail and Factors affecting image comparison