class SeleniumPage::Element
Attributes
base_element[R]
driver[R]
Public Class Methods
new(driver, base_element)
click to toggle source
# File lib/selenium_page/element.rb, line 8 def initialize(driver, base_element) raise Errors::WrongDriver unless driver.is_a? Selenium::WebDriver::Driver unless base_element.is_a? Selenium::WebDriver::Element raise Errors::WrongBaseElement end @driver = driver @base_element = base_element end
Public Instance Methods
add_childrens(parent_selector, &block)
click to toggle source
# File lib/selenium_page/element.rb, line 37 def add_childrens(parent_selector, &block) @parent_selector = parent_selector instance_exec(&block) if block_given? end
element(element_name, element_selector, &block)
click to toggle source
# File lib/selenium_page/element.rb, line 42 def element(element_name, element_selector, &block) define_singleton_method(element_name) do selector = @parent_selector + ' ' + element_selector if block_given? find_element(selector, &block) else find_element(selector) end end end
elements(collection_name, collection_selector, &block)
click to toggle source
# File lib/selenium_page/element.rb, line 53 def elements(collection_name, collection_selector, &block) define_singleton_method(collection_name) do selector = @parent_selector + ' ' + collection_selector if block_given? find_elements(selector, &block) else find_elements(selector) end end end
method_missing(called_method, *args, &block)
click to toggle source
Calls superclass method
# File lib/selenium_page/element.rb, line 21 def method_missing(called_method, *args, &block) # FIXME: should this catch some specific methods (to_s ?) ? if base_element.respond_to?(called_method) base_element.send(called_method, *args, &block) else super end end
respond_to_missing?(called_method, *)
click to toggle source
this fix the calls to :respond_to? in case of delegation to base_element
the method will stay private rubocop best practice suggestion
Calls superclass method
# File lib/selenium_page/element.rb, line 33 def respond_to_missing?(called_method, *) base_element.respond_to?(called_method) || super end
Private Instance Methods
find_element(element_selector, waiter = Selenium::WebDriver::Wait.new( timeout: SeleniumPage.wait_time ), &block)
click to toggle source
# File lib/selenium_page/element.rb, line 66 def find_element(element_selector, waiter = Selenium::WebDriver::Wait.new( timeout: SeleniumPage.wait_time ), &block) waiter.until do result = SeleniumPage::Element.new( @driver, @driver.find_element(:css, element_selector) ) result.add_childrens(element_selector, &block) result end end
find_elements(collection_selector, waiter = Selenium::WebDriver::Wait.new( timeout: SeleniumPage.wait_time ), &block)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/selenium_page/element.rb, line 80 def find_elements(collection_selector, waiter = Selenium::WebDriver::Wait.new( timeout: SeleniumPage.wait_time ), &block) waiter.until do selenium_result = @driver.find_elements(:css, collection_selector) result = [] selenium_result.each do |selenium_element| result << SeleniumPage::Element.new(@driver, selenium_element) end result.each do |selenium_page_element| selenium_page_element.add_childrens(collection_selector, &block) end result end end