ComboBox SelectEvent fired twice

Sep 25, 2008 at 3:09 PM
Hi

I have a problem with a Select on a combobox. Obviously this fires the SelectedValueChanged Event in the target application twice, which unfortunately screws up the  logic in our apps UI. This behviour can also be easily reproduced using the UiSpy SelectionPattern.

Is there any solution or workaround?

Best Regards



Bernd Nierula
Coordinator
Sep 27, 2008 at 12:40 PM
When selecting Item in combobox, white first opens and closes the dropdown first without really selecting anything. It opens the dropdown again, selects the items (which closes the dropdown automatically). The first is to avoid one occasional UIAutomation bug.
Can you try this manually and see if this is what the problem is? White doesn't use the SelectionPattern for combobox.
Sep 30, 2008 at 9:43 PM
Hi viveksingh

Thank You for Your feedback. Unfortunately I'm very confused, because I have a small example, which doesn't work on my maschicne (WinXP SP2, VS2008 SP1, Framework 3.5 SP1)  but it works on the machines of two colleagues with apparently same configuration. The only visible diffrence is, that they run VS2008 developer Edition and I'm a poor man with VS2008 Pro. Can this make a diffrence in the behavior of White????

Can you please give me some hints, I have enclosed the example..

Thank You very much for your support

Best Regards

Bernd Nierula


... ComboBox definition ...

'
'ComboBox1
'
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Items.AddRange(New Object() {"a", "b", "c"})
Me.ComboBox1.Location = New System.Drawing.Point(92, 60)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(160, 21)
Me.ComboBox1.TabIndex = 0

'
' Test definition..
'
<TestMethod()> Public Sub TestMethod1()
Dim comboBoxControl As ListBoxItems.ComboBox = _testWindow.Get(Of ListBoxItems.ComboBox)("ComboBox1")
Assert.IsNotNull(comboBoxControl)        ' ok
comboBoxControl.Select("b")

 

Assert.IsTrue(comboBoxControl.SelectedItemText = "b")  ' Assertion failes

End Sub

 

Coordinator
Oct 2, 2008 at 11:24 AM
white depends on the .NET framework version and not Visual Studio. Is this version different on other machines where it works?
Can you download white sourcecode and try running unit tests related to combobox?
Oct 2, 2008 at 11:10 PM
Hi viveksingh

Thank You very much for Your reply. All the machines I tested run .NetFramework 3.5 SP1....

So I downloades the Source of 0.17. In the Core Modul I found some tests for comboboxes, see the result below...

