New to Telerik Test Studio Dev EditionStart a free 30-day trial

Data Driven Image Verification

To data bind an image verification step certain actions have to be performed. An approach to this scenario is to have previously stored histograms of the image element to which verification should be bonded. Then in a coded step the verification has to be managed as it is given in the sample 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 has to be referenced in the project
  • test script has to be data-bound to a data source with Histogram column
  • image histogram data has to be placed 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
Not finding the help you need?
Contact Support