The @Managed
annotation also lets you specify what driver you want to use for a particular test case, via the driver
attribute. Current supported values are “firefox”, “iexplorer”, “chrome” and “htmlunit”. The driver
attribute 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"); } }
In easyb, you can use the uses_driver
directive, as shown here:
using "thucydides" ... thucydides.uses_default_base_url "http://localhost:9000" thucydides.uses_driver chrome ... scenario "The administrator adds a new category to the system", { given "a new category needs to be added to the system", { administrator.logs_in_to_admin_page_if_first_time() administrator.opens_categories_list() } when "the administrator adds a new category", { administrator.selects_add_category() administrator.adds_new_category("Scala Developers","SCALA") } then "the system should confirm that the category has been created", { administrator.should_see_confirmation_message "The Category has been created" } and "the new category should be visible to job seekers", { job_seeker.opens_jobs_page() job_seeker.should_see_job_category "Scala Developers" } }
In JUnit, 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"); }