如何在使用Assert Function进行CodedUI测试时检查大于,小于等操作?
我正在开发Visual Studio 2010 Ultimate。
答案 0 :(得分:1)
您可以通过自定义代码添加所需的任何其他自定义断言。请遵循以下步骤
首先在您的属性上添加任何断言并为验证方法生成代码。
将验证方法从UIMap.Designer.cs移至UIMap.cs
现在在验证方法中自定义UIMap.cs中的代码。这是一个例子:
/// <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");
}
或者您可以使用AssertTrue:
//...
int expectedValueLimit = 2;
int actualValue = int.Parse(myUiControl.text);
Assert.IsTrue((actualValue > expectedValueLimit), "myUiControl value is less than " + expectedValueLimit);
//...