Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to handle NatTable?
How to handle NatTable? [message #664247] Fri, 08 April 2011 02:45 Go to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
Our project uses NatTable and seems it's not recognizable by SWTBot. Is there any workaround? Thanks.
Re: How to handle NatTable? [message #664251 is a reply to message #664247] Fri, 08 April 2011 03:46 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
http://wiki.eclipse.org/SWTBot/Testing_Custom_Controls
According to the above page, I've also tried to make a wrapper as below:
package org.felix.test;

import net.sourceforge.nattable.NatTable;

import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
import org.hamcrest.SelfDescribing;

public class SWTBotNatTable extends AbstractSWTBot<NatTable> {
	public SWTBotNatTable(NatTable w) throws WidgetNotFoundException {
		this(w, null);
	}
	
	public SWTBotNatTable(NatTable w, SelfDescribing description) throws WidgetNotFoundException {
		super(w, description);
	}
	
	public void setSelectionItem() {
		asyncExec(new VoidResult() {
			public void run() {
				widget.setSelectedItem();
			}
		});
	}
}

And there is an error in the last line widget.setSelectedItem()
I'm a tester and not familiar with coding, so I don't know how to solve this problem. Please advise, thanks.

[Updated on: Fri, 08 April 2011 03:47]

Report message to a moderator

Re: How to handle NatTable? [message #664796 is a reply to message #664251] Tue, 12 April 2011 06:10 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
New wrapper without compiling error:
package org.felix.test;

import net.sourceforge.nattable.NatTable;

import org.eclipse.swtbot.swt.finder.ReferenceBy;
import org.eclipse.swtbot.swt.finder.SWTBotWidget;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.results.IntResult;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
import org.hamcrest.SelfDescribing;

@SWTBotWidget(clasz = NatTable.class, preferredName = "nattable", referenceBy = { ReferenceBy.LABEL })
public class SWTBotNatTable extends AbstractSWTBot<NatTable> {
	
	public SWTBotNatTable(NatTable nattable, SelfDescribing description) throws WidgetNotFoundException {
		super(nattable, description);
	}
	
	public SWTBotNatTable(NatTable nattable) throws WidgetNotFoundException {
		this(nattable, null);
	}
	
	public int rowCount() {
		return syncExec(new IntResult() {
			public Integer run() {
				return widget.getRowCount();
			}
		});
	}
	
}


and the related testing code:
package org.felix.test;

import net.sourceforge.nattable.NatTable;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(SWTBotJunit4ClassRunner.class)
public class TestNatTable {
	private SWTWorkbenchBot bot;

	@Test
	public void getRowCount() {
		NatTable nt = bot.widget(widgetOfType(NatTable.class));
		SWTBotNatTable sbnt = new SWTBotNatTable(nt);
		System.out.println("Row Count: " + sbnt.rowCount());
	}

	@Before
	public void setup() {
		bot = new SWTWorkbenchBot();
	}
}


However, still not work... get the following exception in Junit:
org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException: Could not find widget.
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetAppears(SWTBotFactory.java:348)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.widget(SWTBotFactory.java:308)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.widget(SWTBotFactory.java:317)
	at org.felix.test.EditTarget.EnterTargetText(EditTarget.java:19)
	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.run(SWTBotJunit4ClassRunner.java:54)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(RemotePluginTestRunner.java:64)
	at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(UITestApplication.java:117)
	at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(WorkbenchTestable.java:71)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after: 5000 ms.: Could not find widget matching: of type 'NatTable'
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:398)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:372)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:360)
	at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetAppears(SWTBotFactory.java:346)
	... 31 more
