Skip to main content
Jump to: navigation, search

Writing UI integration tests for your plugin


Hudson uses UI integration tests to verify functionality from end-user perspective. Tests developed based on jUnit and Webdriver + Selenium frameworks. Currently all of the UI tests are located in the hudson-test-ui module which is available in integration-tests profile. The Maven pom in hudson-test-ui is configured to start Hudson web application in an embedded jetty container and then to run jUnit test suites. Tests can use either Selenium or WebDriver commands to emulate end-user work. It's possible to use Selenium IDE to record a draft selenium script and then export it into jUnit test. We are using Failsafe plugin instead of Surefire plugin because it was created to run integration tests and it always tears down the test environment correctly. Example

The following code shows a very simple test case: user creates new free-style job, configures subversion repository, specifies maven goals and starts the build.

The test extends from BaseUITest which contains additional methods for UI verification.

package org.hudsonci.test.ui;

import com.thoughtworks.selenium.Selenium;
import org.junit.Test;
import org.openqa.selenium.By;

public class FreestyleJobTest extends BaseUITest {

    private static final String BUILD_SUCCESS_TEXT = "Finished: SUCCESS";
    private static final String BUILD_FAILURE_TEXT = "Finished: FAILURE";

    private static final String SUBVERSION_LBL_SELECT_EXP = "//label[contains(text(),'Subversion')]";
    private static final String GIT_LBL_SELECT_EXP = "//label[contains(text(),'Git')]";
    private static final String CVS_LBL_SELECT_EXP = "//label[contains(text(),'CVS')]";

    public void testSubversionScm() {
        Selenium selenium = getSelenium();"/");
        waitForTextPresent("New Job");"link=New Job");
        selenium.type("name", "subversion-plugin");"mode");"//button[@type='button']");
        selenium.type("svn.remote.loc", "");"//span[@id='yui-gen2']/span/button");"link=Invoke top-level Maven targets");
        selenium.type("textarea._.targets", "clean install -DskipTests");"//span[@id='yui-gen19']/span/button");
        selenium.waitForPageToLoad("30000");"link=Build Now");

Useful commands

  • Run all UI tests: mvn clean verify -P integration-tests
  • Run single test: mvn clean -Dit.test=ConfigureHudsonIT verify -P integration-tests
  • Debug: mvn -Dmaven.failsafe.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000 -Xnoagent -Djava.compiler=NONE" clean verify -P integration-tests


  • Improve the documentation

Back to the top