Module: Locator

Extended by:
Locator
Included in:
Locator
Defined in:
lib/locator.rb,
lib/locator/dom.rb,
lib/locator/xpath.rb,
lib/locator/result.rb,
lib/locator/boolean.rb,
lib/locator/element.rb,
lib/locator/version.rb,
lib/locator/dom/nokogiri.rb,
lib/locator/element/area.rb,
lib/locator/element/file.rb,
lib/locator/element/form.rb,
lib/locator/element/link.rb,
lib/locator/element/field.rb,
lib/locator/element/input.rb,
lib/locator/element/label.rb,
lib/locator/element/button.rb,
lib/locator/element/select.rb,
lib/locator/dom/nokogiri/page.rb,
lib/locator/element/check_box.rb,
lib/locator/element/text_area.rb,
lib/locator/dom/nokogiri/element.rb,
lib/locator/element/form_element.rb,
lib/locator/element/hidden_field.rb,
lib/locator/element/radio_button.rb,
lib/locator/element/elements_list.rb,
lib/locator/element/select_option.rb,
lib/locator/element/labeled_element.rb

Defined Under Namespace

Modules: Boolean, Dom Classes: Element, Result, Xpath

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](type) ⇒ Object



11
12
13
# File 'lib/locator.rb', line 11

def [](type)
  locators[type.to_sym] || raise("unknown locator type: #{type}")
end

.build(type) ⇒ Object



15
16
17
18
# File 'lib/locator.rb', line 15

def build(type)
  locator = locators[type.to_sym] if type
  locator ? locator.new : Locator::Element.new(type)
end

Instance Method Details

#locate(dom, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/locator.rb', line 33

def locate(dom, *args, &block)
  return args.first if args.first.respond_to?(:elements_by_xpath)

  options = Hash === args.last ? args.last : {}
  result = if scope = options.delete(:within)
    within(*Array(scope)) { locate(dom, *args) }
  else
    type = args.shift if args.first.is_a?(Symbol)
    Locator.build(type).locate(current_scope(dom), *args)
  end

  result && block_given? ? within(result) { yield(self) } : result
end

#within(*scope) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Locator)

    the object that the method was called on



47
48
49
50
# File 'lib/locator.rb', line 47

def within(*scope)
  scopes.push(scope)
  yield(self)
end

#xpath(type, *args) ⇒ Object



29
30
31
# File 'lib/locator.rb', line 29

def xpath(type, *args)
  Locator[type].new.xpath(*args)
end