Ship It! LIVEShip It! LIVE
home about services writing contact

We develop, test, and create fine software products, and design creative solutions to your problems.
The development of software is an intrinsically creative process. We are dedicated to improving our mastery of the art.
Links · RSS Feed
Popular Pages

..."Ship It!" is in the style of the other Pragmatic books and is an easy and focused read. I finished it in two days and have already gained a wealth of insight that I can apply immediately. Hig...
-Anil John
Ship It! is part manual of best practices, part software methodologies book and part a distillation of ideas and experiences of good and bad projects that the authors have been involved in. It migh...
-Tech Book Report
I was amazed that these five chapters only take about 160 pages and yet tell you all you need to know about successful projects. I’ve experienced a lot of these problems myself, and so did/do you, ...
-Javaddicts.net

Running Selenium on an Alternate Port; Starting the Server from Ant (Dec 8)
I found myself needing to run Selenium tests from Java against a Selenium server running on a port other than the default 4444. Every example on the web showed me almost the right way to configure this from within JUnit... so now that I've got it working, I'm documenting it. :)

public void setUp() throws Exception {
    // this is the normal way
    // setUp(server_url, "*chrome");

    // this is the alternate port way
    selenium = new DefaultSelenium("localhost", 11111, "*firefox", server_url );
    selenium.start();
}

Hopefully this will save a few others some time!

Free Bonus Tip

Here's how to start and stop the Selenium server from an Ant script.

    <target name="start_server" description="Starts a Selenium Server in the background">
        <java jar="${lib}/selenium-server.jar" fork="true" spawn="true"/>
    </target>
	
    <target name="stop_server" description="Stops your local Selenium Server">
        <get taskname="selenium-shutdown" 
           src="http://localhost:4444/selenium-server/driver/?cmd=shutDown" 
           dest="result.txt" 
           ignoreerrors="true" />
    </target>

Update

The above Ant script worked for me on Linux, but seems to not work on Windows. (sigh).

Change the arg from value= to line= and it's now working on Windows.

<java jar="${lib}/selenium-server.jar" fork="true" spawn="true" >
    <arg line="-port 4444"/>
</java>

I've also found this useful.

<waitfor maxwait="30" maxwaitunit="second">
    <socket server="localhost" port="${selenium.server.port}"/>
</waitfor>

Category: Java


© 2007 Agile Artisans.