Class: Webrat::Locators::ButtonLocator

Inherits:
Locator show all
Defined in:
lib/webrat/core/locators/button_locator.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Locator

#initialize, #locate!

Constructor Details

This class inherits a constructor from Webrat::Locators::Locator

Instance Method Details

#button_elementObject



12
13
14
15
16
17
18
19
20
# File 'lib/webrat/core/locators/button_locator.rb', line 12

def button_element
  button_elements.detect do |element|
    @value.nil?             ||
    matches_id?(element)    ||
    matches_value?(element) ||
    matches_html?(element)  ||
    matches_alt?(element)
  end
end

#button_elementsObject



39
40
41
# File 'lib/webrat/core/locators/button_locator.rb', line 39

def button_elements
  Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
end

#error_messageObject



43
44
45
# File 'lib/webrat/core/locators/button_locator.rb', line 43

def error_message
  "Could not find button #{@value.inspect}"
end

#locateObject



8
9
10
# File 'lib/webrat/core/locators/button_locator.rb', line 8

def locate
  ButtonField.load(@session, button_element)
end

#matches_alt?(element) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/webrat/core/locators/button_locator.rb', line 35

def matches_alt?(element)
  Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
end

#matches_html?(element) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/webrat/core/locators/button_locator.rb', line 31

def matches_html?(element)
  Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
end

#matches_id?(element) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/webrat/core/locators/button_locator.rb', line 22

def matches_id?(element)
  (@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
  (!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
end

#matches_value?(element) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/webrat/core/locators/button_locator.rb', line 27

def matches_value?(element)
  Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
end