Unfortunately the SelectTest fails....

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<test-results name="D:\Downloads\CodePlex\White\Source_Rel 0.17\WhiteLib\Core.dll" total="7" failures="4" not-run="0" date="2008-10-02" time="23:21:54">
  <environment nunit-version="2.4.2.0" clr-version="2.0.50727.3053" os-version="Microsoft Windows NT 5.1.2600 Service Pack 2" platform="Win32NT" cwd="D:\Downloads\CodePlex\White\Source_Rel 0.17" machine-name="GEOINFO2005" user="Geoinfo" user-domain="GEOINFO2005" />
  <culture-info current-culture="de-CH" current-uiculture="de-DE" />
  <test-suite name="D:\Downloads\CodePlex\White\Source_Rel 0.17\WhiteLib\Core.dll" success="False" time="24.188" asserts="0">
    <results>
      <test-suite name="Core" success="False" time="24.188" asserts="0">
        <results>
          <test-suite name="UIItems" success="False" time="24.188" asserts="0">
            <results>
              <test-suite name="ListBoxItems" success="False" time="24.094" asserts="0">
                <results>
                  <test-suite name="ComboBoxTest" success="False" time="19.734" asserts="1">
                    <results>
                      <test-case name="Core.UIItems.ListBoxItems.ComboBoxTest.GetItems" executed="True" success="True" time="0.359" asserts="3" />
                      <test-case name="Core.UIItems.ListBoxItems.ComboBoxTest.LaunchModalWindowOnIndexChange" executed="True" success="True" time="13.281" asserts="0" />
                      <test-case name="Core.UIItems.ListBoxItems.ComboBoxTest.Select" executed="True" success="False" time="0.703" asserts="1">
                        <failure>
                          <message><![CDATA[  Expected string length 13 but was 0. Strings differ at index 0.
  Expected: "Arundhati Roy"
  But was:  <string.Empty>
  -----------^
]]></message>
                          <stack-trace><![CDATA[   bei Core.UIItems.ListBoxItems.ComboBoxTest.Select() in D:\Downloads\CodePlex\White\Source_Rel 0.17\Core\UIItems\ListBoxItems\ComboBoxTest.cs:Zeile 39.
]]></stack-trace>
                        </failure>
                      </test-case>
                      <test-case name="Core.UIItems.ListBoxItems.ComboBoxTest.SelectAfterScroll" executed="True" success="False" time="0.516" asserts="0">
                        <failure>
                          <message><![CDATA[System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.]]></message>
                          <stack-trace><![CDATA[   bei Core.UIItems.ListBoxItems.ComboBoxTest.SelectAfterScroll() in D:\Downloads\CodePlex\White\Source_Rel 0.17\Core\UIItems\ListBoxItems\ComboBoxTest.cs:Zeile 49.
]]></stack-trace>
                        </failure>
                      </test-case>
                      <test-case name="Core.UIItems.ListBoxItems.ComboBoxTest.SelectItemHavingLongText" executed="True" success="False" time="0.250" asserts="0">
                        <failure>
                          <message><![CDATA[System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.]]></message>
                          <stack-trace><![CDATA[   bei Core.UIItems.ListBoxItems.ComboBoxTest.SelectItemHavingLongText() in D:\Downloads\CodePlex\White\Source_Rel 0.17\Core\UIItems\ListBoxItems\ComboBoxTest.cs:Zeile 56.
]]></stack-trace>
                        </failure>
                      </test-case>
                      <test-case name="Core.UIItems.ListBoxItems.ComboBoxTest.SetValue" executed="True" success="False" time="0.234" asserts="0">
                        <failure>
                          <message><![CDATA[System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.]]></message>
                          <stack-trace><![CDATA[   bei Core.UIItems.ListBoxItems.ComboBoxTest.SetValue() in D:\Downloads\CodePlex\White\Source_Rel 0.17\Core\UIItems\ListBoxItems\ComboBoxTest.cs:Zeile 63.
]]></stack-trace>
                        </failure>
                      </test-case>
                    </results>
                  </test-suite>
                  <test-suite name="WinFormComboBoxTest" success="True" time="4.297" asserts="0">
                    <results>
                      <test-case name="Core.UIItems.ListBoxItems.WinFormComboBoxTest.SetTextInComboBox" executed="True" success="True" time="2.938" asserts="1">
                        <categories>
                          <category name="WinForm" />
                        </categories>
                      </test-case>
                    </results>
                  </test-suite>
                </results>
              </test-suite>
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>
  </test-suite>
</test-results>

As an additional information I noticed when running the test in Debug-Mode an exception like

System.Windows.Automation.ElementNotAvailableException crossed a native/managed boundary
  Message="Eine Ausnahme vom Typ \"System.Windows.Automation.ElementNotAvailableException\" wurde ausgelöst."
  Source="UIAutomationClient"
  StackTrace:
       bei MS.Internal.Automation.HwndProxyElementProvider.System.Windows.Automation.Provider.IWindowProvider.WaitForInputIdle(Int32 milliseconds)

in the following method...

public virtual void WaitWhileBusy()

{

try

 

{

WindowPattern windowPattern = (WindowPattern) Pattern(WindowPattern.Pattern);

if (!CoreAppXmlConfiguration.Instance.InProc &&

!("ConsoleWindowClass".Equals(automationElement.Current.ClassName) ||

windowPattern.WaitForInputIdle(CoreAppXmlConfiguration.Instance.BusyTimeout)))

throw new Exception("Timeout occured" + Constants.BusyMessage);

Clock clock = new Clock(CoreAppXmlConfiguration.Instance.BusyTimeout, 0);

clock.RunWhile(delegate { Thread.Sleep(50); },

delegate { return windowPattern.Current.WindowInteractionState.Equals(WindowInteractionState.NotResponding); },

delegate
{
throw new UIActionException("Window didnt come out of WaitState" + Constants.BusyMessage + " last state known was " +windowPattern.Current.WindowInteractionState)
});
}
catch (Exception e)
if (!(e is InvalidOperationException || e is ElementNotAvailableException))
throw new UIActionException(string.Format("Window didn't respond" + Constants.BusyMessage), e);
}
}


I hope this information is helpful... By the way, is it possible, that I have an old version of the UIAutomation dlls?

Thank You very much for your support


Best Regards



Bernd Nierula

Coordinator
Oct 4, 2008 at 7:33 PM
I am sorry but I am at loss as to what is going wrong. There definitely something different on your machine which need to figure out.
What about the Regional and culture settings?