Class: PageMagic::Element::Selector
- Inherits:
-
Object
- Object
- PageMagic::Element::Selector
- Defined in:
- lib/page_magic/element/selector.rb
Overview
class Selector - models the selection criteria understood by Capybara
Constant Summary collapse
- XPATH =
Selector.new(:xpath, supports_type: false)
- ID =
Selector.new(:id, supports_type: false)
- LABEL =
Selector.new(:field, supports_type: false, exact: true)
- CSS =
Selector.new(supports_type: false)
- TEXT =
Selector.new(supports_type: true)
- NAME =
Selector.new(supports_type: false) do |arg| "*[name='#{arg}']" end
Instance Attribute Summary collapse
-
#exact ⇒ Object
readonly
Returns the value of attribute exact.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#supports_type ⇒ Object
readonly
Returns the value of attribute supports_type.
Class Method Summary collapse
-
.find(name) ⇒ Selector
Find a Selecor using it's name.
Instance Method Summary collapse
-
#build(element_type, locator) ⇒ Object
Build selector query parameters for Capybara's find method.
-
#initialize(selector = nil, supports_type: false, exact: false, &formatter) ⇒ Selector
constructor
A new instance of Selector.
Constructor Details
#initialize(selector = nil, supports_type: false, exact: false, &formatter) ⇒ Selector
Returns a new instance of Selector.
19 20 21 22 23 24 |
# File 'lib/page_magic/element/selector.rb', line 19 def initialize(selector = nil, supports_type: false, exact: false, &formatter) @name = selector @formatter = formatter || proc { |arg| arg } @supports_type = supports_type @exact = exact end |
Instance Attribute Details
#exact ⇒ Object (readonly)
Returns the value of attribute exact.
17 18 19 |
# File 'lib/page_magic/element/selector.rb', line 17 def exact @exact end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
17 18 19 |
# File 'lib/page_magic/element/selector.rb', line 17 def formatter @formatter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/page_magic/element/selector.rb', line 17 def name @name end |
#supports_type ⇒ Object (readonly)
Returns the value of attribute supports_type.
17 18 19 |
# File 'lib/page_magic/element/selector.rb', line 17 def supports_type @supports_type end |
Class Method Details
.find(name) ⇒ Selector
Find a Selecor using it's name
10 11 12 13 14 |
# File 'lib/page_magic/element/selector.rb', line 10 def find(name) selector = constants.find { |constant| constant.to_s.downcase == name.to_s.downcase } fail UnsupportedCriteriaException unless selector const_get(selector) end |
Instance Method Details
#build(element_type, locator) ⇒ Object
Build selector query parameters for Capybara's find method
29 30 31 32 33 34 35 36 |
# File 'lib/page_magic/element/selector.rb', line 29 def build(element_type, locator) [].tap do |array| array << element_type if supports_type array << name if name array << formatter.call(locator) array << { exact: true } if exact end end |