New page: == Overview == 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...
New page
== Overview ==
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.
<pre>
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')]";
@Test
public void testSubversionScm() {
Selenium selenium = getSelenium();
selenium.open("/");
waitForTextPresent("New Job");
selenium.click("link=New Job");
selenium.waitForPageToLoad("30000");
selenium.type("name", "subversion-plugin");
selenium.click("mode");
selenium.click("//button[@type='button']");
selenium.waitForPageToLoad("30000");
selenium.click(SUBVERSION_LBL_SELECT_EXP);
selenium.type("svn.remote.loc", "https://svn.java.net/svn/hudson~svn/trunk/hudson/plugins/subversion");
selenium.click("//span[@id='yui-gen2']/span/button");
selenium.click("link=Invoke top-level Maven targets");
selenium.type("textarea._.targets", "clean install -DskipTests");
selenium.click("//span[@id='yui-gen19']/span/button");
selenium.waitForPageToLoad("30000");
selenium.click("link=Build Now");
selenium.waitForPageToLoad("30000");
selenium.open("/job/subversion-plugin/1/console");
waitForTextPresent(BUILD_SUCCESS_TEXT, BUILD_FAILURE_TEXT);
}
}
</pre>
== Useful commands ==
* Run all UI tests: <code>mvn clean verify -P integration-tests</code>
* Run single test: <code>mvn clean -Dit.test=ConfigureHudsonIT verify -P integration-tests</code>
* Debug: <code>mvn -Dmaven.failsafe.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000 -Xnoagent -Djava.compiler=NONE" clean verify -P integration-tests</code>
== TODO ==
*Improve the documentation