TestStack / White

DEPRECATED - no longer actively maintained
Other
1.02k stars 486 forks source link

ComboBox.Select(item) clicks multiple times in the same combobox #116

Closed alpha1983 closed 11 years ago

alpha1983 commented 11 years ago

Hello there, I've just updated an old working project to the latest version of White and found that whenever I was selecting an entry in a combobox the combobox would be clicked multiple times and then the entry would be selected. Not only that, if ComboBox.SelectedItemText is accessed the ComboBox will be clicked again. On the contrary, other attributes such as ComboBox.Enabled that in fact need to call the windows automation don't cause such behavior.

The code I'm using is this:

public bool SelectItemOnComboBox(String sItemName, String sComboIdentification) { // Variablen expandieren String expandedItemName = ExpandVariables(sItemName); _logger.Debug("SelectItem " + expandedItemName + " OnComboBox " + sComboIdentification);

// Combobox suchen
White.Core.UIItems.ListBoxItems.ComboBox comboBox = GetItem<ComboBox>(sComboIdentification, _selectedWindow);
if (comboBox == null)
{
    return false;
}

// Eintrag auswählen
comboBox.Select(expandedItemName);

// Prüfen, ob der richtige Eintrag ausgewählt wurde
string justForTest = comboBox.SelectedItemText;
if (comboBox.SelectedItemText != expandedItemName)
{
    _logger.Warn("Could not select " + expandedItemName + " on combo box " + sComboIdentification + " the entry " + justForTest +" was selected instead!");
    return false;
}
return true;

}

So, this code should only click and open the combobox once, in comboBox.Select, but in fact it opens it five times. Three times in the ComboBox.Select and once every time ComboBox.SelectedItemText is accessed.

The other code you might be interested is the Get method I'm using to retrieve the Combobox:

private T GetItem(String anIdentification, Window aWindow) where T : UIItem { if (!Asserts.StringNotEmpty(anIdentification)) { return null; } if (!Asserts.WindowNotEmpty(aWindow)) { return null; } // Falls es sich um einen Resource-Namen handelt, z.B. IDC_STRING anIdentification = ResolveResourceNameToId(anIdentification); _logger.Debug("Looking for an identification " + anIdentification); T oUIItem = null; bool bControlFound = false; try { oUIItem = (T)aWindow.Get(SearchCriteria.ByAutomationId(anIdentification).AndControlType(typeof(T), aWindow.Framework), _tGetControlWaitTime); bControlFound = true; } catch (White.Core.AutomationException) { _logger.Debug("Could not find control by identification " + anIdentification + " now trying with text"); } catch (White.Core.WhiteException eWhiteException) { _logger.Error("Exception raised while trying to find control with identification " + anIdentification + " details " + eWhiteException.StackTrace); return null; } if (!bControlFound) { _logger.Debug("Looking for an identification by text " + anIdentification); try { oUIItem = (T) aWindow.Get(SearchCriteria.ByText(anIdentification).AndControlType(typeof(T), aWindow.Framework), _tGetControlWaitTime); } catch (White.Core.AutomationException) { _logger.Warn("Could not find " + typeof(T) + " with identification " + anIdentification + " on window " + aWindow.Name + "!"); return null; } catch (White.Core.WhiteException eWhiteException) { _logger.Error("Exception raised while trying to find control with identification " + anIdentification + " details " + eWhiteException.StackTrace); return null; } } _logger.Debug("Found ID" + oUIItem.Id + " with type " + oUIItem.ToString()); return oUIItem; }

The software I'm using for the tests is: Fitnesse version 20130530 (latest version) Fitsharp version 2.2 .Net 4.0 build White latest unmodified sources from the git repository I have tested this in two different virtual machines. First one run under Windows XP SP3 32 bits and the second one in Windows7 64bits.

Thanks in advance and congratulations for the good work! Unai

JakeGinnivan commented 11 years ago

Hey,

Unfortunately this is going to be a reality. This works around WPF selection issues and virtualisation issues. When I try to reduce the number of clicks, Whites UI tests start failing.

I hope to make this better once White upgrades to the UIA Com Wrapper. If you manage to improve the combobox selection, please submit a pull request