Reputation: 381
How to check operations like Greater Than, Less Than while doing CodedUI Testing using Assert Function?
I am working on Visual Studio 2010 Ultimate.
Upvotes: 1
Views: 51
Reputation: 3139
You can add any other custom assertion you want by customizing the code. Follow following steps
First Add any assertion on your property and generate code for Validation Method.
Move the Validation Method to UIMap.cs from UIMap.Designer.cs
Now Customize the code in UIMap.cs in the Validation Method. Here is an example:
/// <summary>
/// Verifies that the result count is > the min value passed.
/// </summary>
public void VerifyMinimumResultCount(int minResultCount)
{
HtmlSpan totalResults =
this.ApplicationWindow.
IntermediateParent.TotalResultsTextBox;
// Use regular expression to get the text out of the
// Control Property.
int actualResultCount;
Match resultPattern = Regex.Match(totalResults.Text,
"[0-9]+-[0-9]+ of ([0-9,]*) results");
Assert.IsTrue(resultPattern.Success,
"Regular expression match failed");
Assert.IsTrue(int.TryParse(resultPattern.Groups[1].Value,
NumberStyles.Number,
CultureInfo.CurrentCulture,
out actualResultCount),
"Parsing failed");
Assert.IsTrue(actualResultCount >= minResultCount,
"Got less than expected min result");
}
Or you can use the AssertTrue :
//...
int expectedValueLimit = 2;
int actualValue = int.Parse(myUiControl.text);
Assert.IsTrue((actualValue > expectedValueLimit), "myUiControl value is less than " + expectedValueLimit);
//...
Upvotes: 1