Module: Watirmark::ControllerMethods

Defined in:
lib/watirmark/controller/controller.rb

Overview

class MyController < Watirmark::Controller

@page = MyPage                 # This is required and should point to a view. Navigation also should be in the view

# In the simplest case, that's ALL you need. Most of the 
# real info should be contained in your Page. Below are some
# tools you can use to override default behavior

# When running the populate/verify methods, ignore these
# keywords. Note that buttons and links won't get called
# so you don't need to add them here, as they will just get ignored

reject :keyword1, :keyword2, ...    

# Override how the controller populates.
def populate_data
  super # to call the default populate
  # do something
end

# Override how the controller verifies.
def verify_data
  super # to call the default verify
  # do something
end

# Change the rasta value for a keyword. Note that this 
# will both set the value using this and will verify 
# as if this is the rasta value so you shouldn't have to 
# override the verification unless they differ
#
# def #{keyword}_value; # do something; end

def currency_value
  "$#{@rasta[:currency]}" 
end

# Override verification for a given element.
# In this example the file_field that sets the value is blank
# when we verify so we just check that an image was uploaded 
# by looking at what buttons appear 
#
# def verify_#{keyword}; # do something; end

def verify_image
  if @page.uploadimage.exists?
    assert @rasta[:image] == 'nil'
  elsif @page.uploaddifferentimage.exists?
    assert @rasta[:image] != 'nil'
  end
end

# Override data population for a given element.
# In this case we have a rasta value that maps
# to a keyword that has no proc and we override
# things here 
#
# def populate_#{keyword}; # do something; end

def populate_teamdivisions
  @rasta[:teamdivisions].each do |team|
    @page.teamdivision.set team
    close_dialog_if_exists { @page.adddivbutton.click_no_wait }
    Watir::Waiter.wait_until do
      @page.divisionname(team).exists?
    end
  end
end

# Add behavior before an element is set (populate only)
#
# def before_#{keyword}; # do something; end

def before_image
  @page.image.fire_event('OnChange')
end

# Add behavior after an element is set (populate only)
#
# def after_#{keyword}; # do something; end

def after_image
  @page.upload_button.click
end

# Override the default submit behavior which is 
# to click a Save/Next/Finish button. 
def submit
  @page.completebutton.click
end

def create; end           # navigates to the create page and runs populate_data
def edit; end             # navigates to the edit page and runs populate_data
def verify; end           # navigates to the edit page and runs verify_data
def check_defaults; end   # navigates to the create page and runs verify_data

ANY other methods should be created in the controller and delegated to the Page:

end

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) page

Returns the value of attribute page



108
109
110
# File 'lib/watirmark/controller/controller.rb', line 108

def page
  @page
end

Instance Method Details

- (Object) inherited(klass)

Set the view if this controller inherits a class that sets the view



111
112
113
# File 'lib/watirmark/controller/controller.rb', line 111

def inherited(klass) #:nodoc:
  klass.page ||= @page if @page
end

- (Object) submit_method_default



119
120
121
# File 'lib/watirmark/controller/controller.rb', line 119

def submit_method_default
  @@submit_method_default
end

- (Object) submit_method_default=(proc)



115
116
117
# File 'lib/watirmark/controller/controller.rb', line 115

def submit_method_default=(proc)
  @@submit_method_default = proc
end