class Parfait::Control

Attributes

aliases[R]
name[R]

Public Class Methods

new(opts = {}) click to toggle source

Create a new control object

Options

name

the name used to identify this control

logtext

the text to be used when referring to this control in logs

aliases

specifies an array of aliases for the control

parent

specifies the parent object (Region or Page) of this control

Example

newcontrol = Parfait::Control.new(
  :name => "User ID",
  :logtext = "user ID"
)
Calls superclass method Parfait::ParfaitArtifact::new
# File lib/parfait/control.rb, line 23
def initialize(opts = {})
o = {
    :name => nil,
    :logtext => nil,
    :aliases => [],
    :parent => nil
  }.merge(opts)
  @name = o[:name]
  @logtext = o[:logtext]
  @aliases = o[:aliases]
  @parent = o[:parent]

  @set_method = nil
  @get_method = nil
  @update_method = nil
  @retrieve_method = nil
  @verify_method = nil
  @confirm_method = nil
  @goto_method = nil
  @navigate_method = nil

  if @name
    unless @name.is_a?(String)
      raise "Name must be a String when adding a control"
    end
  else
    raise "Name must be specified when adding a control"
  end
  if @logtext
    unless @logtext.is_a?(String)
      raise "Logtext must be a String when adding a control"
    end
  else
    raise "Logtext must be specified when adding a control" 
  end
  if @aliases
    unless @aliases.is_a?(Array)
      raise "Parfait::Control requires aliases to be an array"
    end
    @aliases.each do |my_alias|
      raise "Parfait::Control requires each alias in the array to be a string" unless my_alias.is_a?(String)
    end
  end

  if @parent
    if @parent.is_a? Parfait::Page
      add_to_page(@parent)
    else
      if @parent.is_a? Parfait::Region
        add_to_region(@parent)
      else
        raise "Parent specified for Control \"#{@name}\", but parent object type unrecognized."
      end
    end
  end

  super
end

Public Instance Methods

add_confirm(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 373
def add_confirm(&block)
  @confirm_method = block
end
add_generic_confirm() click to toggle source

Method description

Depends on get, retrieve

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 485
def add_generic_confirm()
  add_confirm { |value,opts|
    retval = false
    found_value = retrieve()
    if value == found_value
      retval = true
    end
    retval
  }        
end
add_generic_navigate() click to toggle source

Method description

Depends on goto

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 508
def add_generic_navigate()
  add_navigate { |opts|
    Parfait.log("Navigating to #{@logtext}")
    goto(opts)
  }
end
add_generic_retrieve() click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 443
def add_generic_retrieve()
  add_retrieve { |opts|
    get(opts)
  }
end
add_generic_update() click to toggle source

Method description

Depends on get, retrieve, set

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 418
def add_generic_update()
  add_update { |value,opts|
    new_value = value
    found_value = retrieve()
    if new_value == found_value
      capital_text = @logtext
      capital_text[0] = capital_text[0].capitalize
      Parfait.log("#{capital_text} is already set to \"#{new_value}\"")
    else
      Parfait.log("Entering #{@logtext}: \"#{new_value}\" (was \"#{found_value}\")")
      set(new_value,opts)
    end
  }
end
add_generic_verify() click to toggle source

Method description

Depends on get, retrieve

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 461
def add_generic_verify()
  add_verify { |value,opts|
    found_value = retrieve()
    if value == found_value
      Parfait.log("Verified #{@logtext} to be \"#{value}\"")
    else
      raise "Expected #{@logtext} to be \"#{value}\", but found \"#{found_value}\" instead"
    end
    true
  }    
end
add_get(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 292
def add_get(&block)
  @get_method = block
  
  add_generic_retrieve() unless @retrieve_method
  add_generic_confirm() unless @confirm_method
  add_generic_verify() unless @verify_method
  if @set_method != nil
    add_generic_update unless @update_method
  end 
end
add_goto(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 387
def add_goto(&block)
  @goto_method = block
  add_generic_navigate() unless @navigate_method
end
add_navigate(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 402
def add_navigate(&block)
  @navigate_method = block
end
add_retrieve(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 345
def add_retrieve(&block)
  @retrieve_method = block
end
add_set(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 313
def add_set(&block)
  @set_method = block

  if @get_method != nil
    add_generic_update() unless @update_method
  end 
end
add_to_page(page) click to toggle source

Add this Control to a Page

Options

page

specifies a Parfait::Page object to add this Control to

Example

loginpage = Parfait::Page.new(
  :name => "Login Page"
)
newcontrol = Parfait::Control.new(
  :name => "User ID",
  :logtext = "user ID"
)
newcontrol.add_to_page(loginpage)
# File lib/parfait/control.rb, line 100
def add_to_page(page)

  if page
    case
    when page.is_a?(Parfait::Page)
      page.add_control(self)
    else
      raise "Input value must be a Page object when adding this Control to a Page"
    end
  else
    raise "Input value cannot be nil when adding this Control to a Page"
  end
  self
end
add_to_region(region) click to toggle source

Add this Control to a Region

Options

region

specifies a Parfait::Region object to add this Control to

Example

user = Parfait::Region.new(
  :name => "User"
)
newcontrol = Parfait::Control.new(
  :name => "Edit User",
  :logtext = "edit user link"
)
user.add_to_region(newcontrol)
# File lib/parfait/control.rb, line 133
def add_to_region(region)

  if region
    case
    when region.is_a?(Parfait::Region)
      region.add_control(self)
    else
      raise "Input value must be a Region object when adding this Control to a Region"
    end
  else
    raise "Input value cannot be nil when adding this Control to a Region"
  end
  self
end
add_update(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 331
def add_update(&block)
  @update_method = block
end
add_verify(&block) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 359
def add_verify(&block)
  @verify_method = block
end
confirm(value,opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 232
def confirm(value,opts = {})
  verify_control_presence("confirm")
  return @confirm_method.call(value,opts)
end
get(opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 172
def get(opts = {})
  verify_control_presence("get")
  return @get_method.call(opts)
end
goto(opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 262
def goto(opts = {})
  verify_control_presence("goto")
  return @goto_method.call(opts)
end
navigate(opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
retrieve(opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 202
def retrieve(opts = {})
  verify_control_presence("retrieve")
  return @retrieve_method.call(opts)
end
set(value,opts = {}) click to toggle source

Set the value for this control

Options

value

specifies the value that this control will be set to

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 187
def set(value,opts = {})
  verify_control_presence("set")
  @set_method.call(value,opts)
end
update(value,opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 217
def update(value,opts = {})
  verify_control_presence("update")
  @update_method.call(value,opts)
end
verify(value,opts = {}) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 247
def verify(value,opts = {})
  verify_control_presence("verify")
  @verify_method.call(value,opts)
end
verify_control_presence(directive_name) click to toggle source

Method description

Options

option

specifies something

Example

$$$ Need an example $$$
# File lib/parfait/control.rb, line 158
def verify_control_presence(directive_name)
  verify_presence "Cannot call \"#{directive_name}\" directive because presence check for control \"#{@name}\" failed"
end