Module: Foundry

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

#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



28
29
30
# File 'lib/test-factory/foundry.rb', line 28

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



17
18
19
20
21
# File 'lib/test-factory/foundry.rb', line 17

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



9
10
11
# File 'lib/test-factory/foundry.rb', line 9

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



41
42
43
# File 'lib/test-factory/foundry.rb', line 41

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