| Summary: | SWTBotRadio method click() doesn't work properly | ||
|---|---|---|---|
| Product: | [Technology] SWTBot | Reporter: | Vlado Pakan <vpakan> |
| Component: | SWTBot | Assignee: | Project Inbox <swtbot-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | cabernal, geoff.bache, glubglub, hubert+eclipseorg, itac, michal.anglart, mistria, pascale.prost, pierre-charles.david, reprogrammer, richard.adams, sbouchet, tmm-bugs.eclipse, tobias.schwarz, Wael.mashal |
| Version: | unspecified | ||
| Target Milestone: | 2.3.0 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| See Also: |
https://git.eclipse.org/r/42546 https://git.eclipse.org/c/swtbot/org.eclipse.swtbot.git/commit/?id=b181b0b6da7b59ebfccdc969f638ce47c0ebdcdf |
||
| Whiteboard: | |||
|
Description
Vlado Pakan
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. |