Button not getting clicked

Jul 31, 2011 at 1:27 AM

I'm having problems getting a button to be clicked. My simple app comes up fine, I am then able to enter text into a textbox, but the button click never seems to happen. I've read several other threads here about similar problems. I have updated the BusyTimeout to 10000ms with no changes. Perhaps I don't have the app.config in the correct place? It is in the root directory of my test application (which is what calls into White)... When I run it I see the msg boxes from the calling code, but the msg box from the app under test never fires. The app under tests works as expected when I run it by itself.

relevant code snippets are below.

thanks!

daniel

 

Calling Code:

         TextBox fileName = s_Window.Get<TextBox>("m_fileName");
         fileName.SetValue(s_SettingsXmlPath);

         Button selectButton = s_Window.Get<Button>("m_selectFileNameButton");
         if (selectButton != null)
         {
            System.Windows.MessageBox.Show("about to click it");
            selectButton.Click();

            Window theWin = s_Window.ModalWindow("foowin");
         }

 

snippets from app under test:

xaml:

        <TextBox Name="m_fileName" Grid.Row="1"></TextBox>
        <Button Name ="m_selectFileNameButton" Grid.Row="2" Click="OnSelect">Select</Button>

codebehind:

      private void OnSelect(object sender, RoutedEventArgs e)
      {
         MessageBox.Show("Just clicked select button");

         m_window = new Window();
         m_window.Title = "foowin";
         m_window.ShowDialog();

       ...

       }

Aug 1, 2011 at 5:48 AM

In your codebehind, shouldn't the event handler for button click be

private void OnClick(object sender, RoutedEventArgs e)

rather than

private void OnSelect(object sender, RoutedEventArgs e)

I'm not a developer though :-)

Aug 1, 2011 at 7:03 AM

Some more information please :)

OS (x64/x86)

is the button not null?

Aug 1, 2011 at 7:10 PM

My comp is 64bit Windows 7, but I am compiling as x86.

Yes the button is not null. I have a msg box that fires after the check for null and right before the call to Click(). I get the msg-box and then nothing. No error.

Aug 1, 2011 at 7:13 PM

using .Net 4, if that makes a difference...

Aug 1, 2011 at 10:51 PM

Loganathan: the xaml sets the click handler to be "OnSelect". The app works fine by itself, just not when I'm trying to use White to do it. I do appreciate your input. I wish it was as simple as your proposal... :-)

Aug 2, 2011 at 1:30 AM

I'll be online this eve until late if that helps for us to be able to go back and forth quickly. Thanks again for you help.

Aug 2, 2011 at 8:25 AM

what do you use to execute the tests?

if Nunit, than use the x86 version in the bin folder, instead of the normal version.

 

but maybe there is an other problem, has the button focus ? than try to press enter on the keyboard object found on the window object.

it's only a workaround, but may help.

 

Other Reason maybe you are to fast an the button is not ready to use in the moment, you can try to implement a wait for button is enabled an visible..

 

Have a look in UIAVerify (you can find on codeplex). Which Pattern are available for the button?

 

Throndorin

Aug 2, 2011 at 9:49 AM
Edited Aug 2, 2011 at 9:00 PM
I am using NUnit to run the tests. I don't have my work env in front of me now, so not sure if I am using the x86
version or not. The button never seems to get focus. I know that if I click it manually while the test is running it will proceed as expected. As far as timing goes, I have put some waits in there, but it doesn't seem to do anything. Could it have anything to do with using .Net 4? I read somewhere in the docs that .Net 4 wasn't fully supported, but I'm just using basic stuff, so I didn't figure it would matter.
I'll check out UIAVerify in the morning when I get to work. Gotta go to bed now... :-)
Thank you for your help.
- daniel

 

Aug 2, 2011 at 10:02 AM

.Net4 should not be the problem our development is also in .Net4.0

 

The most knowing problem with such things is x64 OS bug, because the calculated points are not correct and the click goes to nirvana :)

so woerkaround is: build tests for x86 and use C:\Program Files (x86)\NUnit 2.x.x\bin\net-2.0\nunit-x86.exe to execute tests, fixes this problem.

 

sleep  well :) ;

 

Throndorin

Coordinator
Aug 2, 2011 at 10:06 AM

New version of white 0.21 released yesterday fixes this on 64 bit. Please check the release notes

Aug 2, 2011 at 9:02 PM

