Module: Intelement
- Extended by:
- Capybara::DSL
- Defined in:
- lib/intelement.rb
Class Attribute Summary collapse
-
.driver ⇒ Object
readonly
Returns the value of attribute driver.
-
.uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
- .get_all_element_attribute_value(locator, attribute_name) ⇒ Object
- .get_all_elements(locator) ⇒ Object
- .get_all_elements_value(locator, type = :text) ⇒ Object
- .get_attribute_value(locator, attribute_name) ⇒ Object
- .get_attribute_value_of_index(locator, attribute_name, index = 0) ⇒ Object
- .get_element_details(locator, value_to_get = nil, index = nil) ⇒ Object
- .get_element_value(locator, type = :text) ⇒ Object
- .get_element_value_of_index(locator, type = :text, index = 0) ⇒ Object
- .get_selector(locator) ⇒ Object
- .is_element_present?(locator) ⇒ Boolean
- .visit_page(uri = nil, driver = :selenium) ⇒ Object
Class Attribute Details
.driver ⇒ Object (readonly)
Returns the value of attribute driver.
8 9 10 |
# File 'lib/intelement.rb', line 8 def driver @driver end |
.uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/intelement.rb', line 8 def uri @uri end |
Class Method Details
.get_all_element_attribute_value(locator, attribute_name) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/intelement.rb', line 73 def get_all_element_attribute_value locator, attribute_name selector = get_selector locator all_elements = all(selector, locator) attribute_values = all_elements.map do |element| element[attribute_name] end attribute_values end |
.get_all_elements(locator) ⇒ Object
32 33 34 35 |
# File 'lib/intelement.rb', line 32 def get_all_elements locator selector = get_selector locator all(selector, locator) end |
.get_all_elements_value(locator, type = :text) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/intelement.rb', line 57 def get_all_elements_value locator, type=:text selector = get_selector locator all_elements = all(selector, locator) element_values = case type when :text, :link all_elements.map do |element| element.text end when :button all_elements.map do |element| element.value end end element_values end |
.get_attribute_value(locator, attribute_name) ⇒ Object
47 48 49 50 |
# File 'lib/intelement.rb', line 47 def get_attribute_value locator, attribute_name selector = get_selector locator find(selector, locator)[attribute_name] end |
.get_attribute_value_of_index(locator, attribute_name, index = 0) ⇒ Object
52 53 54 55 |
# File 'lib/intelement.rb', line 52 def get_attribute_value_of_index locator, attribute_name, index=0 selector = get_selector locator all(selector, locator)[index][attribute_name] end |
.get_element_details(locator, value_to_get = nil, index = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/intelement.rb', line 82 def get_element_details locator, value_to_get=nil, index=nil if value_to_get.nil? && index.nil? is_element_present? locator elsif value_to_get.nil? && index.eql?(:all) get_all_elements locator elsif index.nil? if value_to_get.class.eql?(String) get_attribute_value locator, value_to_get else get_element_value locator, value_to_get end else if index.class.eql?(Symbol) if value_to_get.class.eql?(String) get_all_element_attribute_value locator, value_to_get else get_all_elements_value locator, value_to_get end else if value_to_get.class.eql?(String) get_attribute_value_of_index locator, value_to_get, index else get_element_value_of_index locator, value_to_get, index end end end end |
.get_element_value(locator, type = :text) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/intelement.rb', line 22 def get_element_value locator, type=:text selector = get_selector locator case type when :text, :link find(selector, locator).text when :button find(selector, locator).value end end |
.get_element_value_of_index(locator, type = :text, index = 0) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/intelement.rb', line 37 def get_element_value_of_index locator, type=:text, index=0 selector = get_selector locator case type when :text, :link all(selector, locator)[index].text when :button all(selector, locator)[index].value end end |
.get_selector(locator) ⇒ Object
110 111 112 |
# File 'lib/intelement.rb', line 110 def get_selector locator locator[0] == '/' ? :xpath : :css end |
.is_element_present?(locator) ⇒ Boolean
17 18 19 20 |
# File 'lib/intelement.rb', line 17 def is_element_present? locator selector = get_selector locator has_selector?(selector, locator) end |
.visit_page(uri = nil, driver = :selenium) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/intelement.rb', line 10 def visit_page uri=nil, driver=:selenium @uri = uri @driver = driver Capybara.default_driver = @driver Capybara.visit uri end |