Module: Locator::Equal

Defined in:
lib/cucumber/pickles/locator/equal.rb

Constant Summary collapse

EQUAL_REGEX =
/\A([^\p{L}]*)(=)(.*)\Z/

Class Method Summary collapse

Class Method Details

.execute(locator) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cucumber/pickles/locator/equal.rb', line 7

def execute(locator)
  matches = EQUAL_REGEX.match(locator)

  if matches
    captures = matches.captures
    locator = "#{captures[0]}#{captures[2]}"
    xpath = ".//*[text()='#{locator}']"

    [locator, xpath]
  else
    #
    # find node that contains *text* and does not have any child nodes that contain *text*
    #
    xpath = ".//*[contains(., '#{locator}')][not(*[contains(., '#{locator}')])]"

    [locator, xpath]
  end
end