Java Reference
In-Depth Information
22:14:11.554 INFO - Started HttpContext[/selenium-server,/selenium-server]
22:14:11.554 INFO - Started HttpContext[/,/]
22:14:11.570 INFO - Started SocketListener on 0.0.0.0:4444
22:14:11.585 INFO - Started org.mortbay.jetty.Server@109a4c
You're now ready to run tests. When you run tests, you'll see two browser windows
open and close. The first will contain the tested application; the second will display
commands sent to the browser and log entries if you have logging enabled.
If you're building with Ant or Maven, you can manage the lifecycle of the Sele-
nium server from these tools. We recommend that you manage the server from the
test class or suite directly, as we show next. This allows you, as a developer, to run
the tests directly from the command line or an IDE like Eclipse.
12.7.2
Running Selenium tests with JUnit 4
The Selenium requirement for JU nit is version 3; as of Selenium version 1.0 Beta 2,
there's no out-of-the-box integration with JU nit 4. This is a problem because the
performance associated with a default SeleneseTestCase is bad; JU nit starts and
stops a browser around each test method invocation through the setUp and tear-
Down methods.
We present a two-stage solution to this problem by first managing a server for all
test methods in a given class and then managing a server for all classes in a test suite.
To do so, you'll need to add the server JAR file to your classpath, for example, sele-
nium-remote-control-1.0-beta-2\selenium-server-1.0-beta-2\selenium-server.jar.
In our first solution, JU nit starts and stops the server once per class run in the
@BeforeClass and @AfterClass methods, as listing 12.14 demonstrates.
Listing 12.14
Managing the Selenium server from a test
[...]
public class ManagedSeleniumServer {
protected static Selenium selenium;
B
C
private static SeleniumServer seleniumServer;
@BeforeClass
public static void setUpOnce() throws Exception {
startSeleniumServer();
startSeleniumClient();
}
D
public static void startSeleniumClient() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",
" http://www.google.com/");
selenium.start();
}
public static void startSeleniumServer() throws Exception {
seleniumServer = new SeleniumServer();
seleniumServer.start();
}
 
 
 
 
 
 
Search WWH ::




Custom Search