class LegoTechSelenium::ValidateElement

Public Class Methods

new(action, element) click to toggle source

The constructor of the Action class @param element [Selenium::WebDriver::Element] @param action [Hash] A ruby object that has the following layout

{
     :fieldtype => Fields::...
     :identifier => Identifier::...
     :value => String
     :validate => True -> Verify the value before continuing to the next action, skip validation
}
# File lib/ui/validate/ValidateElement.rb, line 15
def initialize(action, element)
  if action.nil? or action.empty?
    raise "Cannot submit a nil or empty action within the Validate class"
  end

  if element.nil?
    raise "Cannot submit a nil Selenium element within the Validate class"
  end

  # Set instance variables
  @action = action
  @element = element
end

Public Instance Methods

validate() click to toggle source

Function used to validate the element is correctly set @return True if correctly validated, False if incorrectly validated @raise [RuntimeError] FieldType is not supported

# File lib/ui/validate/ValidateElement.rb, line 32
def validate()
  case @action[:fieldtype]
  when LegoTechSelenium::FieldType::INPUT
    return validateInput
  when LegoTechSelenium::FieldType::DROPDOWN_LIST
    return validateSelect
  when LegoTechSelenium::FieldType::BUTTON
    # Cannot validate the value of a button
    return true
  when LegoTechSelenium::FieldType::CHECK_BOX
    return validateCheckBox
  when LegoTechSelenium::FieldType::RADIO_BUTTON
    return validateRadioButton
  else
    raise "Cannot validate this field type please refer to the validate function within the Validate class for further details"
  end
end
validateCheckBox() click to toggle source

Validates the value of an input field return True -> action value is equal to the input field value

# File lib/ui/validate/ValidateElement.rb, line 52
def validateCheckBox()
  puts "Asserting that #{LegoTechSelenium::FieldType::INPUT} with field name #{@action[:fieldname]} is set to \"#{@action[:value]}\""
  unless @action[:value].nil?
    return @action[:value].eql? @element.attribute("value")
  else
    return @action[:fieldname].eql? @element.attribute("value")
  end
end
validateInput() click to toggle source

Validates the value of an input field return True -> action value is equal to the input field value

# File lib/ui/validate/ValidateElement.rb, line 74
def validateInput()
  puts "Asserting that #{LegoTechSelenium::FieldType::INPUT} with field name #{@action[:fieldname]} is set to \"#{@action[:value]}\""
  return @action[:value].eql? @element.attribute("value")
end
validateRadioButton() click to toggle source

Validates the value of an input field return True -> action value is equal to the input field value

# File lib/ui/validate/ValidateElement.rb, line 63
def validateRadioButton()
  puts "Asserting that #{LegoTechSelenium::FieldType::INPUT} with field name #{@action[:fieldname]} is set to \"#{@action[:value]}\""
  unless @action[:value].nil?
    return @action[:value].eql? @element.attribute("value")
  else
    return @action[:fieldname].eql? @element.attribute("value")
  end
end
validateSelect() click to toggle source

Validates the value of an input field return True -> action value is equal to the input field value

# File lib/ui/validate/ValidateElement.rb, line 81
def validateSelect()
  puts "Asserting that #{LegoTechSelenium::FieldType::DROPDOWN_LIST} with field name #{@action[:fieldname]} is set to \"#{@action[:value]}\""
  return @action[:value].eql? Selenium::WebDriver::Support::Select.new(@element).first_selected_option.text
end