Module: Capybara::Rc::SeleniumRcLocators

Included in:
Actions, Extensions
Defined in:
lib/capybara/rc/selenium_rc_locators.rb

Instance Method Summary collapse

Instance Method Details

#parse_selenium_rc_locator(locator) ⇒ Object

Follows the logic & heuristics in

https://github.com/SeleniumHQ/selenium/blob/master/javascript/selenium-atoms/se_locators.js
function core.locators.parseLocator_


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capybara/rc/selenium_rc_locators.rb', line 8

def parse_selenium_rc_locator(locator)
  match = locator.match(/\A([A-Za-z]+)=.+\Z/)
  if match
    type = match[1]
    string = locator.split('=', 2)[1]
    {
      type: type.to_sym,
      string: string
    }
  elsif locator =~ %r{^//}
    { type: :xpath, string: locator }
  elsif locator =~ /^document\./
    { type: :dom, string: locator }
  else
    { type: :identifier, string: locator }
  end
end

#parse_selenium_rc_select_option_locator(option_locator) ⇒ Object

Follows the logic & heuristics in

https://github.com/SeleniumHQ/selenium/blob/master/javascript/selenium-atoms/select.js
function core.select.option.getOptionLocator_


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/capybara/rc/selenium_rc_locators.rb', line 30

def parse_selenium_rc_select_option_locator(option_locator)
  match = option_locator.match(/\A([A-Za-z]+)=.*\Z/)
  if match
    type = match[1]
    type = "text" if type == "label"
    string = option_locator.split('=', 2)[1]
    {
      type: type.to_sym,
      string: string
    }
  else
    { type: :text, string: option_locator }
  end
end

#parse_selenium_rc_string_pattern(pattern) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/capybara/rc/selenium_rc_locators.rb', line 59

def parse_selenium_rc_string_pattern(pattern)
  match = pattern.match(/\A([A-Za-z]+):.+\Z/)
  if match
    type = match[1]
    string = pattern.split(':', 2)[1]
    {
      type: type.to_sym,
      string: string
    }
  else
    { type: :glob, string: pattern }
  end
end

#parse_selenium_rc_window_locator(window_locator) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/capybara/rc/selenium_rc_locators.rb', line 45

def parse_selenium_rc_window_locator(window_locator)
  if window_locator == nil || window_locator == "null"
    return { type: :main_window, string: nil }
  end
  match = window_locator.match(/\A([A-Za-z]+)=.*\Z/)
  if match
    type = match[1]
    string = window_locator.split('=', 2)[1]
    { type: type.to_sym, string: string }
  else
    { type: :window_id, string: window_locator }
  end
end