Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » popup menu in NatTable could'nt be found
popup menu in NatTable could'nt be found [message #1817372] Thu, 21 November 2019 10:09 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Hi all,
I'm testing a NatTable widget and tried to execute a command from a popup menu. So, I used the following code:
		botNatTable.clickColumnHeader(4, true);
		UIThreadRunnable.syncExec(() -> botNatTable.contextMenu("Delete Column").click());

Firstly, I omitted the UI thread wrapping which leads to a "Wrong Thread" error message. Now, if I use the UI thread, the popup menu isn't found (timeout while searching for it).

The implementation of botNatTable.contextMenu is

		ContextMenuHelper.notifyMenuDetect(control, widget);

		WaitForObjectCondition<Menu> waitForMenu = Conditions.waitForPopupMenu(control);
		new SWTBot().waitUntilWidgetAppears(waitForMenu);
		return new SWTBotRootMenu(waitForMenu.get(0));


What is the correct way to implement such a test?

TIA,
Ralf.

[Updated on: Thu, 21 November 2019 10:30]

Report message to a moderator

Re: popup menu in NatTable could'nt be found [message #1817395 is a reply to message #1817372] Thu, 21 November 2019 15:34 Go to previous messageGo to next message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 85
Registered: July 2009
Member
Hi Ralf,

It isn't normal that you need to wrap SWTBot code in a UIThreadRunnable. All SWTBot API are expected to be called from a test thread, not the UI thread. Could you share the stack trace?

For context menu, normally you only need to call contextMenu() on a SWTBot widget that represents what you are clicking on. I see you are trying to invoke context menu on a column header.

For a normal Table widget, we have SWTBotTable.header() that returns a SWTBotTableColumn, on which you can invoke contextMenu().

For NatTable, I see that there is SWTBotNatTable.contextMenu(row, column) that can be used to invoke the context menu on a cell.

I guess there is no capability in SWTBotNatTable to invoke the context menu on a column or row header.

If you would like to contribute that capability, we will be happy to review it. Otherwise you can write a bug enhancement request and will have to wait for someone to have time to do it.

Looking at your code snippet, I was wondering what is the class of botNatTable? I do not see any method called clickColumnHeader() in SWTBotNatTable?

Hope this helps,
Patrick
Re: popup menu in NatTable could'nt be found [message #1817437 is a reply to message #1817395] Fri, 22 November 2019 07:18 Go to previous messageGo to next message
Aparna Argade is currently offline Aparna ArgadeFriend
Messages: 61
Registered: October 2010
Member
Hi Ralf,
SWTBotNatTable context menu works for me for headers as well.
Could you try following by specifying your row-
botNatTable.contextMenu(row, 4).menu("Delete Column").click();

For this, the column should be visible.

If your column is not visible, you need scroll to scroll to it first using SWTBotNatTable.scrollToColumnHeader API, then click context menu on the returned position.

Hope this helps,
Aparna
Re: popup menu in NatTable could'nt be found [message #1817443 is a reply to message #1817437] Fri, 22 November 2019 09:47 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Hi Aparna,
this leads to the following exception:
org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException: Could not find pop up menu for control: NatTable {*Wrong Thread*}
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetAppears(SWTBotFactory.java:474)
	at org.eclipse.swtbot.swt.finder.SWTBot.waitUntilWidgetAppears(SWTBot.java:1)
	at org.eclipse.swtbot.nebula.nattable.finder.finders.NatTableContextMenuFinder.contextMenu(NatTableContextMenuFinder.java:76)
	at org.eclipse.swtbot.nebula.nattable.finder.widgets.SWTBotNatTable.contextMenu(SWTBotNatTable.java:264)
	at my.own.EditorTest.testRemoveColumn(EditorTest.java:75)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.eclipse.swtbot.swt.finder.junit.internal.CapturingFrameworkMethod.invokeExplosively(CapturingFrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.runChild(SWTBotJunit4ClassRunner.java:75)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.run(SWTBotJunit4ClassRunner.java:60)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(RemotePluginTestRunner.java:64)
	at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(UITestApplication.java:120)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Testable.lambda$0(E4Testable.java:73)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after: 5000 ms.: Could not find pop up menu for control: NatTable {*Wrong Thread*}
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:524)
	at org.eclipse.swtbot.swt.finder.SWTBot.waitUntil(SWTBot.java:1)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:498)
	at org.eclipse.swtbot.swt.finder.SWTBot.waitUntil(SWTBot.java:1)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:486)
	at org.eclipse.swtbot.swt.finder.SWTBot.waitUntil(SWTBot.java:1)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetAppears(SWTBotFactory.java:468)
	... 35 more

Re: popup menu in NatTable could'nt be found [message #1817458 is a reply to message #1817443] Fri, 22 November 2019 12:56 Go to previous messageGo to next message
Aparna Argade is currently offline Aparna ArgadeFriend
Messages: 61
Registered: October 2010
Member
It seems context menu is not registered in ui Binding registry. SWTBotNattable's context menu gets menu from UiBindingRegistry on MouseDown.

How is context menu implemented in your NatTable? Is it implemented using AbstractUiBindingConfiguration and PopupMenuAction (e.g. https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_501_Data/_5015_AutomaticDataSpanningExample.java )or by using some other mechanism?
Re: popup menu in NatTable could'nt be found [message #1818034 is a reply to message #1817458] Wed, 04 December 2019 14:33 Go to previous message
Patrick Tasse is currently offline Patrick TasseFriend
Messages: 85
Registered: July 2009
Member
Hi,

Just to let you know, the {*Wrong Thread*} is just because the failure message is created by calling Control.toString() from a non-UI thread. This is a bug in WaitForPopupMenu.getFailureMessage(). It is not the cause of the test failure.

Patrick
Previous Topic:Open SWTBot test Recorder with RCP application
Next Topic:SWTBot with JUnit5?
Goto Forum:
  


Current Time: Mon Dec 30 17:32:35 GMT 2024

Powered by FUDForum. Page generated in 0.05781 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top