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();
@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
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
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.