Repository navigation
Roles
Roles are the heart of the Huzzah framework. They are the only object that you must instantiate. The instantiation of all other objects within the framework is handled auto-magically.
role = Huzzah::Role.newThe initialize method for the Huzzah::Role class takes two optional arguments. These optional arguments provide additional features that you may choose to use:
name: This argument is used to load a YAML file that contains data about the role (see Defined Roles below).
args: A Hash of data about the role. This can be used to supplement or overwrite the data of a defined role.
user = Huzzah::Role.new(:dedric)The above example will look for a file in your roles directory named dedric.yml. The file will be read and parsed into a hash with indifferent access named role_data. The role_data hash is available within the Role, all Sites, all Pages & all Flows.
Example: dedric.yml
---
dev:
:email: 'dedric.auer@howe.com'
:password: 'U9HhGbSp'
:full_name: 'Dedric Auer'NOTE: The key dev matches up to the environment defined in your Huzzah::configure block in the spec_helper.rb file.
You can define any number of environments in the YAML file by using a different key:
---
dev:
:email: 'dedric.auer@howe.com'
:password: 'U9HhGbSp'
qa:
:email: 'dedric.auer@howe.com'
:password: 'I34TyCxq'Referencing role data
user = Huzzah::Role.new(:dedric)
# Referenced in a Huzzah::Role object
user.role_data[:email]
# Referenced in a Huzzah::Site object
user.moolah.role_data[:email]
# Referenced in a Huzzah::Page object
user.moolah.login_page.role_data[:email]
# Referenced in a Huzzah::Page (Partial) object
user.moolah.login_page.header.role_data[:email]
# Referenced in a Huzzah::Flow object
user.payment.role_data[:email] You can pass a hash of data to overwrite or supplement the role data from the YAML file when you instantiate the Huzzah::Role object.
# Overwrite the user's password
user = Huzzah::Role.new(:dedric, password: 'password')
# Add the user's account id
user = Huzzah::Role.new(:dedric, account_id: '12345')If you would rather not use YAML files, you can simple pass a Hash to the constructor:
user = Huzzah::Role.new(username: 'johndoe', password: 'password')NOTE: The role data in frozen when a Huzzah::Role is instantiated. It cannot be modified while a scenario is running. This is to prevent data corruption which may cause flapping scenarios.
You can set the driver for the role by adding a driver key along with the name of the custom driver that you want to use for that role.
---
dev:
:email: 'dedric.auer@howe.com'
:password: 'U9HhGbSp'
:full_name: 'Dedric Auer'
:driver: 'chrome'When a new role is instantiated, Huzzah will use the driver defined in the role's YAML file. Otherwise, it will fall back to the default driver.
See Drivers and Configuration