New to Telerik Test Studio? Start a 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:
-
Create a histogram of the image element.
-
Bind the verification step to the histogram.
-
Perform the verification in a coded step as demonstrated below:
C#
// 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); 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