Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » SWT standalone newbie question
SWT standalone newbie question [message #634237] Wed, 20 October 2010 21:55 Go to next message
Keith Willenson is currently offline Keith WillensonFriend
Messages: 21
Registered: July 2009
Junior Member
I am trying to test my standalone application with SWTBot. I can start an Eclipse workbench (using the plugin example), but there is nothing in it. I thought about loading my application, but decided there must be an easier way. Please let me know if I am wrong. I can run junit4 tests, but I can not get an SWTBot to see my applicaiton. So what do I need to do to get the junit tests and SWTBot together? I am using Eclipse Helios 3.6, version 2.0.0.595-dev-e36 of SWTBot, and junit4.

When I uncomment the bot in PPSOpen.beforeClass, I get
java.lang.IllegalStateException: Could not find a display
at org.eclipse.swtbot.swt.finder.utils.SWTUtils.display(SWTUtil s.java:249)
at org.eclipse.swtbot.swt.finder.finders.ControlFinder.<init>(ControlFinder.java:82)
at org.eclipse.swtbot.swt.finder.finders.ControlFinder.<init>(ControlFinder.java:72)
at org.eclipse.swtbot.swt.finder.SWTBot.<init>(SWTBot.java:106)
at org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot.<init>(SWTWorkbenchBot.java:56)
at test.PPSOpen.beforeClass(PPSOpen.java:28)
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:597)
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.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.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.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
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.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:49)
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.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:197)



I run the following as a junit test
I have AllTests.java

package test;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
PPSOpen.class,
OtherTests.class,
PPSClose.class,
})
public class AllTests {

} // AllTests

PPSOpen.java

package test;

import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive ;


public class PPSOpen
{
private static SWTWorkbenchBot bot = null;

public static SWTWorkbenchBot getBot()
{
return bot;
}

@Before
public void beforeClass() throws Exception {
// bot = new SWTWorkbenchBot();
}

@Test(timeout=6000)
public void initPPS()
{
try
{
PPS.main(new String[] { });
}
catch (Exception e)
{
e.printStackTrace();
fail("initialize PPS failed");
}

//ICondition waitForWidget = shellIsActive("PPS");
// bot.waitUntilWidgetAppears(waitForWidget);
}

@Test
public void getPPS()
{
PPS pps = Setup.getPps();
assertNotNull("PPS is null", pps);
}
}

and PPSClose.java

package test;

import org.junit.* ;


public class PPSClose
{
@Test
public void closePPS()
{
PPS.getDisplay().syncExec(new Runnable() {
@Override
public void run()
{
PPS pps = Setup.getPps();
assertTrue(pps != null);
pps.close();
}

});
}
}
Re: SWT standalone newbie question [message #634789 is a reply to message #634237] Sat, 23 October 2010 15:17 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
See SWTBotApplicationLauncherClassRunner: http://goo.gl/g4ae

Also you'd need to use SWTBot class and not SWTWorkbenchBot for SWT only
tests. SWTWorkbenchBot is for eclipse based tests.

--
Ketan
ketan.padegaonkar.name | eclipse.org/swtbot | @ketanpkr

On 10/20/10 2:55 PM, Keith Willenson wrote:
> I am trying to test my standalone application with SWTBot. I can start
> an Eclipse workbench (using the plugin example), but there is nothing in
> it. I thought about loading my application, but decided there must be an
> easier way. Please let me know if I am wrong. I can run junit4 tests,
> but I can not get an SWTBot to see my applicaiton. So what do I need to
> do to get the junit tests and SWTBot together? I am using Eclipse Helios
> 3.6, version 2.0.0.595-dev-e36 of SWTBot, and junit4.
>
> When I uncomment the bot in PPSOpen.beforeClass, I get
> java.lang.IllegalStateException: Could not find a display
> at org.eclipse.swtbot.swt.finder.utils.SWTUtils.display(SWTUtil s.java:249)
> at
> org.eclipse.swtbot.swt.finder.finders.ControlFinder.<init>(ControlFinder.java:82)
>
> at
> org.eclipse.swtbot.swt.finder.finders.ControlFinder.<init>(ControlFinder.java:72)
>
> at org.eclipse.swtbot.swt.finder.SWTBot.<init>(SWTBot.java:106)
> at
> org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot.<init>(SWTWorkbenchBot.java:56)
>
> at test.PPSOpen.beforeClass(PPSOpen.java:28)
> 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:597)
> 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.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:76)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.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.junit.runners.Suite.runChild(Suite.java:128)
> at org.junit.runners.Suite.runChild(Suite.java:24)
> 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.jdt.internal.junit4.runner.JUnit4TestReference.r
> un(JUnit4TestReference.java:49)
> 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.jdt.internal.junit.runner.RemoteTestRunner.main(
> RemoteTestRunner.java:197)
>
>
>
> I run the following as a junit test
> I have AllTests.java
>
> package test;
>
> import org.junit.runner.RunWith;
> import org.junit.runners.Suite;
>
> @RunWith(Suite.class)
> @Suite.SuiteClasses({
> PPSOpen.class,
> OtherTests.class,
> PPSClose.class,
> })
> public class AllTests {
>
> } // AllTests
>
> PPSOpen.java
>
> package test;
>
> import static
> org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive ;
>
>
> public class PPSOpen
> { private static SWTWorkbenchBot bot = null;
>
> public static SWTWorkbenchBot getBot()
> {
> return bot; }
>
> @Before
> public void beforeClass() throws Exception {
> // bot = new SWTWorkbenchBot();
> }
>
> @Test(timeout=6000)
> public void initPPS()
> {
> try
> {
> PPS.main(new String[] { });
> }
> catch (Exception e)
> {
> e.printStackTrace();
> fail("initialize PPS failed");
> }
>
> //ICondition waitForWidget = shellIsActive("PPS");
> // bot.waitUntilWidgetAppears(waitForWidget);
> }
>
> @Test
> public void getPPS()
> {
> PPS pps = Setup.getPps();
> assertNotNull("PPS is null", pps);
> }
> }
>
> and PPSClose.java
>
> package test;
>
> import org.junit.* ;
>
>
> public class PPSClose
> { @Test
> public void closePPS()
> {
> PPS.getDisplay().syncExec(new Runnable() {
> @Override
> public void run()
> {
> PPS pps = Setup.getPps();
> assertTrue(pps != null);
> pps.close();
> }
>
> });
> }
> }
>
Re: SWT standalone newbie question [message #636695 is a reply to message #634789] Tue, 02 November 2010 13:41 Go to previous message
Keith Willenson is currently offline Keith WillensonFriend
Messages: 21
Registered: July 2009
Junior Member
Thank you very much for your help. I was confused about what to do because I develop in Eclipse, so SWTWorkbenchBot seemed like the right thing to use. The example code for SWTBotApplicationLauncher should be updated to:

import org.eclipse.swtbot.swt.finder.junit.SWTBotApplicationLaunche rClassRunner;

public class FooApplicationTestClassRunner extends SWTBotApplicationLauncherClassRunner
{
public FooApplicationTestClassRunner(Class<?> klass) throws Exception
{
super(klass);
}


@Override
public void startApplication()
{
Foo.main(new String[] { "arguments", "to", "your application" });
}
}
Previous Topic:when to use syncExec?
Next Topic:Need help configuring my target platform for SWTBot
Goto Forum:
  


Current Time: Thu Apr 25 08:25:29 GMT 2024

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

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

Back to the top