Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to enable checkbox?( bot.checkBox().click(); fails because checkBox is not enabled)
How to enable checkbox? [message #1754325] Thu, 16 February 2017 12:01 Go to next message
Horst Weigelt is currently offline Horst WeigeltFriend
Messages: 4
Registered: February 2017
Location: Tübingen
Junior Member
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 19:44 Go to previous messageGo to next message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 84
Registered: July 2009
Member
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 #1754555 is a reply to message #1754436] Mon, 20 February 2017 08:27 Go to previous messageGo to next message
Horst Weigelt is currently offline Horst WeigeltFriend
Messages: 4
Registered: February 2017
Location: Tübingen
Junior Member
Hello Patrick,
yes your answer helped for a workaround. Thank you!
Yes I am sure that SWTBot "clicks" the correct button. You are right if there are many buttons and they are not labelled it's easy to click the wrong one Sad .

I am not 100% sure that we are talking about the same issue.
Surely I can standby while the automated tests are running and click on the correct button - this will enable the "new person" button and the test continues. However this will be not an automated test anymore.
Moreover I ran into very similar problems while running different tests with buttons.

If I have dozens of tests and in every second or third test I have to 'assist' the SWTBot it will become really tedious and it will not be an automated test anymore at all. Plus it would need a lot of explanation to pass the testing to a second tester ...

The plan is to go one step further and start the automated tests automatically (e.g. Jenkins) which will make it even harder to manually click the right buttons or checkboxes at the right time ...

I will think about a better workaround or wait for an improved version of SWTBot Rolling Eyes

kind regards
Horst

[Updated on: Mon, 20 February 2017 08:43]

Report message to a moderator

Re: How to enable checkbox? [message #1754598 is a reply to message #1754555] Mon, 20 February 2017 16:53 Go to previous messageGo to next message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 84
Registered: July 2009
Member
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 #1754655 is a reply to message #1754325] Tue, 21 February 2017 10:39 Go to previous messageGo to next message
Horst Weigelt is currently offline Horst WeigeltFriend
Messages: 4
Registered: February 2017
Location: Tübingen
Junior Member
solved!

actually I found the solution here in the forum
https://www.eclipse.org/forums/index.php/t/1067419/


Hello Patrick,
thank you for the quick reply!

We probably found out the reason why the click() fails.
The AUT is an E4 application and the containing MPart of the toolButtonWithTooltip("new person") does not have focus and the handler call fails.
This will lead to a chain of Exceptions. I did not see these exceptions last week.

So you are right the application is not in the correct state to handle the click-event.
But we have no solution yet.

Now we are looking for a connection beetween SWT, SWTBot and E4-Parts - without leading to Invalid thread access violations which occur when climbing up the widget tree ....

Do you have an ideas or heard of a similar problem?

Horst

[Updated on: Tue, 21 February 2017 11:20]

Report message to a moderator

Re: How to enable checkbox? [message #1754706 is a reply to message #1754655] Tue, 21 February 2017 17:01 Go to previous messageGo to next message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 84
Registered: July 2009
Member
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... Wink

Patrick
Re: How to enable checkbox? [message #1754771 is a reply to message #1754706] Wed, 22 February 2017 09:19 Go to previous messageGo to next message
Horst Weigelt is currently offline Horst WeigeltFriend
Messages: 4
Registered: February 2017
Location: Tübingen
Junior Member
Hello,
At least in our case SWTBotToolBarButton.setFocus() will not be enough, since the click-eventhandlercode is hooked at the E4 MPart. In our case the MPart is null if the part is not active -> no associated handlercode.

Horst
Re: How to enable checkbox? [message #1754828 is a reply to message #1754771] Wed, 22 February 2017 21:57 Go to previous messageGo to next message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 84
Registered: July 2009
Member
I'm not too familiar with E4 implementation, but browsing the code I saw that ContributedPartRenderer seems to activate an MPart through a SWT.Activate listener that is hooked on the MPart's widget.
Re: How to enable checkbox? [message #1754890 is a reply to message #1754828] Thu, 23 February 2017 15:39 Go to previous message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 84
Registered: July 2009
Member
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...
Previous Topic:Can't add Required plug-ins to MANIFEST.MF
Next Topic:Reference a target file as platform configuration
Goto Forum:
  


Current Time: Fri Apr 19 20:22:03 GMT 2024

Powered by FUDForum. Page generated in 0.03690 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top