Module: Foundry

Included in:
DataFactory
Defined in:
lib/test-factory/foundry.rb

Overview

This module provides methods that instantiate the page and data classes.

Instance Method Summary collapse

Instance Method Details

#create(data_object_class, opts = {}) ⇒ Object

An extension of the #make method that simplifies and improves the readability of your “create” step definitions by combining the make with the create. Of course, this requires that your data object classes properly follow the design pattern and have a #create method available.



56
57
58
59
60
# File 'lib/test-factory/foundry.rb', line 56

def create data_object_class, opts={}
  data_object = make data_object_class, opts
  data_object.create
  data_object
end

#make(data_object_class, opts = {}) ⇒ Object

Use this for making a data object in your test steps

Parameters:

  • data_object_class (Class)

    The name of the class you want to use to build a data object for testing

  • opts (Hash) (defaults to: {})

    The list of attributes you want to give to your data object



46
47
48
# File 'lib/test-factory/foundry.rb', line 46

def make data_object_class, opts={}
  data_object_class.new @browser, opts
end

#on(page_class, visit = false, &block) ⇒ Object Also known as: on_page

Instantiates the supplied page class, then runs the supplied block of code. Use this method when you are already on the site page you want to interact with.

Parameters:

  • page_class (Class)

    the name of the page class that you want to instantiate

  • visit (TrueClass, FalseClass) (defaults to: false)

    Essentially you will never have to specify this explicitly

  • &block (C)

    this is the block of code that you want to run while on the given page



34
35
36
37
38
# File 'lib/test-factory/foundry.rb', line 34

def on page_class, visit=false, &block
  $current_page = page_class.new @browser, visit
  block.call $current_page if block
  $current_page
end

#visit(page_class, &block) ⇒ Object

Using the page_url defined in the provided page_class, this method will enter that url into the browser’s address bar, then run the block of code that you specify.

Parameters:

  • page_class (Class)

    the name of the page class that you want to instantiate

  • &block (C)

    this is the block of code that you want to run while on the given page



24
25
26
# File 'lib/test-factory/foundry.rb', line 24

def visit page_class, &block
  on page_class, true, &block
end

#wait_until(timeout = 30, message = nil, &block) ⇒ Object

A helper method that takes a block of code and waits until it resolves to true. Useful when you need to wait for something to be on a page that’s a little more involved than a simple element (for those, you should use the #expected_element method found in the PageFactory class)

Examples:

page.wait_until { |b| b.processing_message=="Done" }

Parameters:

  • timeout (Fixnum) (defaults to: 30)

    Defaults to 30 seconds

  • message (String) (defaults to: nil)

    The text thrown if the timeout is reached



72
73
74
# File 'lib/test-factory/foundry.rb', line 72

def wait_until(timeout=30, message=nil, &block)
  Object::Watir::Wait.until(timeout, message, &block)
end