Tips for Functional Tests with Selenium

With more and more UI being rendered and processed dynamically with JavaScript, in-browser testing has become a requirement for functional testing. Selenium is a popular choice for implementing tests that execute within the context of a browser but are still Java-driven. This page gives you tips for using Selenium to test your plugin.

Add atlassian-selenium-browsers-auto to your pom.xml

Add this XML to the <dependencies> section in your pom.xml:


You should verify the <version> value is the latest by searching for the <groupId> in Atlassian's Maven repository. 

Write a Selenium test

The Atlassian Plugin SDK comes with support for integration/functional tests that will run with the target Atlassian application started and your plugin installed. You just have to create one or more tests in the src/test/java/it directory. The convention is if your code is in the com.mycompany.myplugin package, your integration tests would be in the package or src/test/java/it/com/mycompany/myplugin directory.

To use Selenium in these tests, the atlassian-selenium-browsers-auto artifact provides a few static helper methods. These methods, when used for the first time:

  1. Detect your operating system
  2. Install the appropriate browser (FireFox 3.5 is the default) for your OS in target/seleniumTmp
  3. If Linux and xfvb.enable is set to true, start Xvfb on an open DISPLAY detected automatically
  4. Start the Selenium server
  5. Start the newly installed browser

This all happens in the background, so you should just be able to focus on your test.

Here is a simple test that hits the home page and looks for the text of "Hello world":

import com.atlassian.selenium.SeleniumClient;
import static com.atlassian.selenium.browsers.AutoInstallClient.assertThat;
import static com.atlassian.selenium.browsers.AutoInstallClient.seleniumClient;
public class TestHelloWorld extends TestCase
    public void testHelloWorld() throws Exception
        SeleniumClient client = seleniumClient();"/");
        assertThat().textPresent("Hello world");

Specify a Browser

If you want to specify a browser other than Firefox 3.5, you can do so by specifying the selenium.browser system property in your atlassian-<product>-plugin configuration. For example:

          <selenium.browser>firefox-3.6</selenium.browser> <!-- also available chrome-6 and chrome-7 -->

You can find out what strings are valid by looking at the com.atlassian.browsers.BrowserVersion.


Writing and Running Plugin Tests

Was this page helpful?
Powered by Confluence and Scroll Viewport