How to enable checkbox? [message #1754325] |
Thu, 16 February 2017 07:01  |
Eclipse User |
|
|
|
Hello SWTBot world,
I have the following code used in a Java GUI test campaign:
bot.toolbarButtonWithTooltip("new person").click(); // this enables various (the ones beneath and more) controls in my application.
bot.textWithLabel("Name").setText("John Doe"); // works fine
.... more textFields filled ...
....
bot.checkBox().click(); // fails with the message "The widget (of type 'Button' and with style 'SWT.CHECK') was not enabled."
Is there a way to enable the checkbox within the SWTBot?
In my application it takes a while until the controls are updated. The test framework is faster than me clicking the checkbox or inserting text ...
So I tried bot.wait(1000) after the 1st line of code which resulted in another error message.
If I set a breakpoint at bot.checkBox().click(); all controls are greyed/disabled but the textWithLabel controls are filled by the SWTBot code - only the click() method of the checkBox fails.
thanks for any help
HoWei
|
|
|
Re: How to enable checkbox? [message #1754436 is a reply to message #1754325] |
Fri, 17 February 2017 14:44   |
Eclipse User |
|
|
|
Hi Horst,
There's no way to force a widget to be enabled, as there is no UI equivalent to this operation. You should use the application's normal method to enable the widget, such as clicking the "new person" tool bar button in your application.
When you call SWTBotCheckBox.click(), it waits for the button to be enabled.
The default timeout is 5000 ms, but you can change it by modifying the value of the SWTBotPreferences.TIMEOUT public field.
Calling bot.wait(long) is something completely different, it is a method of Java's Object class, it's related to thread synchronization.
Assuming your timeout is long enough, are you sure that your are trying to click the right checkbox button? Calling bot.checkBox() will return the first checkbox button that it finds in the current active shell. Perhaps you need a more specific method to find the widget? Or are there multiple shells or views in your application, and you might need to get a specific bot from the shell or view that contains your checkbox button?
Hope this helps,
Patrick
|
|
|
|
Re: How to enable checkbox? [message #1754598 is a reply to message #1754555] |
Mon, 20 February 2017 11:53   |
Eclipse User |
|
|
|
Hi Horst,
Of course we don't want the tester to need to manually click anything while the test is running... I meant that you should use SWTBot API to do the mouse or keyboard actions necessary to enable a widget, because there's no SWTBot API for widget.setEnabled(true).
I'm confused, do you have an issue with the "new person" tool bar button being disabled? I thought clicking that tool bar button was OK, but after clicking it, it was the other checkbox button that was disabled.
If you look at the application when the test is running, does the checkbox button ever become enabled? If it does not, then it could be that the "new person" tool bar button was not properly clicked, or that your application was not in a state ready to handle that button?
Another issue we have seen sometimes is that a lot of widget actions in SWTBot use the sequence FocusIn, Activate, *do stuff*, Deactivate, FocusOut. This is not necessarily representative of the real UI behavior, since clicking a widget doesn't make it lose focus (on the contrary!). While in most cases this doesn't cause a problem, if your application is specifically listening and acting on the FocusOut event, it could interfere.
Patrick
|
|
|
|
Re: How to enable checkbox? [message #1754706 is a reply to message #1754655] |
Tue, 21 February 2017 12:01   |
Eclipse User |
|
|
|
Hi Horst,
Great that you have solved your problem.
However, without spending too much time, I would have thought that there would be a SWTBot way to give focus to the E4 MPart?
One thing I notice is that SWTBotToolbarButton in particular, does not send a SWT.FocusIn event when click() is called, unlike I mentioned in my last message. Would that have been enough? Then maybe you could call SWTBotToolBarButton.setFocus() before the click(). Or maybe calling active() or setFocus() on the Shell that contains the tool bar?
Otherwise, if I could debug this, I would try to find the point where the E4 MPart gets focus, add a breakpoint there, then manually click the tool bar button, identify in the call stack which SWT event leads to the activation of the MPart, and then see how SWTBot can also trigger that same event... 
Patrick
|
|
|
|
|
Re: How to enable checkbox? [message #1754890 is a reply to message #1754828] |
Thu, 23 February 2017 10:39  |
Eclipse User |
|
|
|
What I see in debugging is that when you click on a Control that is contained in a MPart, the OS sends a focus event to the Control, which in turn calls setActiveControl() to the Shell (see Control.sendFocusEvent()).
The Shell then recursively sends a SWT.Activate event up the chain of parents of the focused Control, and eventually in that chain is found the ContributedPartRenderer's widget (which is an internal Composite that SWTBot does not have direct access to). That widget's SWT.Activate listener then makes the MPart active.
So I would try to set the focus on one of your MPart's controls using its SWTBot widget instance ie. AbstractSWTBot.setFocus(). Hopefully that will trigger the above chain of events...
|
|
|
Powered by
FUDForum. Page generated in 0.05480 seconds