Quick Tutorial: Netbeans + Selenium + Hudson

Selenium is one of the most powerful web application test tool I know. It supports a wide range of Browsers, Operating Systems, Languages and Test Frameworks (find all infos here). It takes a while to learn all the commands in the API that you can use to test your web application, fortunately there are some plugins  that help you to get started. Although I found it confusing to get started with Netbeans and Hudson, each having its own plugin, plus Firefox also offering a plugin, and some websites and tutorials leading in different directions (if you are in hurry like me).

This short tutorial walks you through the steps to get started in a few minutes.


  • A CI or build-server is usually headless, means there is no desktop, no Gnome, no GUI, so would not be possible for Selenium to start and control a browser. This tutorial assumes you run a build-server with desktop. At a later stage we will discuss the headless testing.
  • In this tutorial we will implement a simple JSP web application with 2 pages and create a JUnit test triggering the Selenium Test.
  • The Netbeans plugin and Hudson plugin for Selenium is not required for this tutorial.
  • The tutorial is created with Ubuntu as OS (Windows should be similar)


  • Netbeans 6.8 (earlier versions certainly work as well)
  • Glassfish
    A local Glassfish that comes with Netbeans is good enough.
  • Hudson Server
    Download the war file from here. For the tutorial we will use a local standalone Hudson server.
  • Selenium RC
    Download from here.
  • Sourcecode Repository (SVN)
    In order to use Hudson, it is recommended to have a sourcecode repository like SVN to upload the code.


  • Create a new Web Application
    Call it WebApplSelenium, store all libraries in local folder, no frameworks.

    New Web Application

    New Web Application

    New Web Application

  • Implement 2 JSP Pages
    Lets create 2 pages, on the first pages a simple form with 2 entries and the second page will echo back the entries.simpleform.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>JSP DEMO</title>
     <h1>Sample entries:</h1>
     <%-- Call another JSP file on submit--%>
     <form action="simpleresult.jsp">
     Name: <input type="text" name="yourName" value="" /><BR>
     Age: <input type="text" name="yourAge" value="" /><BR>
     <input type="submit" value="Send" />


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>JSP Demo</title>
     <h1>Values from previous form:</h1>
     <%-- JSP Expression --%>
     <%= request.getParameter("yourName") %><br>
     <%= request.getParameter("yourAge") %>
  • Deploy and Run the Web Application

    Run the Web Application

  • Add the Selenium Client Driver
    Unzip the file that you downloaded from selenioumhq.org earlier.
    Add the client driver to the Web project (selenium-java-client-driver.jar)

    Selenium RC Directory

    Project Properties

  • Create a Test Class
    Right Click on Test Packages | Create Java Class (We dont need to use the tools.. to cretae JUnit test)

    package webtest;
    import com.thoughtworks.selenium.*;
    import org.junit.*;
    public class simpleFormTest {
     static private String appServerURL = "http://vcb3:8080/";
     public void testSimple() throws Exception {
     Selenium selBrowser = new DefaultSelenium("localhost", 4444, "*firefox", appServerURL);
     // optional to make it visible/slower:
     // selenium.setSpeed("500");
     selBrowser.type("fullname", "bla1");
     selBrowser.type("age", "99");
     selBrowser.click("//input[@value='Press me']");
     // optional for slower pages (?):
     // selBrowser.waitForPageToLoad("3000");
     Assert.assertTrue(selBrowser.isTextPresent("bla1, 99"));
  • Start the Selenium RC Server
    Open a shell and navigate to the  Selenium Server path (see above directory structure) and start the server
    java -jar selenium-server.jar

    Running Selenium RC Server

    Now we have a Selenium Server running and listening on port 4444.
    Warning: If you installed the Netbeans plugin for Selenium, it will auto-install and autostart a Selenium Server. In that case either stop it or use it.

  • Run the Test locally
    Select Test file (slect the test class in the project browser). Execute JUnit tests for the project might be disabled.
    Warning: Our JUnit test is not fully linked with our project yet. We need to deploy the application first before triggering the test (or activate deploy on save).

    Running Selenium Test

    Test Result

  • Start Hudson
    Navigate to the path of the hudson.war file you downloaded earlier and start it. Note the default port is 8080, it will create a conflict if you start it on the same box as Glassfish.
    java -jar hudson.war –httpPort=7080

    Start Hudson (standalone)

  • Create a Hudson Job and execute it
    (I skip this part for now because it would be a repetition to the previous tutorial here)
    Note: You need apply the same changes to your build.xml and project properties to get the build executed.

    Hudson will execute our test script and trigger Selenium to open the browser for testing.
    Test will be successful.

     [junit] Testsuite: webtest.NewSeleneseTest
     [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 8.329 sec


  • Download and install the Firefox Selenium IDE from here.
  • Open the IDE in Firefox (tools|Selenium), open the URL of the web application and start performing the inputs and user activities that shall be replayed in out test.

    Recording Selenium Test

  • Change the the clipboard format to Java (JUnit) (Options|Clipboard Format), select the commands from the list and copy. Paste into the respective test class in our project.
    selenium.type("yourName", "someName");
    selenium.type("yourAge", "75");
  • You have the option to export the complete java text class from the Selenium IDE but we wont need that since we implemented out test skeleton already.

Open Issues:

  • The triggered JUnit test is executing a test with an already deployed web application, it is actually required to perform a build-deploy-test sequence. The optional Hudson plugin to deploy war files does not help because it will deploy at the en of a build/test job.
  • Execute the build and test on a headless server.

5 thoughts on “Quick Tutorial: Netbeans + Selenium + Hudson

  1. Pingback: Quick Tutorial: Netbeans + Selenium + Hudson (Part 2) « The JavaDude Weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s