Skip to main content

Thucydides Release 0.4.26 – HTMLUnit support, and using different drivers in the same test case

Posted by johnsmart on November 15, 2011 at 2:10 AM PST

Thucydides 0.4.26 has just been released. Some of the new features in this release include HTMLUnit support and the ability to specify the browser you want to run tests in at both the test case and the individual test level, as well as a few bug fixes and under-the-hood improvements.

Thucydides is an open source library designed to make writing and reporting on automated acceptance tests, in particular web-based acceptance tests using WebDriver/Selenium 2.

HtmlUnit support

You can now run tests in HTMLUnit, in addition to Firefox, Chrome and Internet Explorer. HTMLUnit is a fast, browserless driver that . The main advantage of HTMLUnit is speed - it will run much faster than any of the browser-based drivers. However HTMLUnit is not without it's disadvantages. Firstly, since HTMLUnit does not open a browser, tests run in HTMLUnit will not have screenshots (although the HTML source code for each page is stored), which limits its value for ATDD reporting. And secondly, although HTMLUnit does have some Javascript support, it does not fully match the behaviour of a real browser. Nevertheless, there are times when you prefer fast, more low-level tests, and in this case HTMLUnit can be a useful option. To activate HTMLUnit, just provide "htmlunit" as the webdriver.driver system property, or define the driver for a test case or test as described in the following section.

Test-specific driver support

The @Managed annotation now supports the driver attribute, which lets you specify what driver you want to use for a particular test case. Current supported values are "firefox", "iexplorer", "chrome" and "htmlunit". This lets you override the system-level default driver for specific requirements. For example, the following test case will run in Chrome, regardless of the webdriver.driver system property value used:

@RunWith(ThucydidesRunner.class)
@Story(Application.Search.SearchByKeyword.class)
public class SearchByFoodKeywordStoryTest {

    @Managed(uniqueSession = true, driver="chrome")
    public WebDriver webdriver;

    @ManagedPages(defaultUrl = "http://www.google.co.nz")
    public Pages pages;

    @Steps
    public EndUserSteps endUser;

    @Test
    public void searching_by_keyword_pears_should_display_the_corresponding_article() {
        endUser.is_the_google_home_page();
endUser.enters("pears");
        endUser.starts_search();
endUser.should_see_article_with_title_containing("Pear");
    }

    @Test
    @WithDriver("firefox")
    public void searching_by_keyword_pineapples_should_display_the_corresponding_article() {
        endUser.is_the_google_home_page();
endUser.enters("pineapples");
        endUser.starts_search();
        endUser.should_see_article_with_title_containing("Pineapple");
    }
}

 

You can also use the @WithDriver annotation to specify a driver for an individual test. This will override both the system-level driver and the @Managed annotation's driver attribute, if provided. For example, the following test will always run in Firefox:

	@Test
@WithDriver("firefox")
public void searching_by_keyword_pineapples_should_display_the_corresponding_article() {
    endUser.is_the_google_home_page();
    endUser.enters("pineapples");
    endUser.starts_search();
    endUser.should_see_article_with_title_containing("Pineapple");
}

 

Related Topics >>

Comments

Is it still necessary to install ChromeDriver or should it ...

Is it still necessary to install ChromeDriver or should it work out of the box?