I will get the new version and see if that helps. If not, I will try out the x86 version of nUnit. I'll let you guys know how it goes later today.

Thanks for all of your help!

Daniel

Aug 3, 2011 at 3:11 AM

Wasn't able to get to this today. I'll be on it first thing in the morning and let you guys know how it goes.

Aug 3, 2011 at 11:43 PM

Some success, another problem related to Click()...

I installed White 0.21 and experience similar but different problems. I started using the x86 version of nUnit and it fixes it.

The new problem:

The effect of clicking the button is that a new Window is created by the app under test. This window comes up just fine, 5 seconds go by and then I get the following error and the test fails.

BDDSpecs.InPlacedEditingOfInkConfigFileFeature.OpenFile:
Bricks.BricksException : Error invoking Button.Click
  ----> White.Core.UIItems.UIActionException : Window in still wait mode. Cursor: 65543, after waiting for 5000 ms

I added some debugging code and can see that the code for the click handler runs to completion and presumably returns. However, the call to Click() does not return.

 

I noticed this in the documentation on "Wait Handling":

1. When any action is performed white automatically waits till the window can respond again to next action.

 

I wonder if that might be related to the problem...

Aug 3, 2011 at 11:43 PM

Stack Trace of above error:

at Bricks.RuntimeFramework.ReflectedObject.Invoke(MethodInfo methodInfo, Object[] arguments) in D:\projects\bricks-toolkit\Bricks.RuntimeFramework\ReflectedObject.cs:line 69
at Bricks.DynamicProxy.DynamicProxyInterceptors.Process(IInvocation invocation, InterceptContext interceptedContext) in D:\projects\bricks-toolkit\Bricks\DynamicProxy\DynamicProxyInterceptors.cs:line 20
at White.Core.Interceptors.CoreInterceptor.Intercept(IInvocation invocation) in c:\white\Components\Core\Source\Interceptors\CoreInterceptor.cs:line 30
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.ButtonProxy.Click()
at BDDSpecs.InPlaceEditorSteps.WhenIEnterTheFilesystemPathToASettings_XmlFile() in D:\dgs-sprint6\Sprint_6\DAWizard\BDDSpecs\InPlaceEditorSteps.cs:line 66
at lambda_method(Closure )
at TechTalk.SpecFlow.Bindings.MethodBinding.InvokeAction(Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.TestRunner.ExecuteStepMatch(BindingMatch match, Object[] arguments)
at TechTalk.SpecFlow.TestRunner.ExecuteStep(StepArgs stepArgs)
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
at BDDSpecs.InPlacedEditingOfInkConfigFileFeature.OpenFile() in d:\dgs-sprint6\Sprint_6\DAWizard\BDDSpecs\InPlaceEditor.feature:line 9
--UIActionException
at White.Core.UIItems.Actions.Action.<Handle>b__2() in c:\white\Components\Core\Source\UIItems\Actions\Action.cs:line 35
at Bricks.Core.Clock.Perform(Do do, Matched matched, Expired expired) in D:\projects\bricks-toolkit\Bricks\Core\Clock.cs:line 44
at White.Core.UIItems.Actions.Action.Handle(Window window) in c:\white\Components\Core\Source\UIItems\Actions\Action.cs:line 36
at White.Core.UIItems.WindowItems.Window.ActionPerformed(Action action) in c:\white\Components\Core\Source\UIItems\WindowItems\Window.cs:line 185
at White.Core.InputDevices.Mouse.ActionPerformed(ActionListener actionListener) in c:\white\Components\Core\Source\InputDevices\Mouse.cs:line 166
at White.Core.InputDevices.Mouse.Click(Point point, ActionListener actionListener) in c:\white\Components\Core\Source\InputDevices\Mouse.cs:line 161
at White.Core.UIItems.UIItem.PerformClick() in c:\white\Components\Core\Source\UIItems\UIItem.cs:line 222
at White.Core.UIItems.UIItem.Click() in c:\white\Components\Core\Source\UIItems\UIItem.cs:line 216

Aug 4, 2011 at 12:18 AM

One other note, the window that I pull up is NOT modal, so that shouldn't be the prob

Aug 4, 2011 at 9:29 AM

Hi

add white configuration settings to App.config and increase the timeout from 5000 to a higher value.

See Configuration for information

Aug 5, 2011 at 7:30 AM

I experimented with different values here, up to 30 seconds, with the same results. Except of course that it takes longer to time out.

All of the code that gets called by the click-handler that is activated by the Click() method runs (in well less than a second). The window that is created as a result of the click comes up completely and is ready to use, again, in less than a second. The Click() method just never returns, regardless of the wait setting. Again, all of my code has run and nothing in the app under test is holding anything up.

thanks,
Daniel


This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law. If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message. Thank you for your co-operation.
Aug 10, 2011 at 1:03 AM

any ideas or thoughts on this?

Aug 10, 2011 at 7:50 AM

 

Hi

 

can you try to use InvokePattern on selectButton.AutomationElement

 

Throndorin

Aug 11, 2011 at 5:16 PM

Hi Thorndorin,

Success! I simply changed

selectButton.Click();

to

selectButton.RaiseClickEvent();

and it works!

Thanks for all the help.

Sep 7, 2011 at 5:24 PM

Hey!

Thank you. I had the same problem. But using selectButton.RaiseClickEvent(); solved it.

Sep 7, 2011 at 5:42 PM

One thing this taught me and has helped in my use of White is to remember that all of the native capabilities of all of the windows/controls/widgets are there and should be used. Same goes for the UI Automation framework. Use the White API when it makes things easier, which it does in many cases, but don't hesitate to use those other capacities. Happy automating!

Jan 5, 2012 at 10:59 AM

Thanks for this solution !

I was wandering if it was the good solution, and it seems to !

Feb 7, 2012 at 7:16 AM
dgbillotte wrote:

I'm having problems getting a button to be clicked. My simple app comes up fine, I am then able to enter text into a textbox, but the button click never seems to happen. I've read several other threads here about similar problems. I have updated the BusyTimeout to 10000ms with no changes. Perhaps I don't have the app.config in the correct place? It is in the root directory of my test application (which is what calls into White)... When I run it I see the msg boxes from the calling code, but the msg box from the app under test never fires. The app under tests works as expected when I run it by itself.

relevant code snippets are below.

thanks!

daniel

 

Calling Code:

         TextBox fileName = s_Window.Get<TextBox>("m_fileName");
         fileName.SetValue(s_SettingsXmlPath);

         Button selectButton = s_Window.Get<Button>("m_selectFileNameButton");
         if (selectButton != null)
         {
            System.Windows.MessageBox.Show("about to click it");
            selectButton.Click();

            Window theWin = s_Window.ModalWindow("foowin");
         }

 

snippets from app under test:

xaml:

        <TextBox Name="m_fileName" Grid.Row="1"></TextBox>
        <Button Name ="m_selectFileNameButton" Grid.Row="2" Click="OnSelect">Select</Button>

codebehind:

      private void OnSelect(object sender, RoutedEventArgs e)
      {
         MessageBox.Show("Just clicked select button");

         m_window = new Window();
         m_window.Title = "foowin";
         m_window.ShowDialog();

       ...

       }


you can try to reffere to the button just as a UIItem:

UIItem yourButton = (UIItem) windowName.Get(SearchCriteria .ByAutomationId("yourButtonAutomationID"));

then click it:

yourbutton.Click();

Jul 10, 2012 at 12:02 PM
Edited Jul 10, 2012 at 12:03 PM

i downloaded the source code and when debugging it, it seems to be failing here,

            if (CoreAppXmlConfiguration.Instance.WaitBasedOnHourGlass)
            {
                Clock.Do @do = () => Mouse.Instance.Cursor;
                Clock.Matched matched = delegate(object obj)
                                            {
                                                var cursor = (MouseCursor) obj;
                                                if (MouseCursor.WaitCursors.Contains(cursor))
                                                {
                                                    Mouse.Instance.MoveOut();
                                                    return false;
                                                }
                                                return true;
                                            };
                Clock.Expired expired =
                    delegate { throw new UIActionException(string.Format("Window in still wait mode. Cursor: {0}{1}", Mouse.Instance.Cursor, Constants.BusyMessage)); };
                new Clock(CoreAppXmlConfiguration.Instance.BusyTimeout).Perform(@do, matched, expired);
            }

 

it seems to be fixed, when i set it not to wait based on hour glass. (for more information, http://white.codeplex.com/wikipage?title=Wait%20Handling)

Add the following to your app.config 

<add key="WaitBasedOnHourGlass" value="False"/>