Module: Xpath

Defined in:
lib/generic_test/xpath.rb

Overview

Module to help form xpaths for generic identification

Class Method Summary collapse

Class Method Details

.input_by_label(label) ⇒ String



12
13
14
15
# File 'lib/generic_test/xpath.rb', line 12

def input_by_label(label)
  upcase_text = upcase('text()')
  "//input[@id=(//label[contains(#{upcase_text},'#{label.upcase}')]/@for)]"
end

.label_or_attribute(field_name) ⇒ String



18
19
20
21
22
23
# File 'lib/generic_test/xpath.rb', line 18

def label_or_attribute(field_name)
  any_input_with_atr = "//input[@*='#{field_name}']"
  input_with_text = "//input[text()='#{field_name}']"
  [input_by_label(field_name), any_input_with_atr, input_with_text]
    .join('|')
end

.upcase(xpath_method) ⇒ String



7
8
9
# File 'lib/generic_test/xpath.rb', line 7

def upcase(xpath_method)
  "translate(#{xpath_method},'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"
end