Created On:  24 June 2010

Problem:

Is it possible to verify that a controls visual appearence matches a bitmap stored on disk?

Resolution:

At present no Silk4J class provides a method to verify that a controls visual appearence matches a bitmap file stored on disc. This article provides a zipped JAR file containing a utility class with methods that allow a user to perform some basic bitmap comparisons. The methods provided are as follows:


boolean compareBitmaps(String sSourceBitmap, String sCompare, boolean bOutputDiff)

boolean wait4Bitmap(TestObject window, String sSourceBitmap, long nTimeout)

boolean verifyBitmap(TestObject window, String sSource)



The "compareBitmaps" method allows a user to compare 2 bitmap files stored on disk. The argument "sSourceBitmap" accepts a string with the path to the source bitmap, "sCompare" accepts a string with a path to the bitmap to be used for comparison. The argument "bOutputDiff" if set to true, will create a bitmap highlighting the differences between both bitmaps in the same directory as "sCompare". The said method can used in a statement such as the following:


boolean bMatch = com.mf.support.Utilities.compareBitmaps("C:\\Source.bmp","C:\\Compare.bmp",true);



The "wait4Bitmap" method will cause Silk4J execution to wait "nTimeout" milliseconds, for a controls visual appearence to match that of a bitmap file stored on disk. A boolean value will be returned indicating if the controls visual appearence matched the source bitmap at any time during the timeout. The said method can used in a statement such as the following:


boolean bMatch = com.mf.support.Utilities.wait4Bitmap(desktop.find("FormsWindow[@caption='My App']"), "C:\\Source.bmp", 15000);



The "verifyBitmap" method will return a boolean value with the result of comparing a controls visual appearence to that of a bitmap stored on disk. The said method can used in a statement such as the following:


boolean bMatch = com.mf.support.Utilities.verifyBitmap(desktop.find("FormsWindow[@caption='My App']"), "C:\\Source.bmp");



The said methods execute locally, i.e. not on the Open Agent. Therefore should you be executing tests against a remote agent it will not be possible to use the methods provided in the utility class.