browsers

In order to run a test in a browser, that browser must be present on the computer running that test. For example if you have Internet Explorer 9 and you run an Internet Explorer test class, the test will execute in your installed version of Internet Explorer. For browsers like Firefox that allow you to have multiple installations on the same computer, it is possible to specify the exact executable to use as a part of the properties configuration.

Chrome

This library comes with the Chrome Web Driver used for Chrome on 32-bit Windows, but you can download any one you want from the project website here. To change the web driver in use, you just have to modify the location specified in project and/or build properties file:

chrome.driver=drivers/chromedriver_win32_2.1/chromedriver.exe

To specify to run a tests in Chrome use the BrowserType annotation and specify Chrome:

@BrowserType(value = Browser.CHROME)
public class Form1ChromeTest extends Form1TestBase

Firefox

This library uses Selenium, which comes with a Firefox web driver already present. You do however have the ability to optionally specify the Firefox executable to use in the in the project and/or build properties:

firefox.exe=C:\\Program Files\\Mozilla\\firefox.exe

To specify to run a tests in Firefox use the BrowserType annotation and specify Firefox:

@BrowserType(value = Browser.FIREFOX)
public class Form1FirefoxTest extends Form1TestBase

Safari

This library uses Selenium, which comes with a Safari web driver already present.

To specify to run a tests in Safari use the BrowserType annotation and specify Safari:

@BrowserType(value = Browser.SAFARI)
public class Form1SafariTest extends Form1TestBase

Internet Explorer

This library comes with the Selenium Web Driver used for Internet Explorer on 32-bit Windows, but you can download any one you want from the project website here. To change the web driver in use, you just have to modify the location specified in project and/or build properties file:

ie.driver=drivers/IEDriverServer_Win32_2.35.3/IEDriverServer.exe

To specify to run a tests in Internet Explorer use the BrowserType annotation and specify Internet Explorer:

@BrowserType(value = Browser.INTERNET_EXPLORER)
public class Form1IETest extends Form1TestBase

HTML Unit

HtmlUnit is a “GUI-Less browser for Java programs”. It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc… just like you do in your “normal” browser.

– http://htmlunit.sourceforge.net/

Since HTML Unit is supported within Selenium I went ahead and included within this library. However, while this is a more quick way to execute tests against HTML, that test is only a simulation. I have found that most complex HTML5 components such as with ExJS trees and grids do not work in HTML Unit. For example while the Firefox test in the real browser works, the Firefox simulated test though HTML Unit encounters JavaScript errors.

There are two ways to specify an HTML Unit test, the first of which is to just specify HTML Unit in the test’s browser annotation:

@BrowserType(value = Browser.HTML_UNIT)
public class Form1HtmlUnitTest extends Form1TestBase

This will run the test in the HTML Unit’s default HTML and JavaScript implementation.

The second way is to use a specific browser emulator though HTML Unit, which is done by specifying the browser annotation along with a version:

@BrowserType(value = Browser.HTML_UNIT)
@EmulateVersion(value = BrowserVersion.FIREFOX_17)
public class Form1HtmlUnitFirefoxTest extends Form1TestBase

The supported emulation versions are the following:

  • Chome – CHROME
  • Chrome v 16 – CHOME_16
  • Firefox v10 – FIREFOX_10
  • Firefox v17 – FIREFOX_17
  • Firefox v3.6 – FIREFOX_3_6
  • Internet Explorer 6 – INTERNET_EXPLORER_6
  • Internet Explorer 7 – INTERNET_EXPLORER_7
  • Internet Explorer 8 – INTERNET_EXPLORER_8
  • Internet Explorer 9 – INTERNET_EXPLORER_9

What Next?

See Locating Components.