Jump to: navigation, search

Difference between revisions of "SWTBot/FAQ"

(How do I configure log4j to turn on logging for SWTBot?)
m
Line 48: Line 48:
  
 
SWT does not have support to recognize native dialogs, and SWTBot therefore cannot test them. See [https://bugs.eclipse.org/bugs/show_bug.cgi?id=164192 eclipse bug #164191] for more info. Consider adding a comment and a vote on that bug as well.
 
SWT does not have support to recognize native dialogs, and SWTBot therefore cannot test them. See [https://bugs.eclipse.org/bugs/show_bug.cgi?id=164192 eclipse bug #164191] for more info. Consider adding a comment and a vote on that bug as well.
 +
 +
[[Category:SWTBot]] [[Category:Eclipse Project]] [[Category:FAQ]]

Revision as of 23:39, 7 December 2008

FAQ

Why do tests run on a non-UI thread?

A lot of events that SWTBot sends to the UI are blocking. SWT dialogs are one of them. This means that functions opening dialogs, will block until the dialog closes. Since we do not want tests to block when a dialog open up, SWTBot runs in a non-UI thread, and posts events to the UI thread.

There are two solutions to this:

  1. Make the dialog non-modal, by invoking Dialog#setBlockOnOpen(false)
  2. Open the dialog in a non-ui thread

SWTBot chooses the later approach, since the first approach is not always practical.

Why do I have to run tests as SWTBot tests, instead of PDE-JUnit tests?

PDE-Junit tests run on the UI thread. SWTBot needs that tests run on a non-UI thread, hence a new run configuration. See #Why do tests run on a non-UI thread? for more info.

Can I slow down the execution speed of SWTBot tests?

Yes you can! To slow down the speed of execution of SWTBot, you need to set the system property "net.sf.swtbot.playback.delay". This delay is in milliseconds. You can also set this property in code as follows:

System.setProperty("net.sf.swtbot.playback.delay", "10");
// do something
System.setProperty("net.sf.swtbot.playback.delay", "0");

Can I change the timeout for execution of SWTBot tests?

Yes you can! To change the timeout, you need to set the system property "net.sf.swtbot.search.timeout". The timeout is specified in milliseconds. You can also set this property in code as follows:

System.setProperty("net.sf.swtbot.search.timeout", "10000");
// do something
System.setProperty("net.sf.swtbot.search.timeout", "5000");

How do I configure log4j to turn on logging for SWTBot?

Copy the file http://swtbot.svn.sourceforge.net/svnroot/swtbot/trunk/net.sf.swtbot.finder.test/src/log4j.xml to the src directory in your plugin. Ensure that the plugin's MANIFEST.MF contains the following lines, note the dependency on org.apache.log4j

Require-Bundle: com.example.foo,
 org.apache.log4j
Eclipse-RegisterBuddy: org.apache.log4j	

If you still get the message:

log4j:WARN No appenders could be found for logger (net.sf.swtbot.matcher.WidgetMatcherFactory$MenuMatcher).
log4j:WARN Please initialize the log4j system properly.

Then there's something else not right. Drop an email on the mailing list.

How do I use SWTBot to test native dialogs (File Dialogs, Color Dialogs, etc)?

You can't! Very unfortunate but true.

SWT does not have support to recognize native dialogs, and SWTBot therefore cannot test them. See eclipse bug #164191 for more info. Consider adding a comment and a vote on that bug as well.