lib/selenium/client/idiomatic.rb in selenium-client-1.2 vs lib/selenium/client/idiomatic.rb in selenium-client-1.2.1
- old
+ new
@@ -1,13 +1,11 @@
-#
-# Provide a more idiomatic API than the generated Ruby driver.
-#
-# Work on progress...
-#
module Selenium
module Client
+ # Provide a more idiomatic API than the generated Ruby driver.
+ #
+ # Work in progress...
module Idiomatic
# Return the text content of an HTML element (rendered text shown to
# the user). Works for any HTML element that contains text.
#
@@ -16,21 +14,21 @@
# or the innerText (IE-like browsers) of the element, which is the
# rendered text shown to the user.
#
# 'locator' is an Selenium element locator
def text_content(locator)
- get_string "getText", [locator,]
+ string_command"getText", [locator,]
end
# Return the title of the current HTML page.
def title
- get_string "getTitle"
+ string_command"getTitle"
end
# Returns the absolute URL of the current page.
def location
- get_string "getLocation"
+ string_command"getLocation"
end
# Waits for a new page to load.
#
# Selenium constantly keeps track of new pages loading, and sets a
@@ -41,57 +39,74 @@
#
# 'timeout_in_seconds' is a timeout in seconds, after which this
# command will return with an error
def wait_for_page(timeout_in_seconds=nil)
actual_timeout = timeout_in_seconds || default_timeout_in_seconds
- do_command "waitForPageToLoad", [actual_timeout * 1000,]
+ remote_control_command "waitForPageToLoad", [actual_timeout * 1000,]
end
# Gets the entire text of the page.
def body_text
- get_string "getBodyText"
+ string_command"getBodyText"
end
# Clicks on a link, button, checkbox or radio button. If the click action
# causes a new page to load (like a link usually does), call
# waitForPageToLoad.
#
# 'locator' is an element locator
def click(locator, options={})
- do_command("click", [locator,])
+ remote_control_command("click", [locator,])
if options[:wait_for] == :page
wait_for_page options[:timeout_in_seconds]
+ elsif options[:wait_for] == :ajax
+ wait_for_ajax options[:timeout_in_seconds]
+ elsif options[:wait_for] == :effects
+ wait_for_effects options[:timeout_in_seconds]
end
end
# Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
#
# 'pattern' is a pattern to match with the text of the page
def text_present?(pattern)
- get_boolean "isTextPresent", [pattern,]
+ boolean_command "isTextPresent", [pattern,]
end
# Verifies that the specified element is somewhere on the page.
#
# 'locator' is an element locator
def element_present?(locator)
- get_boolean "isElementPresent", [locator,]
+ boolean_command "isElementPresent", [locator,]
end
# Gets the (whitespace-trimmed) value of an input field
# (or anything else with a value parameter).
# For checkbox/radio elements, the value will be "on" or "off"
# depending on whether the element is checked or not.
#
# 'locator' is an element locator
+ def field(locator)
+ string_command "getValue", [locator,]
+ end
+
+ # Alias for +field+
def value(locator)
- get_string "getValue", [locator,]
+ field locator
end
+ # Returns whether a toggle-button (checkbox/radio) is checked.
+ # Fails if the specified element doesn't exist or isn't a toggle-button.
+ #
+ # 'locator' is an element locator pointing to a checkbox or radio button
+ def checked?(locator)
+ boolean_command "isChecked", [locator,]
+ end
+
# Whether an alert occurred
def alert?
- get_boolean "isAlertPresent"
+ boolean_command "isAlertPresent"
end
# Retrieves the message of a JavaScript alert generated during the previous action,
# or fail if there were no alerts.
#
@@ -103,16 +118,16 @@
# Selenium does NOT support JavaScript alerts that are generated in a
# page's onload() event handler. In this case a visible dialog WILL be
# generated and Selenium will hang until someone manually clicks OK.
#
def alert
- get_string "getAlert"
+ string_command"getAlert"
end
# Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
def confirmation?
- get_boolean "isConfirmationPresent"
+ boolean_command "isConfirmationPresent"
end
# Retrieves the message of a JavaScript confirmation dialog generated during
# the previous action.
#
@@ -129,16 +144,16 @@
# NOTE: Selenium does NOT support JavaScript confirmations that are
# generated in a page's onload() event handler. In this case a visible
# dialog WILL be generated and Selenium will hang until you manually click
# OK.
def confirmation
- get_string "getConfirmation"
+ string_command"getConfirmation"
end
# Whether a prompt occurred
def prompt?
- get_boolean "isPromptPresent"
+ boolean_command "isPromptPresent"
end
# Retrieves the message of a JavaScript question prompt dialog generated during
# the previous action.
#
@@ -151,11 +166,11 @@
#
# NOTE: Selenium does NOT support JavaScript prompts that are generated in a
# page's onload() event handler. In this case a visible dialog WILL be
# generated and Selenium will hang until someone manually clicks OK.
def prompt
- get_string "getPrompt"
+ string_command"getPrompt"
end
# Returns the result of evaluating the specified JavaScript snippet whithin the browser.
# The snippet may have multiple lines, but only the result of the last line will be returned.
#
@@ -166,12 +181,30 @@
# a locator to refer to a single element in your application page, you can
# use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
#
# 'script' is the JavaScript snippet to run
def js_eval(script)
- get_string "getEval", [script,]
+ string_command"getEval", [script,]
end
+ # Set the Remote Control timeout (as opposed to the client side driver timeout).
+ # This timout specifies the amount of time that Selenium Core will wait for actions to complete.
+ #
+ # The default timeout is 30 seconds.
+ # 'timeout' is a timeout in seconds, after which the action will return with an error
+ #
+ # Actions that require waiting include "open" and the "waitFor*" actions.
+ def remote_control_timeout_in_seconds=(timeout_in_seconds)
+ remote_control_command "setTimeout", [timeout_in_seconds * 1000,]
+ end
+
+ # Returns the text from a cell of a table. The cellAddress syntax
+ # tableLocator.row.column, where row and column start at 0.
+ #
+ # 'tableCellAddress' is a cell address, e.g. "foo.1.4"
+ def table_cell_text(tableCellAddress)
+ string_command "getTable", [tableCellAddress,]
+ end
# set speed
end
end