I use SpecFlow with Coded UI to create some automated functional tests for a WPF application.
Let's see the following SpecFlow scenario:
Scenario: Issue
When Results button is pressed
When Result 123 is selected
When Results button is pressed
When Result 123 is selected
1st and 3rd row parameter: Results
2nd and 4th row parameter: 123
Here are the methods for the upper mentioned steps:
When Results button is pressed
public void PressButton(string buttonName)
{
WpfButton uIButton = this.UIAUT.UIButton;
uIButton.SearchProperties[WpfButton.PropertyNames.Name] = buttonName;
uIButton.WaitForControlEnabled();
Mouse.Click(uIButton);
}
When Result 123 is selected
public void SelectResultByID(string resultId)
{
WpfListItem uIResult = this.UIAUT.UITier1List.UITier2ListBox.UITier3ListItem;
var allResults = uIResult.FindMatchingControls();
foreach (WpfListItem item in allResults)
{
string[] elem = item.GetChildren().GetNamesOfControls();
if (elem[0] == resultID)
{
Mouse.Click(item);
}
}
}
The first three rows are OK. When the 4th step When Result 123 is selected
is executed again var allResults = uIResult.FindMatchingControls();
is empty so the foreach
part is skipped, no action is taken and the test is passed.
Could someone tell me what is wrong? It is obvious that I miss something.
Assuming you code is generated by recording (or is similar) then I would suspect the "cacheing" nature of the higher level UI Controls. The application may draw one UI Control containing the first 123
and draw another UI Control for the second 123
. These controls look identical but are different and have different window-ids (or handles or whatever). One of the UI Controls in
WpfListItem uIResult = this.UIAUT.UITier1List.UITier2ListBox.UITier3ListItem;
probably refers to the UI Control of the first 123
even though it is no longer on display. I suspect UITier3ListItem
or its child controls; if it were ...1...
or ...2...
then I would expect a failure message rather than zero matches.