Re: How to handle NatTable? [message #664822 is a reply to message #664796] Tue, 12 April 2011 08:18 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
Almost resolved. The above code works fine now.
I wrongly added net.sourceforge.nattable.core-2.2.0.jar to Build Path and Runtime Classpath (as an External JAR).
The right way is to add it to plug-in dependencies (nattable core has been installed as a plugin in the target platform of our product).
There is one thing rest - complete the methods I need in SWTBotNatTable.class.

[Updated on: Tue, 12 April 2011 15:29]

Report message to a moderator

Re: How to handle NatTable? [message #665952 is a reply to message #664822] Mon, 18 April 2011 10:06 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
I'm stuck here: with the the codes copied from SWTBotTable/Item and SWTBotTree/Item, Double Click and Context Menu (Right Click) won't work...
Both of them work like a Single Click only: the target Cell was selected, but neither Double Click actions reflected on the UI nor Context Menu popped up.
Maybe the default "notify" method should be recoded - but I don't know how.
Ulike Table and Tree, NatTable has no "Item" and lack of documents.
Re: How to handle NatTable? [message #667241 is a reply to message #665952] Wed, 27 April 2011 15:14 Go to previous messageGo to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi Felix !

I've been doing testing on NatTable for almost three weeks now, and I just found your post.

I manage to "double click" on my NatTable using the Display :

private static void editCellByPosition(final SWTBotEditor editor, final int columnPosition,
			final int rowPosition) {
		syncExec(new VoidResult() {
			public void run() {

				Rectangle rect = this.fBodyLayer.getSelectionLayer().getBoundsByPosition(columnPosition - 1, rowPosition - 1);
				Point pt =  this.natTable.toDisplay(rect.x, rect.y);
				
				Event event = new Event();
				final Display display = editor.bot().getDisplay();

				// Move the mouse cursor over the cell
				event.type = SWT.MouseMove;
				event.x = pt.x;
				event.y = pt.y;
				display.post(event);

				event = new Event();
				// Apparently acts as a MouseDoubleClick
				event.type = SWT.MouseDown;
				event.button = 1;
				display.post(event);
				display.post(event);
			}
		});
	}



I manage to use the context menu using this workaround :
http://www.eclipse.org/forums/index.php?t=msg&S=f56965ee d40385216344f3a8cd673c6e&th=11863&goto=664833#msg_66 4833


Regards,

Nicolas Guyomar
http://www.eclipse.org/MoDisco/
http://www.eclipse.org/modeling/emft/facet/


Re: How to handle NatTable? [message #667748 is a reply to message #667241] Mon, 02 May 2011 03:53 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
Hi Nicolas,

Thank you very much for the useful information.
I've managed to make the Double Click work too. I just changed the AbstractSWTBot's original
notify(SWT.Selection, createSelectionEvent(SWT.BUTTON1));
to
notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));


Now it is:
	public void doubleClick(final int rowPosition, final int columnPosition) {
		assertIsLegalCell(rowPosition, columnPosition);
		asyncExec(new VoidResult() {
			public void run() {
				Rectangle cellBounds = widget.getBoundsByPosition(columnPosition, rowPosition);
				doubleClickXY(cellBounds.x + (cellBounds.width / 2), cellBounds.y + (cellBounds.height / 2));
			}
		});
	}
	
	protected void doubleClickXY(int x, int y) {
		log.debug(MessageFormat.format("Double-clicking on {0}", widget)); //$NON-NLS-1$
		notify(SWT.MouseEnter);
		notify(SWT.MouseMove);
		notify(SWT.Activate);
		notify(SWT.FocusIn);
		notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
		notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1));
		notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
		notify(SWT.MouseDoubleClick, createMouseEvent(x, y, 1, SWT.BUTTON1, 2));
		notify(SWT.MouseHover);
		notify(SWT.MouseMove);
		notify(SWT.MouseExit);
		notify(SWT.Deactivate);
		notify(SWT.FocusOut);
		log.debug(MessageFormat.format("Double-clicked on {0}", widget)); //$NON-NLS-1$
	}


I'll try the context menu. Thanks again!
icon14.gif  Re: How to handle NatTable? [message #668074 is a reply to message #667748] Tue, 03 May 2011 15:45 Go to previous messageGo to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi Felix,

Nice work on the double click, I didn't had time to really look into it.

Thanks


Re: How to handle NatTable? [message #668559 is a reply to message #668074] Fri, 06 May 2011 08:47 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
Hi Nicolas,

The ContextMenuHelper does not work for me. Even if I used Sikuli to trigger the right click event to show the context menu, SWTBot cannot find any MenuItem as the context menu shown.
Re: How to handle NatTable? [message #673315 is a reply to message #668559] Mon, 23 May 2011 08:22 Go to previous messageGo to next message
Felix Lu is currently offline Felix LuFriend
Messages: 12
Registered: April 2011
Junior Member
Hi Nicolas,

I finally get the ContextMenuHelper work - with the help of our developer.
Our developer didn't use the setMenu() method to bind the context menu to the NatTable, that's why I couldn't get the menu by control.getMenu() in the helper.
We still didn't use the setMenu() method, because it causes context menu conflict(bodyMenu and headerMenu) in the header. We use setDate(Menu.class.getName(), bodyMenu), so I changed the control.getMenu() to (Menu) widget.getData(Menu.class.getName()) to get the menu.
Re: How to handle NatTable? [message #696007 is a reply to message #673315] Wed, 13 July 2011 04:30 Go to previous messageGo to next message
Krasimir.K is currently offline Krasimir.KFriend
Messages: 2
Registered: July 2009
Junior Member
Hi Felix,
Can you help me with resolving "WidgetNotFoundException: Could not find widget"?
I have similar code like you (NatTable nattable = bot.widget(widgetOfType(NatTable.class))Wink and I use Eclipse Orbit version of nattable plug-in.
I execute swtbot tests from tycho maven build system.
I have nattable inside tab part of view. I was able to access all SWT widgets, but throw the error on NatTable.
Regards,
Krasi

P.S. : I found my problem : I don't got exactly bot object for the view.

[Updated on: Wed, 13 July 2011 11:31]

Report message to a moderator

Re: How to handle NatTable? [message #715112 is a reply to message #668074] Fri, 12 August 2011 12:03 Go to previous message
vineel Missing name is currently offline vineel Missing nameFriend
Messages: 12
Registered: April 2011
Location: Pune,India
Junior Member

Hi,

We are trying to do automation testing our swing and AWT UI through sikuli,can it be used for commercial purposes or are there any licensing issues with it.
Please let me know.

Regards,
Venkata Vineel
Previous Topic:SwtbotEclipseEditor.typeText() fails in Eclipse cocoa
Next Topic:Sikuli for commercial purpose
Goto Forum:
  


Current Time: Thu Mar 28 14:36:52 GMT 2024

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

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

Back to the top