Module: WebConditions
- Defined in:
- lib/web-object/conditions/url.rb,
lib/web-object/conditions/text.rb,
lib/web-object/conditions/alert.rb,
lib/web-object/conditions/title.rb,
lib/web-object/conditions/waiting.rb,
lib/web-object/conditions/elements_count.rb,
lib/web-object/conditions/element_property.rb,
lib/web-object/conditions/element_interaction.rb
Instance Method Summary collapse
- #alert_present? ⇒ Boolean true, Boolean false
- #attribute_is_absent(ele, attr) ⇒ Boolean true, Boolean false (also: #attribute_is_empty)
- #attribute_is_present(ele, attr) ⇒ Boolean true, Boolean false (also: #attribute_is_not_empty)
- #attribute_to_include(ele, attr, item) ⇒ Boolean true, Boolean false (also: #attribute_to_contain)
- #attribute_to_match(ele, attr) ⇒ Boolean true, Boolean false
- #element_is_absent(ele) ⇒ Boolean true, Boolean false
- #element_is_clickable(ele) ⇒ Boolean true, Boolean false
- #element_is_disabled(ele) ⇒ Boolean true, Boolean false
- #element_is_enabled(ele) ⇒ Boolean true, Boolean false
- #element_is_invisible(ele) ⇒ Boolean true, Boolean false
- #element_is_present(ele) ⇒ Boolean true, Boolean false
- #element_is_visible(ele) ⇒ Boolean true, Boolean false
-
#element_or_locator(ele) ⇒ Object
internal method.
- #elements_count_to_be_equal_to(ele, count) ⇒ Boolean true, Boolean false
- #elements_count_to_be_less_than(ele, count) ⇒ Boolean true, Boolean false
- #elements_count_to_be_more_than(ele, count) ⇒ Boolean true, Boolean false
- #text_in_element_to_include(ele, txt) ⇒ Boolean true, Boolean false (also: #text_in_element_to_contain)
- #text_in_element_to_match(ele, attr) ⇒ Boolean true, Boolean false
- #text_to_be_on_page(txt) ⇒ Boolean true, Boolean false
- #title_to_include ⇒ Boolean true, Boolean false (also: #title_to_contain)
- #title_to_match ⇒ Boolean true, Boolean false
- #url_to_include ⇒ Boolean true, Boolean false (also: #url_to_contain)
- #url_to_match ⇒ Boolean true, Boolean false
- #waiting(time_in_secs) ⇒ object of WebDriver::Wait class
Instance Method Details
#alert_present? ⇒ Boolean true, Boolean false
7 8 9 10 11 12 |
# File 'lib/web-object/conditions/alert.rb', line 7 def alert_present? @driver.switch_to.alert true rescue false end |
#attribute_is_absent(ele, attr) ⇒ Boolean true, Boolean false Also known as: attribute_is_empty
29 30 31 32 33 34 35 36 |
# File 'lib/web-object/conditions/element_property.rb', line 29 def attribute_is_absent(ele,attr) element = element_or_locator(ele) if element.attribute(attr).empty? true else false end end |
#attribute_is_present(ele, attr) ⇒ Boolean true, Boolean false Also known as: attribute_is_not_empty
11 12 13 14 15 16 17 18 |
# File 'lib/web-object/conditions/element_property.rb', line 11 def attribute_is_present(ele,attr) element = element_or_locator(ele) if element.attribute(attr).empty? false else true end end |
#attribute_to_include(ele, attr, item) ⇒ Boolean true, Boolean false Also known as: attribute_to_contain
66 67 68 69 70 71 72 73 |
# File 'lib/web-object/conditions/element_property.rb', line 66 def attribute_to_include(ele,attr,item) element = element_or_locator(ele) if element.attribute(attr).to_s.include?(item.to_s) true else false end end |
#attribute_to_match(ele, attr) ⇒ Boolean true, Boolean false
48 49 50 51 52 53 54 55 |
# File 'lib/web-object/conditions/element_property.rb', line 48 def attribute_to_match(ele,attr,item) element = element_or_locator(ele) if element.attribute(attr).to_s == (item.to_s) true else false end end |
#element_is_absent(ele) ⇒ Boolean true, Boolean false
102 103 104 105 106 107 108 109 |
# File 'lib/web-object/conditions/element_interaction.rb', line 102 def element_is_absent(locator) begin @driver.find_element(locator) false rescue true end end |
#element_is_clickable(ele) ⇒ Boolean true, Boolean false
9 10 11 12 13 14 15 16 |
# File 'lib/web-object/conditions/element_interaction.rb', line 9 def element_is_clickable(ele) element = element_or_locator(ele) if element_is_visible(element) and element_is_enabled(element) true else false end end |
#element_is_disabled(ele) ⇒ Boolean true, Boolean false
41 42 43 44 45 46 47 48 |
# File 'lib/web-object/conditions/element_interaction.rb', line 41 def element_is_disabled(ele) element = element_or_locator(ele) if element.enabled? false else true end end |
#element_is_enabled(ele) ⇒ Boolean true, Boolean false
25 26 27 28 29 30 31 32 |
# File 'lib/web-object/conditions/element_interaction.rb', line 25 def element_is_enabled(ele) element = element_or_locator(ele) if element.enabled? true else false end end |
#element_is_invisible(ele) ⇒ Boolean true, Boolean false
73 74 75 76 77 78 79 80 |
# File 'lib/web-object/conditions/element_interaction.rb', line 73 def element_is_invisible(ele) element = element_or_locator(ele) if element.displayed? false else true end end |
#element_is_present(ele) ⇒ Boolean true, Boolean false
88 89 90 91 92 93 94 95 |
# File 'lib/web-object/conditions/element_interaction.rb', line 88 def element_is_present(locator) begin @driver.find_element(locator) true rescue false end end |
#element_is_visible(ele) ⇒ Boolean true, Boolean false
57 58 59 60 61 62 63 64 |
# File 'lib/web-object/conditions/element_interaction.rb', line 57 def element_is_visible(ele) element = element_or_locator(ele) if element.displayed? true else false end end |
#element_or_locator(ele) ⇒ Object
internal method
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/web-object/conditions/element_interaction.rb', line 112 def element_or_locator(ele) if ele.class == Hash begin @driver.find_element(ele) rescue raise 'Looks like the element itself is not present on the page, Please wait for element to be present' end else ele end end |
#elements_count_to_be_equal_to(ele, count) ⇒ Boolean true, Boolean false
43 44 45 46 47 48 49 50 |
# File 'lib/web-object/conditions/elements_count.rb', line 43 def elements_count_to_be_equal_to(loc,count) elements = @driver.find_elements(loc) if elements.size == count.to_i true else false end end |
#elements_count_to_be_less_than(ele, count) ⇒ Boolean true, Boolean false
27 28 29 30 31 32 33 34 |
# File 'lib/web-object/conditions/elements_count.rb', line 27 def elements_count_to_be_less_than(loc,count) elements = @driver.find_elements(loc) if elements.size < count.to_i true else false end end |
#elements_count_to_be_more_than(ele, count) ⇒ Boolean true, Boolean false
10 11 12 13 14 15 16 17 |
# File 'lib/web-object/conditions/elements_count.rb', line 10 def elements_count_to_be_more_than(loc,count) elements = @driver.find_elements(loc) if elements.size > count.to_i true else false end end |
#text_in_element_to_include(ele, txt) ⇒ Boolean true, Boolean false Also known as: text_in_element_to_contain
40 41 42 43 44 45 46 |
# File 'lib/web-object/conditions/text.rb', line 40 def text_in_element_to_include(ele, txt) if element_or_locator(ele).text.include?(txt) true else false end end |
#text_in_element_to_match(ele, attr) ⇒ Boolean true, Boolean false
24 25 26 27 28 29 30 |
# File 'lib/web-object/conditions/text.rb', line 24 def text_in_element_to_match(ele, txt) if element_or_locator(ele).text == txt true else false end end |
#text_to_be_on_page(txt) ⇒ Boolean true, Boolean false
8 9 10 11 12 13 14 15 |
# File 'lib/web-object/conditions/text.rb', line 8 def text_to_be_on_page(txt) # puts element_or_locator({:tag_name => 'body'}).text if element_or_locator({:tag_name => 'body'}).text.include?(txt) true else false end end |
#title_to_include ⇒ Boolean true, Boolean false Also known as: title_to_contain
22 23 24 25 26 27 28 29 |
# File 'lib/web-object/conditions/title.rb', line 22 def title_to_include(title) actual = @driver.title if actual.include?(title) true else false end end |
#title_to_match ⇒ Boolean true, Boolean false
8 9 10 11 12 13 14 15 |
# File 'lib/web-object/conditions/title.rb', line 8 def title_to_match(title) actual = @driver.title if actual == title true else false end end |
#url_to_include ⇒ Boolean true, Boolean false Also known as: url_to_contain
22 23 24 25 26 27 28 29 |
# File 'lib/web-object/conditions/url.rb', line 22 def url_to_include(url) actual = @driver.current_url if actual.include?(url) true else false end end |
#url_to_match ⇒ Boolean true, Boolean false
8 9 10 11 12 13 14 15 |
# File 'lib/web-object/conditions/url.rb', line 8 def url_to_match(url) actual = @driver.current_url if actual == url true else false end end |
#waiting(time_in_secs) ⇒ object of WebDriver::Wait class
7 8 9 |
# File 'lib/web-object/conditions/waiting.rb', line 7 def waiting(time_in_secs) Selenium::WebDriver::Wait.new(:timeout => time_in_secs.to_i) end |