Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Display Creation Problem in User Guide
Display Creation Problem in User Guide [message #4882] Tue, 25 November 2008 22:34 Go to next message
Jeff Winkler is currently offline Jeff WinklerFriend
Messages: 2
Registered: July 2009
Junior Member
Hi-
There seems to be a problem in the idiom shown on
http://swtbot.sourceforge.net/users-guide.html:

public class FooBarTest extends SWTBotTestCase {
static {
startApplicationInAnotherThread();
}
protected void setUp() throws Exception {
super.setUp();
waitForDisplayToAppear(5000); // wait for the display to appear
before you do anything
}

I was getting intermittent successes and failures including widget not
found, and:

junit.framework.AssertionFailedError: Exception in constructor:
testClickCancel (java.lang.IllegalStateException: Could not find a display
at net.sf.swtbot.utils.SWTUtils.display(SWTUtils.java:241)
at net.sf.swtbot.finder.ControlFinder.<init>(ControlFinder.java:82)
at net.sf.swtbot.finder.ControlFinder.<init>(ControlFinder.java:72)
at net.sf.swtbot.SWTBotFactory.<init>(SWTBotFactory.java:71)
at net.sf.swtbot.SWTBot.<init>(SWTBot.java:82)
at net.sf.swtbot.SWTBotTestCase.<init>(SWTBotTestCase.java:40)
at org.eclipse.swt.snippets.Snippet108Test.<init>(Snippet108Test.java:9)


Problem: setUp() is too late to call waitForDisplayToAppear()... the
SWTBot ctor invoked by SWTBotTestCase ctor needs a Display, and the
other thread may not have created one yet.

Waiting in the static section solves the problem:

public class Snippet108Test extends SWTBotTestCase {
static {
startAppIntoAnotherThread();
try {
waitForDisplayToAppear(5000); // wait for the display before you do
anything.
} catch (TimeoutException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

Do you agree?

Also, I was doubting my sanity when the widgets weren't found, so
adapted some code I had around to dump widgets to text. For
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet108.java?view=co
The output looks like this:

Shell 'Snippet108' @1680,47 size 411,60 RowLayout
Label 'Enter your name:' @3,3 size 111,15
Text '' @117,3 size 110,25
Button 'OK was clicked!' @230,3 size 110,27
Button 'Cancel' @343,3 size 55,27

It's just a starting point, but could see it being very useful to dump
the widget hierarchy to text for postmortems if a Match fails due to a
typo or GUI change. Please let me know if you're interested.

Regards,
Jeff Winkler
Re: Display Creation Problem in User Guide [message #4950 is a reply to message #4882] Wed, 26 November 2008 10:12 Go to previous message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Hi Jeff,

Thanks for pointing out. Yes, that example is a bit flaky at times. This
was brought out on the SWTBot mailing list a while ago.

Your workaround and solution is also correct. You could also look
through the thread at
http://www.nabble.com/Hit-a-BUg-in-SWTBot-2.0-tt19990466.htm l#a20047323
for more info on this.

The example was merely to demonstrate how you can set things up the
'quick and dirty' way. You'd probably want to do something different in
the long run.

I'm also exploring ways make the SWTBot.display() a bit
more redundant by adding a waitFor() condition, so that it does not
crash out.

-- Ketan

On 26/11/08 04:04, Jeff Winkler wrote:
> Hi-
> There seems to be a problem in the idiom shown on
> http://swtbot.sourceforge.net/users-guide.html:
>
> public class FooBarTest extends SWTBotTestCase {
> static {
> startApplicationInAnotherThread();
> }
> protected void setUp() throws Exception {
> super.setUp();
> waitForDisplayToAppear(5000); // wait for the display to appear before
> you do anything
> }
>
> I was getting intermittent successes and failures including widget not
> found, and:
>
> junit.framework.AssertionFailedError: Exception in constructor:
> testClickCancel (java.lang.IllegalStateException: Could not find a display
> at net.sf.swtbot.utils.SWTUtils.display(SWTUtils.java:241)
> at net.sf.swtbot.finder.ControlFinder.<init>(ControlFinder.java:82)
> at net.sf.swtbot.finder.ControlFinder.<init>(ControlFinder.java:72)
> at net.sf.swtbot.SWTBotFactory.<init>(SWTBotFactory.java:71)
> at net.sf.swtbot.SWTBot.<init>(SWTBot.java:82)
> at net.sf.swtbot.SWTBotTestCase.<init>(SWTBotTestCase.java:40)
> at org.eclipse.swt.snippets.Snippet108Test.<init>(Snippet108Test.java:9)
>
>
> Problem: setUp() is too late to call waitForDisplayToAppear()... the
> SWTBot ctor invoked by SWTBotTestCase ctor needs a Display, and the
> other thread may not have created one yet.
>
> Waiting in the static section solves the problem:
>
> public class Snippet108Test extends SWTBotTestCase {
> static {
> startAppIntoAnotherThread();
> try {
> waitForDisplayToAppear(5000); // wait for the display before you do
> anything.
> } catch (TimeoutException e) {
> e.printStackTrace();
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> }
>
> Do you agree?
>
> Also, I was doubting my sanity when the widgets weren't found, so
> adapted some code I had around to dump widgets to text. For
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet108.java?view=co
> The output looks like this:
>
> Shell 'Snippet108' @1680,47 size 411,60 RowLayout
> Label 'Enter your name:' @3,3 size 111,15
> Text '' @117,3 size 110,25
> Button 'OK was clicked!' @230,3 size 110,27
> Button 'Cancel' @343,3 size 55,27
>
> It's just a starting point, but could see it being very useful to dump
> the widget hierarchy to text for postmortems if a Match fails due to a
> typo or GUI change. Please let me know if you're interested.
>
> Regards,
> Jeff Winkler
Previous Topic:SWTBot Creation Review
Next Topic:Update on SWTBot moving to eclipse.org!
Goto Forum:
  


Current Time: Sun Sep 19 11:54:55 GMT 2021

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

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

Back to the top