New to Telerik Test Studio? Download free 30-day trial

Data Driven Image Verification

To data bind an image verification step, certain actions have to be performed. One possible approach to this scenario involves the following steps:

  1. Create a histogram of the image element.

  2. Bind the verification step to the histogram.

  3. Perform the verification in a coded step as demonstrated below:

// get an image of MyImage element        
System.Drawing.Bitmap bitmap = Pages.MyPage.MyImage.Capture();

// create a histogram to compare
ArtOfTest.Common.Histogram histogram = ArtOfTest.Common.Histogram.FromBitmap(bitmap);
// create Histogram to place original data inside
ArtOfTest.Common.Histogram histogramToCompare = ArtOfTest.Common.Histogram.FromBitmap(bitmap);

// place data from Data Source to a string array
var stringHistogram = Data["Histogram"].ToString().Split(',');

// place original data in the Histogram object
for (int i=0; i < histogram.Data.Length; i++)
{
    histogramToCompare.Data[i] = Double.Parse(stringHistogram[i]);
}
// compare histogram objects
double compareValue = (histogram.Compare(histogramToCompare) * 100);

// set tolerans in %
double tolerance = 10D;

// Assert statement 
ArtOfTest.Common.UnitTesting.Assert.IsTrue(tolerance >= compareValue); 

Dim bitmap As System.Drawing.Bitmap = Pages.MyPage.MyImage.Capture()

Dim histogram As ArtOfTest.Common.Histogram = ArtOfTest.Common.Histogram.FromBitmap(bitmap)

Dim histogramToCompare As ArtOfTest.Common.Histogram = ArtOfTest.Common.Histogram.FromBitmap(bitmap)

Dim stringHistogram = Data("Histogram").ToString().Split(","C)

For i As Integer = 0 To histogram.Data.Length - 1
    histogramToCompare.Data(i) = [Double].Parse(stringHistogram(i))
Next

Dim compareValue As Double = (histogram.Compare(histogramToCompare) * 100)

Dim tolerance As Double = 10.0

ArtOfTest.Common.UnitTesting.Assert.IsTrue(tolerance >= compareValue)

To complete this scenario using the provided sample:

  • System.Drawings .NET assembly must have a reference in the project.
  • The test script must be bound to a data source with a Histogram column.
  • The image histogram data must be formatted as a single line string in the data storage cell. For a histogram example - one is created if an image verification step is recorded in the test script .tstest file
In this article
Not finding the help you need? Improve this article