Friday 2 September 2011

CodedUI Testing Automation - Assertions for Values that Change

I've found a few situations during testing where I have the need to place assertions on values that are always changing, for example during one of my tests I sell inventory products and need to verify that the quantity in the inventory reduces after the sale is processed. This is pretty easy to do, first I open my inventory item and get the quantity value from a display text property, then convert it to an integer.

UIMap.OpenInventoryModule();
UIMap.OpenInventoryItem();
int origSkuQty = Convert.ToInt32(UIMap.UIWindow.UIInStockCustom.UIItemText.DisplayText);

For this to work i've dropped the CodedUI assertion picker on the DisplayText property of my inventory item and added this to my UIMap to call during the test.

After my sale I perform the same inventory check and verify that the DisplayText int is now the origSkuQty - 1