Skip to content

Commit

Permalink
Used the workaround in Eclipse bug 344484 to select the radio button …
Browse files Browse the repository at this point in the history
…properly.

This commit belongs to issue #1.
  • Loading branch information
reprogrammer committed Jul 11, 2011
1 parent c4229d8 commit 9b3dd8c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
import static org.junit.Assert.assertTrue;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.hamcrest.Matcher;

/**
* @author Mohsen Vakilian
Expand Down Expand Up @@ -168,6 +174,27 @@ public void clickButtons(String... buttonNames) {
}
}

/**
*
* This method provides a workaround for Eclipse bug 344484.
*
* @param radioText
*/
public void deselectRadio(final String radioText) {
UIThreadRunnable.syncExec(new VoidResult() {

public void run() {
@SuppressWarnings("unchecked")
Matcher<Widget> matcher= WidgetMatcherFactory.allOf(WidgetMatcherFactory.widgetOfType(Button.class), WidgetMatcherFactory.withStyle(SWT.RADIO, "SWT.RADIO"),
WidgetMatcherFactory.withMnemonic(radioText));

Button b= (Button)bot.widget(matcher);
b.setSelection(false);
}

});
}

public SWTWorkbenchBot getBot() {
return bot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.github.reprogrammer.swtbot.examples;

import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.junit.Assert.assertEquals;

import org.eclipse.jface.dialogs.IDialogConstants;
Expand All @@ -18,10 +19,14 @@ public class TestEncapsulateField extends SWTBotTest {
protected void doExecuteRefactoring() {
bot.selectFromPackageExplorer(PROJECT_NAME, "src", PACKAGE_NAME, getTestFileName(), getTestName(), "field");
bot.invokeRefactoringFromMenu("Encapsulate Field...");
final String dialogName= "Encapsulate Field";
bot.getBot().waitUntilWidgetAppears(shellIsActive(dialogName));
bot.deselectRadio("use setter and getter");
bot.getBot().radio("keep field reference").click();
bot.clickButtons(IDialogConstants.OK_LABEL);
bot.getBot().waitUntil(Conditions.shellCloses(bot.getBot().shell("Encapsulate Field")));
bot.getBot().waitUntil(Conditions.shellCloses(bot.getBot().shell(dialogName)));
assertEquals(getTestOuputContents(), bot.getEditorContents(getTestName()));
}


}

0 comments on commit 9b3dd8c

Please sign in to comment.