Community
Participate
Working Groups
Build Identifier: 2.0.4.20110304_0338-e5aff47-dev-e36 After changes related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=286897 method click() doesn't work for SWTBotRadio. When selecting not selected radio button currently selected radio button is deselected new radio button is selected and finally previously selected radio button is again selected. Reason is this new code from SWTBotRadio click() method: if (otherSelectedButton != null) { otherSelectedButton.notify(SWT.Selection); } This is not correct behavior because application and not test has to deselect currently selected radio button. When user selects deselected radio button he is not deselecting previously selected radio button so there is difference between what user is doing and what SWTBot is simulating. Reproducible: Always Steps to Reproduce: 1. Create dialog with 2 radio buttons 2. Add logic to this radio buttons selection listener to disable previously selected radio button 3. Use SWTBotRadio method click() to click on not selected radio button. 4. New radio button is selected and then previously selected radio button is selected again
Came across same problem on MacOSX and posted here in user group http://www.eclipse.org/forums/index.php/t/215850/ A temporary fix is to use this method in your test code which deselects the current selection, then select the desired button: /** *@param currSelection The index of the radiobutton to deselect */ void deselectDefaultSelection(int currSelection) { UIThreadRunnable .syncExec(new VoidResult() { public void run() { Matcher<Widget> matcher = allOf(widgetOfType(Button.class), withStyle(SWT.RADIO, "SWT.RADIO")); Button b = (Button) bot.widget(matcher, currSelection); // the current selection b.setSelection(false); } }); }
(In reply to comment #1) My test suffered from the same problem in selecting radio buttons (See my report at <http://stackoverflow.com/q/6641244/130224>). And, your temporary fix worked for me. I'm using Eclipse 3.7 (Build id: 20110615-0604) with SWTBot (2.0.4.20110304_0338-e5aff47-dev-e36) on Ubuntu. > Came across same problem on MacOSX and posted here in user group > > http://www.eclipse.org/forums/index.php/t/215850/ > > A temporary fix is to use this method in your test code which deselects the > current selection, then select the desired button: > /** > *@param currSelection The index of the radiobutton to deselect > */ > void deselectDefaultSelection(int currSelection) { > UIThreadRunnable > .syncExec(new VoidResult() { > > public void run() { > Matcher<Widget> matcher = allOf(widgetOfType(Button.class), > withStyle(SWT.RADIO, "SWT.RADIO")); > > Button b = (Button) bot.widget(matcher, currSelection); // the > current selection > b.setSelection(false); > > } > > }); > }
It seems that I've also met this problem and posted about it here: http://www.eclipse.org/forums/index.php/t/238897/ Thanks for workaround - I will try it
We also encountered this. To be clear, when clicking on a radio button normally the SWT.Selection events are received by the buttons in the order: current, new. Isn't fixing this properly as simple as swapping the "notify" lines of code at the bottom of SWTBotRadio.click()??
Same question as Tim: (In reply to comment #4) [...] > Isn't fixing this properly as simple as swapping the "notify" lines of code at > the bottom of SWTBotRadio.click()?? I updated my plugin "org.eclipse.swtbot.swt.finder_2.0.5" changing the order of the selections and it seems ok now. The code is the following (only 2 changes): /** * Selects the radio button. */ public SWTBotRadio click() { if (isSelected()) { log.debug(MessageFormat.format("Widget {0} is already selected, not clicking again.", this)); //$NON-NLS-1$ return this; } waitForEnabled(); log.debug(MessageFormat.format("Clicking on {0}", this)); //$NON-NLS-1$ final SWTBotRadio otherSelectedButton = otherSelectedButton(); if (otherSelectedButton != null) { otherSelectedButton.notify(SWT.Deactivate); asyncExec(new VoidResult() { public void run() { otherSelectedButton.widget.setSelection(false); } }); otherSelectedButton.notify(SWT.Selection); /* FIXME 344484: OTHER SELECTION MOVED HERE */ } notify(SWT.Activate); notify(SWT.MouseDown, createMouseEvent(0, 0, 1, 0, 1)); notify(SWT.MouseUp, createMouseEvent(0, 0, 1, SWT.BUTTON1, 1)); asyncExec(new VoidResult() { public void run() { widget.setSelection(true); } }); notify(SWT.Selection); /* FIXME 344484: OTHER SELECTION WAS THERE */ /* if (otherSelectedButton != null) { otherSelectedButton.notify(SWT.Selection); } */ log.debug(MessageFormat.format("Clicked on {0}", this)); //$NON-NLS-1$ return this; }
If the suggested patch works, is somebody going to apply it and release a new SWTBot? Just got bitten by this as well (again).
Can we get this patch committed? Several people have stumbled onto this problem, and the fix seems to be fairly straightforward.
@Georges: can you please submit this change as a Gerrit contribution to share it with all other interested parties? http://wiki.eclipse.org/SWTBot/Contributing#Provide_a_contribution_using_Gerrit
i see the same problem with SWTBotRadio.click() working on eclipse 3.8.1. but the suggested patch does not solve this issue!
sorry - ignore my last comment - the fix _IS_ working. i ran into a problem in the dialog i tried to test with SWTBotRadio.
Hi I build the finder jar with the above code and its OK on the level click() method exception , But The other case i have ,I enabling some components depend on radio selection but still not work , in my case a Text field will be enabled when I click on the radio if I do it manually it works fine But if I call these steps using SWTBot the radio selected but the Text field still disabled , see my code below always the condition false in the if statement SWTBot shellBot = bot.activeShell().bot(); SWTBotRadio radio = shellBot.radio("Platform Manager URL"); radio.click(); if (shellBot.text(1).isEnabled()) { shellBot.text(1).typeText("http://url"); shellBot.text(2).typeText("Admin"); shellBot.text(3).typeText("Admin"); } Any Idea Friends ? #Georges Dupont ?
I am using Eclipse CDT Kepler SR2 (4.3.2) and SWTBot 2.2.2 on Windows 7. My tests contain SWTBotRadio.click(). I tried to implement the suggested patch with deselectDefaultSelection method. The "deselection" works fine (I can see it happening on the screen), but after the call to SWTBotRadio.click(), new radio button is selected and just after previously selected radio button is selected again. Any advice is welcome, I cannot go further with my tests...
I have also tried to implement the suggested patch SWTBotRadio.click() method, but the issue still remains.
@Vlado: do you think you could provide a patch for that issue?
I was finally able to solve my issue, using the patch suggested by Georges Dupont, but I had to add the a "setFocus();" statement before the "notify(SWT.Activate);" : replacing : notify(SWT.Activate); notify(SWT.MouseDown, createMouseEvent(0, 0, 1, 0, 1)); notify(SWT.MouseUp, createMouseEvent(0, 0, 1, SWT.BUTTON1, 1)); with : notify(SWT.Activate); notify(SWT.MouseDown, createMouseEvent(0, 0, 1, 0, 1)); notify(SWT.MouseUp, createMouseEvent(0, 0, 1, SWT.BUTTON1, 1));
Sorry, discard my previous comment (it got posted before I actually finished writing it). I was finally able to solve my issue, using the patch suggested by Georges Dupont, but I had to add the a "setFocus();" statement before the "notify(SWT.Activate);". So I replaced : notify(SWT.Activate); notify(SWT.MouseDown, createMouseEvent(0, 0, 1, 0, 1)); notify(SWT.MouseUp, createMouseEvent(0, 0, 1, SWT.BUTTON1, 1)); with : setFocus(); notify(SWT.Activate); notify(SWT.MouseDown, createMouseEvent(0, 0, 1, 0, 1)); notify(SWT.MouseUp, createMouseEvent(0, 0, 1, SWT.BUTTON1, 1)); Now my tests work fine :-)
Hi, I'm getting the same problem trying to set some eclipse preferences. I am able to fix thanks to previous comments. i'll make a patch that includes a testcase and the fix thru gerrit.
New Gerrit change created: https://git.eclipse.org/r/42546
Gerrit change https://git.eclipse.org/r/42546 was merged to [master]. Commit: http://git.eclipse.org/c/swtbot/org.eclipse.swtbot.git/commit/?id=b181b0b6da7b59ebfccdc969f638ce47c0ebdcdf
Thanks Stephane. Your change was merged. SWTBot 2.2.2 snapshot with this change will be available within a few minutes in http://download.eclipse.org/technology/swtbot/snapshots.