Over a million developers have joined DZone.

Running Selenium on an Alternate Port; Starting the Server from Ant

DZone's Guide to

Running Selenium on an Alternate Port; Starting the Server from Ant

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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 );

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 name="stop_server" description="Stops your local Selenium Server">
<get taskname="selenium-shutdown"
ignoreerrors="true" />


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" >
&ltarg line="-port 4444"/>

I've also found this useful.

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

From http://agileartisans.com

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}