Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.
lkhoward edited this page Mar 18, 2016 · 12 revisions

Sites in Huzzah are a bit of an abstract concept. There is not a user-defined Ruby class that represents a site. Instead, they are defined when you define your Pages. The module namespace that you use to define your pages is used to dynamically generate methods that return a Huzzah::Site instance. Be sure to be consistent when naming your Pages.

For example:

# The module namespace 'Moolah' is the Site.
# The class name 'LoginPage' is the Page.
module Moolah 
  class LoginPage < Huzzah::Page 
     
  end
end

# In snake case:
# The site name == moolah
# The page name == login_page

Huzzah dynamically generates methods that return an instance of the site. The name of the method is the snake-cased version of the module namespace (e.g. module Moolah == moolah).

To return an instance of the site:

user = Huzzah::Role.new
user.moolah # Returns the site instance

Typically, the site method is part of a method chain to return page-object or the site's config data.

user = Huzzah::Role.new
user.moolah.login_page # Returns an instance of LoginPage for site Moolah
user.moolah.config # Returns the config data for site Moolah (see below)

Optionally, the site method with accept a block of code:

user.some_site do
  some_page.some_locator.action
  some_page.some_locator.action
  another_page.some_locator.action
end

A couple of things to keep in mind if you find yourself using blocks frequently:

  1. Are all of the steps in the block calling the same page-object? If so, consider creating a method in the page-object to perform those steps.

  2. If the steps in the block reference multiple page-objects, consider using a Flow.

Definitely follow the above advice if you find yourself using the same blocks in multiple scenarios.

Site Config

You do not have to do any additional work to define sites, but Huzzah provides optional functionality to define data about your sites (and test environments). In order to use these optional features, you will need to define a YAML file under the sites directory.

The name of the YAML file should be a snake case version of the module namespace defined in your Pages as described above.

module Moolah
  ...
end
# The site config file would be named moolah.yml

The structure of the YAML file would look like this:

---
dev:
    :url: 'http://localhost:9292'

In the above example, the key dev is refers to the environment that your tests will run against. You may have any number of environments defined. Huzzah will only load the data for environment that is set in your configuration block.

For example:

# This config block tells Huzzah to load the 'dev'  
# environment data for each defined site.
Huzzah.configure do |config|
  config.environment = 'dev'
end
``

For each environment, you may define any data that you need (e.g. urls, database connection info, etc). The _url_ key is a special case. It is used by the site's _visit_ method to navigate the browser to the correct URL for the environment.

```ruby
role.moolah.visit

All other site config data must be referenced by calling the site's config method, which returns a Hash created from the YAML file.

role.moolah.config
> [url: "http://localhost:9292", "url": "http://localhost:9292"]

NOTE: The Hash of config data has indifferent access, so you may use Strings or Symbols to reference the keys.

The site's config data file (if it exists) is read when a Huzzah::Role is instantiated, but there may be times that you need to access the site config before you instantiate a Role. For instance, you may want to want to use data from the site config to establish a database connection or to call a web service before you execute a suite of tests.

If you need to access to a site's config data independently, you can do so:

@config = Huzzah.site_config(:moolah)
@config[:url]
> "http://wlocalhost:9292"

Finally, Huzzah sites contain a special method for dynamically calling pages. It can be useful in certain situations, especially testing frameworks like Cucumber where you may have a step definition that can apply to multiple pages.

@role.moolah.on(:login_page).login

Clone this wiki locally