Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337465 - Focus Problem in SWTBot Test
Summary: Focus Problem in SWTBot Test
Status: NEW
Alias: None
Product: SWTBot
Classification: Technology
Component: SWTBot (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows 7
: P3 critical with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-17 11:56 EST by Jens Baumgart CLA
Modified: 2011-02-17 11:57 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Baumgart CLA 2011-02-17 11:56:39 EST
I have a failing SWTBot test. If I click the same sequence as human everything is ok.

Given a wizard page with radio buttons A and B.
A has the focus.

The test selects radio Button B on the wizard page and presses Next.
Then the test fails because A is selected (B expected).

bot.radio(UIText.GitSelectWizardPage_ImportExistingButton).click(); // B
SWTBotButton button = shell.bot().button(IDialogConstants.NEXT_LABEL);
//		button.setFocus(); <--- Workaround to make the test run
button.click();

The reason for the problem is the following: button.click() does not set the focus on the Next button. The wizard framework restores focus in the handler of the click event and thus wrongly restores the focus to the radio button A.
Restoring the focus on the wrong control causes problems for radio buttons, because setFocus changes the selection state of a radio button.

Summarized I think the root cause of the problem is that SWTBot does not set the focus on clicked controls.

Call stack of focus handling in WizardDialog.nextPressed

java.lang.Exception: Button.setSelection caller
	at org.eclipse.swt.widgets.Button.setSelection(Button.java:1056)
	at org.eclipse.swt.widgets.Button.selectRadio(Button.java:835)
	at org.eclipse.swt.widgets.Button.wmCommandChild(Button.java:1317)
	at org.eclipse.swt.widgets.Control.WM_COMMAND(Control.java:4297)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4163)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4886)
	at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2362)
	at org.eclipse.swt.widgets.Button.callWindowProc(Button.java:344)
	at org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2401)
	at org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:4792)
	at org.eclipse.swt.widgets.Button.WM_SETFOCUS(Button.java:1225)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4229)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4873)
	at org.eclipse.swt.internal.win32.OS.SetFocus(Native Method)
	at org.eclipse.swt.widgets.Control.forceFocus(Control.java:995)
	at org.eclipse.swt.widgets.Control.setFocus(Control.java:3000)
	at org.eclipse.jface.wizard.WizardDialog.stopped(WizardDialog.java:1299)
	at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:1020)
	at org.eclipse.egit.ui.internal.clone.GitProjectsImportPage.setProjectsList(GitProjectsImportPage.java:343)
	at org.eclipse.egit.ui.internal.clone.GitCreateProjectViaWizardWizard$2.setVisible(GitCreateProjectViaWizardWizard.java:85)
	at org.eclipse.jface.wizard.WizardDialog.updateForPage(WizardDialog.java:1239)
	at org.eclipse.jface.wizard.WizardDialog.access$4(WizardDialog.java:1218)
	at org.eclipse.jface.wizard.WizardDialog$6.run(WizardDialog.java:1207)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.jface.wizard.WizardDialog.showPage(WizardDialog.java:1205)
	at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:894)
	at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:426)
	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
	at org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot$2.run(AbstractSWTBot.java:159)
	at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$5.doRun(UIThreadRunnable.java:221)
	at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$1.run(UIThreadRunnable.java:89)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
	at org.eclipse.jface.window.Window.open(Window.java:801)
	at org.eclipse.egit.ui.internal.repository.tree.command.ImportProjectsCommand.execute(ImportProjectsCommand.java:46)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:820)
	at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:806)
	at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:796)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
	at org.eclipse.egit.ui.test.ContextMenuHelper$5.run(ContextMenuHelper.java:168)
	at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$5.doRun(UIThreadRunnable.java:221)
	at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$1.run(UIThreadRunnable.java:89)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.swtbot.eclipse.core.UITestApplication.start(UITestApplication.java:54)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1383)