lib/page-object/platforms/selenium_element.rb in page-object-0.1.1 vs lib/page-object/platforms/selenium_element.rb in page-object-0.2
- old
+ new
@@ -87,8 +87,56 @@
# Click this element
#
def click
@element.click
end
+
+ #
+ # Waits until the element is present
+ #
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
+ #
+ def when_present(timeout=5)
+ wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
+ wait.until do
+ self.exists?
+ end
+ end
+
+ #
+ # Waits until the element is visible
+ #
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
+ #
+ def when_visible(timeout=5)
+ wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
+ wait.until do
+ self.visible?
+ end
+ end
+
+ #
+ # Waits until the element is not visible
+ #
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
+ #
+ def when_not_visible(timeout=5)
+ wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
+ wait.until do
+ not self.visible?
+ end
+ end
+
+ #
+ # Waits until the block returns true
+ #
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
+ # @param [String] the message to display if the event timeouts
+ # @param the block to execute when the event occurrs
+ #
+ def wait_until(timeout=5, message=nil, &block)
+ wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
+ wait.until &block
+ end
end
end
end
\ No newline at end of file