1
votes

While automating testing of a website shopping experience, I am attempting to verify that the subtotal, total, and tax are calculating properly. Since the price and/or tax will change in the future, I cannot simply assert the actual price value inside the control. Instead, I would need to build a calculation based upon the controls themselves and assert that quantity multiplied by individual price for each item added together equals the subtotal, and so on.

For example, say my controls for each are named such (control names are in asterisks):

 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)

Instead of validating the values are the actual numbers, can I write an assertion formula using the identifiers as variables?

Keep in mind, I am using the Coded UI Test Builder rather than writing the code outright.

If the Individual Product Total InnerText assertion comparator is AreEqual, can the Comparison Value be something like:

 UIItem2Cell-InnerText * UIItem249Pane-DisplayText

A. Is this sort of formula possible?

B. If so, how do I write it?

(Please forgive me, as I am very green when it comes to this.)

1

1 Answers

0
votes

You most certainly can. First off in your app itself it would be greatly useful to use IDs on your controls so you can match on just that criteria. that way your not using calculated values for search criteria.

Now as is in your question you will need to pull those values from the cells, calculate the Value and use it in your 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);