Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Get the tree node(Get the tree node)
Get the tree node [message #502025] Fri, 04 December 2009 15:03 Go to next message
Seema  is currently offline Seema
Messages: 14
Registered: December 2009
Junior Member
Hi,
I have a tree structure as shown below:

root
|
Project1
|
Element1

The "root" node is hidden. Project 1 has a context menu with one of the menu items as "Open project".
Selecting "Open Project" menu item opens expands the tree and on expanding "Element 1" is present at the first node. It works fine upto this point. "Element 1" has a context menu with menu item "Manage Element 1". I want to select this and click to open up a view. I'm unable to do so. I need help.

These are few lines of the code that I was trying to achieve what I want.

SWTBotTree tree = tree();
SWTBotTreeItem[] array = tree.getAllItems();
//There has to be atleast one project in the tree view
assertTrue(array.length > 0);

SWTBotTreeItem treeNode = tree.getTreeItem("Project1);
treeNode.select().contextMenu("Open Project").click();//works

//tree.select("Element 1").contextMenu("Manage Data Elements");//tried but did not work
// treeNode.getNode("Data Elements").select().contextMenu("Manage Data Elements")//tried but did not work
treeNode.select().contextMenu("Manage Data Elements");//tried but did not work

Can anyone let me know how to go about?

Thanks.
Re: Get the tree node [message #502030 is a reply to message #502025] Fri, 04 December 2009 15:24 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Seema wrote:
> //tree.select("Element 1").contextMenu("Manage Data Elements");//tried
> but did not work
> // treeNode.getNode("Data Elements").select().contextMenu("Manage Data
> Elements")//tried but did not work

Any reason why its treeNode.getNode("Data Elements") and not
treeNode.getNode("Element 1") ? I'll figure its only a copy-paste error ;)

> treeNode.select().contextMenu("Manage Data Elements");//tried but did
> not work
>
> Can anyone let me know how to go about?
I did something similar and it would look like this:
treeNode.expand().getNode("Element 1").select().contextMenu("Manage Data
Elements").click();

It only adds an expand() call, but that worked for me... Although you
said that your treeNode was already expanded.
If it stills doesn't work, look closely at the thrown exception and
search for what is really failing. Might be it can't find your sub-item
or your context menu...

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Get the tree node [message #502035 is a reply to message #502030] Fri, 04 December 2009 15:52 Go to previous messageGo to next message
Seema  is currently offline Seema
Messages: 14
Registered: December 2009
Junior Member
thanks for the reply.
Yes that was copy paste problem.

The node expands when "Open Project" menu item is selected. I tried your suggestion again, but it did not help.
I get the following error and here is the stack trace:

org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.j ava:195)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchroniz er.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4312)
at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.run(U IThreadRunnable.java:76)
at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncE xec(UIThreadRunnable.java:172)
at org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot.syncExe c(AbstractSWTBot.java:475)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem.getItem s(SWTBotTreeItem.java:659)
at com.compwuare.dataprivacy.bottests.DataElements.CreateDataEl ementTest.testOpenProject(CreateDataElementTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at org.eclipse.swtbot.swt.finder.SWTBotTestCase.runBare(SWTBotT estCase.java:228)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38Cla ssRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:117)
at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:71)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336)
at org.eclipse.swt.widgets.TreeItem.getItems(TreeItem.java:783)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem$18.run( SWTBotTreeItem.java:661)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem$18.run( SWTBotTreeItem.java:1)
at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$3.doR un(UIThreadRunnable.java:169)
at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$1.run (UIThreadRunnable.java:89)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3855)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3476)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 21)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at com.compuware.frameworks.workbench.Application.start(Unknown Source)
at org.eclipse.swtbot.eclipse.core.UITestApplication.start(UITe stApplication.java:56)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:194)
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(EclipseS tarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)

Re: Get the tree node [message #502039 is a reply to message #502035] Fri, 04 December 2009 16:11 Go to previous message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Hmmmm, the dreaded "Widget is disposed" :P

I don't know what's the underlying logic or what you are really doing in
your test case, but here's my guess:
When you "Open the project" the previous tree item "Project1" gets
disposed and replaced by another tree item widget that is expandable.
What you could try is this:

SWTBotTree tree = bot.tree();
SWTBotTreeItem treeNode = tree.getTreeItem("Project1);
treeNode.select().contextMenu("Open Project").click();

treeNode = tree.getTreeItem("Project1");
treeNode.getNode("Element 1").select().contextMenu("Manage Data Elements");

If this still doesn't work, I can't really think if anything else
without knowing the details...

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Previous Topic:Hyperlink text
Next Topic:New SWTBot build
Goto Forum:
  


Current Time: Wed Jul 23 14:05:52 EDT 2014

Powered by FUDForum. Page generated in 0.01554 seconds