Forum Discussion

ankit05gupta1's avatar
Occasional Contributor
7 years ago

Image comparison failling

I have a test script to compare the two images. I tried with both methods (Regions checkpoint & Compare) for the image comparison. But none of them worked for me.


I have attached the TestComplete sample script to do image comparison on Sample Order application. Please suggest, what might be causing this?




Ankit Gupta

3 Replies

  • tristaanogre's avatar
    Esteemed Contributor

    One of the drawbacks of image comparison is that, depending upon the image, etc., and the settings you are using to make the comparison, all it takes is 1 pixel different to cause a failed checkpoint.  It's why I generally avoid image comparisons unless absolutely necessary.


    Rather than giving us the sample project that every TestCOmplete installation comes with... could you post


    1) The code you're using to execute

    2) Screenshots showing the two images being compared

    3) Screenshots of your log showing the differences.

    • jab4743's avatar

      Depending on your issue:

      By using a combination of Get_Host_Name, determining if the screen is in landscape or portrait mode,  Regions.Contains,  Regions.CreateRegionInfo, and Regions.Check methods,  you can create image compares that run reliably on any machine.   You need to create a unique region / image name for each image (I have one method I call from anywhere in the project that creates my unique and dynamic image name for every image).  You check if that image already exists in the regions store.  If it does you know the test already ran on this machine (and assume already ran on this resolution) if not - you add a new image to the regions store with a new unique name. Once you have the image in the regions store - you just do a Regions Check (and again - I have one method I can call from anywhere in the project that does the region check) and you are done. 

      Things to be careful with - the very first time you run the Regions.CreateRegionInfo step on a new machine - make sure the region image you are capturing is correct.  Currently, in my scripts I assume the image is always in the same place. I am also currently looking at the Pict.Find method which - if it works - would eliminate the need to assume the image I am checking is in the same place.  If Pict.Find works, I can just take an image of the whole screen - search for the image of - say a button I want to click - and then use the ImageSetItem.Click method to click the button.  If that works I won't have to worry if an image moves - as long as the resolution on the machine stays the same. The applications I test tend not to change images/resolutions that often - this code has worked and continues to work after almost a year without the need to update the script.  (The region store tends to contain vast numbers of images - but this isn't an issue for my tests).  While the test doesn't run slow - speed isn't a issue on these legacy applications.

      • jab4743's avatar

        Code sample to checkpoint a region name stored in a variable:  create a variable to hold the region name - for example - regionpanelname (for an existing regions item in the stores)


        set tempregion = Regions.Items(regionpanelname)


        compareresultsc = tempregion.Check(Regions.CreateRegionInfo(Aliases.anyapp.frmMain.SplitContainer1.SplitterPanel.anyapp2.pnlWord.formxxDocxCompatibilityM.panel.panelStartupDocx.panelMicrosoftWordDocument, 298, 138, 166, 26, False), False, False, 0, 0) 


        this will compare the region created by regions.createregioninfo section to the image stored in regions under the name that is in the regionpanelname variable.


        compareresultsc will hold the Boolean true/false depending on if the images match.

        You can now run this on every machine with the same resolution if you make the regionpanelname variable contain details on resolution or machine name .....