module WebConditions
Public Instance Methods
@method alert_present? @return [Boolean true] – if alert is present on page @return [Boolean false] – if alert is absent from page
# File lib/web-object/conditions/alert.rb, line 7 def alert_present? @driver.switch_to.alert true rescue false end
@method attribute_is_absent
(ele,attr) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param attr [String] – attribute that need to be checked for absence @return [Boolean true] – if element attribute is not found in the html tag in page source @return [Boolean false] – if element attribute is found in the html tag in page source
# 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
@method attribute_is_present
(ele,attr) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param attr [String] – attribute that need to be checked for presence @return [Boolean true] – if element attribute is found in the html tag in page source @return [Boolean false] – if element attribute is not found in the html tag in page source
# 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
@method attribute_to_match
(ele,attr) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param attr [String] – attribute that need to be checked for actual value in page source @param item [String] – substring value of attribute that needs to be contained within actual in page source @return [Boolean true] – if element attribute substring is present within actual value in the html tag in page source @return [Boolean false] – if actual attribute value does not contain passed substring
# 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
@method attribute_to_match
(ele,attr) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param attr [String] – attribute that need to be checked for actual value in page source @param item [String] – expected value of attribute that needs to be exactly matched with actual in page source @return [Boolean true] – if element attribute value is exact match with expected value in the html tag in page source @return [Boolean false] – if element attribute is mismatch with expected value in the html tag in page source
# 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
@method element_is_absent
(ele) @param locator [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is absent in DOM of page @return [Boolean false] – if element is present from DOM of page
# 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
@method element_is_clickable
(ele) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is clickable(visible and enabled) on page @return [Boolean false] – if element is not clickable(visible and enabled) on page
# 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
@method element_is_disabled
(ele) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is disabled on page @return [Boolean false] – if element is enabled on page
# 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
@method element_is_enabled
(ele) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is enabled on page @return [Boolean false] – if element is disabled on page
# 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
@method element_is_invisible
(ele) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is invisible / hidden on page @return [Boolean false] – if element is visible on page
# 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
@method element_is_present
(ele) @param locator [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is present in DOM of page @return [Boolean false] – if element is absent from DOM of page
# 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
@method element_is_visible
(ele) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @return [Boolean true] – if element is visible on page @return [Boolean false] – if element is invisible / hidden on page
# 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
internal method
# 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
@method elements_count_to_be_equal_to
(ele,count) @param ele [Array of WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param count [Fixnum] – expected count of elements present on page @return [Boolean true] – if actual count found on page is less than expected count passed in param @return [Boolean false] – if actual count found on page is greater than expected count passed in param
# File lib/web-object/conditions/element_property.rb, line 117 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
@method elements_count_to_be_less_than
(ele,count) @param ele [Array of WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param count [Fixnum] – expected count of elements present on page @return [Boolean true] – if actual count found on page is less than expected count passed in param @return [Boolean false] – if actual count found on page is greater than expected count passed in param
# File lib/web-object/conditions/element_property.rb, line 101 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
@method elements_count_to_be_more_than
(ele,count) @param ele [Array of WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param count [Fixnum] – expected count of elements present on page @return [Boolean true] – if actual count found on page is greater than expected count passed in param @return [Boolean false] – if actual count found on page is less than expected count passed in param
# File lib/web-object/conditions/element_property.rb, line 84 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
@method text_in_element_to_match
(ele,attr) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param txt [String] – text that will be checked in the body of the page @return [Boolean true] – if text is found inside element and is exact match of the passed text in parameter @return [Boolean false] – if text is found inside element and is not an exact match of the passed text in parameter @alias text_in_element_to_contain
(txt) – alternative name for this method, can be used as both
# 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
@method text_in_element_to_match
(ele,attr) @param ele [WebElement object] @param ele [locator Hash] – eg {:id => 'some_id'}] @param txt [String] – text that will be checked in the body of the page @return [Boolean true] – if text is found inside element and is exact match of the passed text in parameter @return [Boolean false] – if text is found inside element and is not an exact match of the passed text in parameter
# 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
@method text_to_be_on_page
(txt) @param txt [String] @return [Boolean true] – if text is found in the body of page @return [Boolean false] – if text is not found in the body of page
# 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
@method title_to_include
@param [title] – expected title to match the actual title of the web page @return [Boolean true] – if expected title is included in the actual title on the web page @return [Boolean false] – if expected title is not included in the actual title on the web page
# 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
@method title_to_match
@param [title] – expected title to match the actual title of the web page @return [Boolean true] – if expected title matches the actual title on the web page @return [Boolean false] – if expected title does not match the actual title on the web page
# 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
@method url_to_include
@param [url] – part of the expected url to be present in actual url in the browser @return [Boolean true] – if expected url in parameter in present in actual url @return [Boolean false] – if expected url in parameter in not present in actual url
# 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
@method url_to_match
@param [url] – expected url to match the actual url on the browser @return [Boolean true] – if expected url matches the actual url on the browser @return [Boolean false] – if expected url does not match the actual url on the browser
# 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
@method waiting(time_in_secs) @param time_in_secs [Fixnum] – Maximum amount of time a condition needs to wait @return [object of WebDriver::Wait class]
# 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