Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Widget not found exception
Widget not found exception [message #481753] Mon, 24 August 2009 08:39 Go to next message
Eclipse UserFriend
Hi !
I use SWTBot to test my Eclipse Plug-in.

Currently i am trying to create some preconditions
for each test case(there should be a project with
a test file in the workspace. after the project and
file creation, i intent to open the file in the text
editor and print some text in it).

My test:

@RunWith(SWTBotJunit4ClassRunner.class)
public class MyFirstTest {

private static SWTWorkbenchBot bot;

@BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTWorkbenchBot();
bot.viewByTitle("Welcome").close();
SWTBotPerspective perspective =
bot.perspectiveByLabel("ConfigModeler");
perspective.activate();

// Create a project
bot.menu("File").menu("New").menu("Project...").click();
bot.shell("New Project").activate();
bot.tree().expandNode("General").select("Project");
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText("test
project");
bot.button("Finish").click();

// Create a file
bot.menu("File").menu("New").menu("Other...").click();
bot.shell("New").activate();
bot.tree().
expandNode("Config Modeler").
select("Source file");
bot.button("Next >").click();
bot.textWithLabel("Container:").setText("test project");
bot.button("Finish").click();

SWTBotEditor botEditor =
bot.editorByTitle("new_product.cml");
SWTBotEclipseEditor textEditor =
botEditor.toTextEditor();
for(int i=0; i<10; i++) {
textEditor.typeText("test");
}
}

@Test
public void test...() throws Exception {
....
}
}

When i start the test, i get the following exception:

org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion: Could
not find widget.
at
org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetA ppears(SWTBotFactory.java:346)
at org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFacto ry.java:255)
at org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFacto ry.java:206)
at org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFacto ry.java:196)
at
com.webxcerpt.configmodeler.tests.example.MyFirstTest.before Class(MyFirstTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:27)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at
org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner. run(SWTBotJunit4ClassRunner.java:54)
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:636)
Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException:
Timeout after: 5000 ms.: Could not find a menu within the shell 'Shell
with text {}' matching 'with mnemonic 'File''
at
org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:396)
at
org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:370)
at
org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:358)
at
org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetA ppears(SWTBotFactory.java:344)
... 24 more


any ideas whats wrong with my test ?

thanx
Aleksey
Re: Widget not found exception [message #481815 is a reply to message #481753] Mon, 24 August 2009 12:12 Go to previous messageGo to next message
Eclipse UserFriend
Aleksey Shumilin schrieb:
> Hi !
> I use SWTBot to test my Eclipse Plug-in.
>
> Currently i am trying to create some preconditions
> for each test case(there should be a project with
> a test file in the workspace. after the project and
> file creation, i intent to open the file in the text
> editor and print some text in it).
>
> My test:
>
> @RunWith(SWTBotJunit4ClassRunner.class)
> public class MyFirstTest {
>
> private static SWTWorkbenchBot bot;
>
> @BeforeClass
> public static void beforeClass() throws Exception {
> bot = new SWTWorkbenchBot();
> bot.viewByTitle("Welcome").close();
> SWTBotPerspective perspective =
> bot.perspectiveByLabel("ConfigModeler");
> perspective.activate();
>
> // Create a project
> bot.menu("File").menu("New").menu("Project...").click();
> bot.shell("New Project").activate();
> bot.tree().expandNode("General").select("Project");
> bot.button("Next >").click();
> bot.textWithLabel("Project name:").setText("test
> project");
> bot.button("Finish").click();
>
> // Create a file
> bot.menu("File").menu("New").menu("Other...").click();
> bot.shell("New").activate();
> bot.tree().
> expandNode("Config Modeler").
> select("Source file");
> bot.button("Next >").click();
> bot.textWithLabel("Container:").setText("test project");
> bot.button("Finish").click();
>
> SWTBotEditor botEditor =
> bot.editorByTitle("new_product.cml");
> SWTBotEclipseEditor textEditor =
> botEditor.toTextEditor();
> for(int i=0; i<10; i++) {
> textEditor.typeText("test");
> }
> }
>
> @Test
> public void test...() throws Exception {
> ....
> }
> }
>
> When i start the test, i get the following exception:
>
> org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion: Could
> not find widget.
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetA ppears(SWTBotFactory.java:346)
>
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFacto ry.java:255)
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFacto ry.java:206)
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFacto ry.java:196)
> at
> com.webxcerpt.configmodeler.tests.example.MyFirstTest.before Class(MyFirstTest.java:34)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:616)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:27)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at
> org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner. run(SWTBotJunit4ClassRunner.java:54)
>
> 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:636)
> Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException:
> Timeout after: 5000 ms.: Could not find a menu within the shell 'Shell
> with text {}' matching 'with mnemonic 'File''
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:396)
>
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:370)
>
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:358)
>
> at
> org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetA ppears(SWTBotFactory.java:344)
>
> ... 24 more
>
>
> any ideas whats wrong with my test ?
>
> thanx
> Aleksey
>
>

the problem was removed with the activation of the eclipse main window

SWTBotShell shell = bot.activeShell();

// Create a project
bot.menu("File").menu("New").menu("Project...").click();
bot.shell("New Project").activate();
bot.tree().expandNode("General").select("Project");
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText("test
project");
bot.button("Finish").click();
shell.activate();
Re: Widget not found exception [message #481921 is a reply to message #481815] Mon, 24 August 2009 17:33 Go to previous message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Yes, I've run into that one.

Here's another gotcha ...

bot.menu("Project").menu("Build Automatically").click();

had to be changed to

bot.menu("Project",1).menu("Build Automatically").click();

in my test case, even though the "Project" menu is in the main menu bar.

Seems like there should be some obvious heirarchy to the menu search. I
didn't figure out which "Project" it was finding, but apparently it found
something else first.
Previous Topic:fix for tree expand flakiness
Next Topic:SWTBotText.setText(String) not notifying listeners
Goto Forum:
  


Current Time: Thu Apr 18 06:41:51 GMT 2024

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

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

Back to the top