Quick Tutorial: Netbeans + Selenium + Hudson (Part 2)

In part 1 of this tutorial (I recommend to walk through it first) we created a simple web application, set up a Hudson server to build it and test it with Selenium. But we left with one major flaw: Hudson build the war file, but the JUnit test the job triggered was tesing an application already deployed to a Glassfish instance. Today we wipe out this problem, setting up a proper sequence of building, deploying and testing the application.

Pre-Requirements (same as in part 1):

  • Netbeans 6.9 (earlier versions certainly work as well)
  • Glassfish
    A local Glassfish that comes with Netbeans is good enough. I am using a Glassfish 3.0.1 running in a VirtualBox.
  • 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.


  • Lets look at the existing Hudson job

    Hudson Job

    It is the default job, update the sourcecode from SVN and trigger the ANT build. If we dont specifiy a target it will run the default target from your build.xml file

     <target depends="test,dist,javadoc" description="Build whole project." name="default"/>

    (it overrides the default target from build-impl.xml that does not contain the test dependency)

  • Modify the Hudson Job
    We change the job to a 3 step job:
    1. Build it using the target dist.
    2. Deploy with asadmin to the local (or remote) Glassfish
    3. Run the test target

    Modified Hudson Job


    • The host running Hudson must have a local Glassfish installation (even you deploy to a remote/virtual host), because you use the local asadmin tool to deploy the war file.
    • You need also a local file containing the admin password
      AS_ADMIN_MASTERPASSWORD=yyyyyy (optional)
    • The complete deployment command
      {glassfish_path}/bin/asadmin --host {gf_server} --user {admin}  --passwordfile {path}/{pw_file} deploy --force {webappl}.war
    • I recommend having a sleep command after the deployment to avoid trying to test the application, even it is not fully deployed.
  • Run the modified Hudson Job
    Should result in something similar to this

    Started by user hudson
    Updating https://xxxxxx.svn.xxxxxx.com/playground/TEST_WebAppTestSelenium
    At revision 131
    no change for https://xxxxxx.svn.xxxxxx.com/playground/TEST_WebAppTestSelenium since the previous build
    [TEST_WebAppTestSelenium] $ /var/lib/hudson/tools/ANT/bin/ant dist
    Buildfile: /var/lib/hudson/jobs/TEST Selenium/workspace/TEST_WebAppTestSelenium/build.xml
    Total time: 0 seconds
    [workspace] $ /bin/sh -xe /tmp/hudson3769812188754918086.sh
    + echo /var/lib/hudson/jobs/TEST Selenium/workspace
    + cd TEST_WebAppTestSelenium/dist
    + /home/user/glassfishv3rel/bin/asadmin --host vcb3 --user aadmin --passwordfile /home/user/glassfishv3rel/bin/GFP.txt deploy --force TEST_WebAppTestSelenium.war
    Application deployed successfully with name TEST_WebAppTestSelenium.
    Command deploy executed successfully.
    + sleep 5
    [TEST_WebAppTestSelenium] $ /var/lib/hudson/tools/ANT/bin/ant test
    Buildfile: /var/lib/hudson/jobs/TEST Selenium/workspace/TEST_WebAppTestSelenium/build.xml
     [junit] Testsuite: webtest.NewSeleneseTest
     [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 7.175 sec
    Total time: 8 seconds
    Finished: SUCCESS

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