Visual Studio 2012 - 编码的UI测试生成器:断言公式?

时间:2015-07-21 20:30:55

标签: visual-studio-2012 coded-ui-tests assert assertion

在自动测试网站购物体验的同时,我试图验证小计,总计和税金是否正确计算。由于价格和/或税将在未来发生变化,我不能简单地断言控制中的实际价格值。相反,我需要根据控件本身构建一个计算,并声明数量乘以加在一起的每个项目的单个价格等于小计,依此类推。

例如,假设我的每个控件都是这样命名的(控件名称是星号):

 Quantity = *UIItem2Cell*
 (InnerText has a Value of 2)

 Individual Price = *UIItem249Pane*
 (DisplayText has a value of 2.49)

 Individual Product Total (price x qty) = *UIItem498Pane*
 (InnerText has a Value of 4.98)

我可以使用标识符作为变量编写断言公式,而不是验证值是实际数字吗?

请记住,我使用的是Coded UI测试生成器,而不是直接编写代码。

如果Individual Product Total InnerText断言比较器是AreEqual,则比较值可以是:

 UIItem2Cell-InnerText * UIItem249Pane-DisplayText

一个。这种公式可能吗?

B中。如果是这样,我该怎么写呢?

(请原谅我,因为我对此非常环保。)

1 个答案:

答案 0 :(得分:0)

你当然可以。首先,在您的应用中,在控件上使用IDs非常有用,这样您就可以匹配该条件。这样你就不会使用搜索条件的计算值。

现在,就像你的问题一样,你需要从单元格中提取这些值,计算Value并在Search Criteria中使用它

// I'd recommend trimming text values: 
// depending on how tables and such are rendered you'll have extra white-space characters
var firstValue = Double.Parse(UIItem2Cell.InnerText.Trim());
var secondValue = Double.Parse(UIItem249Pane.DisplayText.Trim());
var calculatedValue = string.Format("{0,N2}%", firstValue * secondValue);

// assuming your in a web app
var totalDiv = new HtmlDiv(currentHtmlDoc);
totalDiv.SearchProperties.Add(new PropertyExpression(HtmlDiv.PropertyNames.InnerText, calculatedValue, PropertyExpressionOperator.Contains));
Assert.IsTrue(totalDiv.TryFind());
SringAssert.Contains(totalDiv.InnerText,calculatedValue);