Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 424238

Summary: SWTBotViewMenu's click is not working for Action's with ID
Product: [Technology] SWTBot Reporter: Frank Schuerer <fschuerer>
Component: EclipseBotAssignee: Project Inbox <swtbot-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mistria
Version: 2.1.1   
Target Milestone: 2.2.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Frank Schuerer CLA 2013-12-17 09:13:43 EST
I've to click view menus action contributed by extension point org.eclipse.ui.viewAction. The action extension requires a id.

Testcode:
SWTBotView view = bot.viewByTitle("viewId");
view.menu("View Action").click();

The click doesn't happen.
Exception stack:

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.RuntimeException: Failed to execute the command - org.eclipse.swtbot.eclipse.finder.test.action)
	at org.eclipse.swt.SWT.error(SWT.java:4361)
	at org.eclipse.swt.SWT.error(SWT.java:4276)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4144)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	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:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.RuntimeException: Failed to execute the command - org.eclipse.swtbot.eclipse.finder.test.action
	at org.eclipse.swtbot.eclipse.finder.widgets.SWTBotViewMenu$1.run(SWTBotViewMenu.java:138)
	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:135)
	... 24 more
Caused by: org.eclipse.core.commands.common.NotDefinedException: Trying to execute a command that is not defined. org.eclipse.swtbot.eclipse.finder.test.action
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:477)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:178)
	at org.eclipse.swtbot.eclipse.finder.widgets.SWTBotViewMenu$1.run(SWTBotViewMenu.java:136)

It works as expect, when the actionID is not used as commendID at SWTBotViewMenu:

public SWTBotViewMenu(ActionContributionItem contributionItem)
    throws WidgetNotFoundException {
    Assert.isNotNull(contributionItem);
    Assert.isNotNull(contributionItem.getAction());

    actionItem = contributionItem;
    action = actionItem.getAction();
   // commandID = actionItem.getId();
    text = actionItem.getAction().getText();

    if (commandID == null)
      commandID = actionItem.getAction().getActionDefinitionId();
  }
Comment 1 Mickael Istria CLA 2013-12-17 09:24:39 EST
Do you think you could turn this test as a unit-test and contribute it via Gerrit (togeether with a patch ideally) http://wiki.eclipse.org/SWTBot/Contributing
Comment 2 Frank Schuerer CLA 2014-01-06 12:05:52 EST
I create some Unit-Tests:
https://git.eclipse.org/r/#/c/20299/1

and a Patch:
https://git.eclipse.org/r/#/c/20300/
Comment 3 Mickael Istria CLA 2014-01-06 12:13:05 EST
Thanks. Could you please put both test + patch in a single commit?
Comment 4 Frank Schuerer CLA 2014-01-08 05:13:17 EST
Test and patch in a single commit:
https://git.eclipse.org/r/#/c/20368/
Comment 5 Mickael Istria CLA 2014-01-08 05:15:15 EST
Fixed with gerrit review https://git.eclipse.org/r/#/c/20368/
Next CI build https://hudson.eclipse.org/swtbot/job/swtbot-tycho/154/ with this change should be published in http://download.eclipse.org/technology/swtbot/snapshots/ within a few minutes.

Thanks for this contribution. I will make it to upcoming 2.2.0.