2015-07-21 77 views
1

在自动测试网站购物体验时,我试图验证小计,总计和税金是否正确计算。由于价格和/或税收将在未来发生变化,因此我不能简单地声明控制权内的实际价格值。相反,我需要根据控制自身进行计算,并声明数量乘以每个项目加在一起的单个价格等于小计,等等。Visual Studio 2012 - 编码的UI测试生成器:断言公式?

例如,说我的每一个控件被命名为这样的(控制名称是星号):

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) 

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

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

如果个别产品总的innerText断言比较是AreEqual,可以比较值是这样的:

UIItem2Cell-InnerText * UIItem249Pane-DisplayText 

A.是这种配方的可能?

B.如果是的话,我该怎么写呢?

(请原谅我,因为我很绿色,当谈到这一点)。

回答

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); 
相关问题