Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Browsers & Drivers

lkhoward edited this page Mar 17, 2016 · 6 revisions

Browsers

The browser is launched when a Huzzah::Role is instantiated. You can access the browser from any Huzzah class by calling the browser method:

# Role
# Launch the Browser
user = Huzzah::Role.new

# Access the browser through a Role
user.browser

# Access the browser through a Site
user.moolah.browser

# Access the browser through a Page
user.moolah.login_page.browser

# Access the browser through a Partial
user.moolah.user_account.header.browser

# Access the browser through a Flow
user.payment.browser

Huzzah supports a basic firefox (and defaults to it) driver out of the box. The same as calling:

Watir::Browser.new(:firefox)

Selenium

You can access the underlying Selenium driver by calling:

user.browser.driver

Custom Drivers

You can define a custom driver as follows:

Huzzah.define_driver(:chrome) do
  
  Watir::Browser.new(:chrome)

end

NOTE: This example assumes that you have chromedriver properly installed.

You can define as many drivers as you wish and they can be a complicated as you need them to be. Any type of profile or capabilities configuration that you can do with watir-webdriver, you can do within the Huzzah.define_driver block. The only caveat is that the last line of your block needs to return the browser instance. The block is not called until a role is instantiated.

A More Complex Example

Huzzah.define_driver(:custom_firefox) do
  client = Selenium::WebDriver::Remote::Http::Default.new
  client.timeout = 120
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['browser.fixup.alternate.enabled'] = false
  profile['network.dns.disablePrefetch'] = true
  profile['network.http.connect.timeout'] = 120
  profile['network.http.request.timeout'] = 120

  driver = Selenium::WebDriver.for(:firefox, profile: profile)
  Watir::Browser.new(driver)
end

Setting the Default Drivers

You can set an overall default driver within the Huzzah.config block. See Configuration

You can also set a driver per role. This is done within the role's YAML file:

---
dev:
  :email: 'dedric.auer@howe.com'
  :password: 'U9HhGbSp'
  :full_name: 'Dedric Auer'
  :driver: 'chrome'

When a new role is instantiated, Huzzah will check to see if a the driver has been specified in the role's YAML file. Otherwise, it will fall back to the default driver defined in the configuration block.

Clone this wiki locally