lib/selenium/client/idiomatic.rb in selenium-client-1.2.9 vs lib/selenium/client/idiomatic.rb in selenium-client-1.2.10
- old
+ new
@@ -13,22 +13,24 @@
# This command uses either the textContent (Mozilla-like browsers)
# or the innerText (IE-like browsers) of the element, which is the
# rendered text shown to the user.
#
# * 'locator' is an Selenium element locator
+ #
+ # TODO - Should be renamed 'text'
def text_content(locator)
- string_command"getText", [locator,]
+ string_command "getText", [locator,]
end
# Return the title of the current HTML page.
def title
- string_command"getTitle"
+ string_command "getTitle"
end
# Returns the absolute URL of the current page.
def location
- string_command"getLocation"
+ string_command "getLocation"
end
# Waits for a new page to load.
#
# Selenium constantly keeps track of new pages loading, and sets a
@@ -38,24 +40,37 @@
# after a Selenium command that caused a page-load.
#
# * '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
+ actual_timeout = timeout_in_seconds || default_timeout_in_seconds
remote_control_command "waitForPageToLoad", [actual_timeout * 1000,]
end
+ alias_method :wait_for_page_to_load, :wait_for_page
+ # Waits for a popup window to appear and load up.
+ #
+ # window_id is the JavaScript window "name" of the window that will appear (not the text of the title bar)
+ # timeout_in_seconds is a timeout in seconds, after which the action will return with an error
+ def wait_for_popup(window_id, timeout_in_seconds=nil)
+ actual_timeout = timeout_in_seconds || default_timeout_in_seconds
+ remote_control_command "waitForPopUp", [window_id, actual_timeout * 1000 ,]
+ end
+
# Flexible wait semantics. ait is happening browser side. Useful for testing AJAX application.
#
- # * wait :wait_for => :page # will wait for a new page to load
- # * wait :wait_for => :ajax # will wait for all ajax requests to be completed (Prototype only)
- # * wait :wait_for => :effects # will wait for all Prototype effects to be rendered
- # * wait :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
- # * wait :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
- # * wait :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
- # * wait :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
- # * wait :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
+ # * wait :wait_for => :page # will wait for a new page to load
+ # * wait :wait_for => :popup, :window => 'a window id' # will wait for a new popup window to appear. Also selects the popup window for you provide `:select => true`
+ # * wait :wait_for => :ajax # will wait for all ajax requests to be completed (Prototype only)
+ # * wait :wait_for => :effects # will wait for all Prototype effects to be rendered
+ # * wait :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
+ # * wait :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
+ # * wait :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
+ # * wait :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
+ # * wait :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
+ # * wait :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
+ # * wait :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
#
# Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
# is used.
def wait_for(options)
if options[:wait_for] == :page
@@ -65,45 +80,51 @@
elsif options[:wait_for] == :element
wait_for_element options[:element], options[:timeout_in_seconds]
elsif options[:wait_for] == :no_element
wait_for_no_element options[:element], options[:timeout_in_seconds]
elsif options[:wait_for] == :text
- wait_for_text options[:text], options[:timeout_in_seconds]
+ wait_for_text options[:text], options[:element], options[:timeout_in_seconds]
elsif options[:wait_for] == :no_text
- wait_for_no_text options[:text], options[:timeout_in_seconds]
+ wait_for_no_text options[:text], options[:element], options[:timeout_in_seconds]
elsif options[:wait_for] == :effects
wait_for_effects options[:timeout_in_seconds]
+ elsif options[:wait_for] == :popup
+ wait_for_popup options[:window], options[:timeout_in_seconds]
+ select_window options[:window] if options[:select]
elsif options[:wait_for] == :condition
wait_for_condition options[:javascript], options[:timeout_in_seconds]
end
end
# Gets the entire text of the page.
def body_text
- string_command"getBodyText"
+ string_command "getBodyText"
end
# Clicks on a link, button, checkbox or radio button.
#
# 'locator' is an element locator
#
# Using 'options' you can automatically wait for an event to happen after the
# click. e.g.
#
- # * click 'some_id', :wait_for => :page # will wait for a new page to load
- # * click 'some_id', :wait_for => :ajax # will wait for all ajax requests to be completed (Prototype only)
- # * click 'some_id', :wait_for => :effects # will wait for all Prototype effects to be rendered
- # * click 'some_id', :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
- # * click 'some_id', :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
+ # * click :wait_for => :page # will wait for a new page to load
+ # * click :wait_for => :popup, :window => 'a window id' # will wait for a new popup window to appear. Also selects the popup window for you provide `:select => true`
+ # * click :wait_for => :ajax # will wait for all ajax requests to be completed (Prototype only)
+ # * click :wait_for => :effects # will wait for all Prototype effects to be rendered
+ # * click :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
+ # * click :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
# * click :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
+ # * click :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
# * click :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
- # * click 'some_id', :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
+ # * click :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
+ # * click :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
#
# Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
# is used.
def click(locator, options={})
- remote_control_command("click", [locator,])
+ remote_control_command "click", [locator,]
wait_for options
end
# Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
#
@@ -160,11 +181,11 @@
# 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
- string_command"getAlert"
+ string_command "getAlert"
end
# Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
def confirmation?
boolean_command "isConfirmationPresent"
@@ -186,11 +207,11 @@
# 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
- string_command"getConfirmation"
+ string_command "getConfirmation"
end
# Whether a prompt occurred
def prompt?
boolean_command "isPromptPresent"
@@ -208,11 +229,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
- string_command"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.
#
@@ -223,11 +244,11 @@
# 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)
- string_command"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.
#
@@ -265,18 +286,21 @@
# Simulates the user clicking the "back" button on their browser.
# Using 'options' you can automatically wait for an event to happen after the
# click. e.g.
#
- # * go_back :wait_for => :page # will wait for a new page to load
- # * go_back :wait_for => :ajax # will wait for all ajax requests to be completed (Prototype only)
- # * go_back :wait_for => :effects # will wait for all Prototype effects to be rendered
- # * go_back :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
- # * go_back :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
- # * go_back :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
- # * go_back :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
- # * go_back :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
+ # * go_back :wait_for => :page # will wait for a new page to load
+ # * go_back :wait_for => :popup, :window => 'a window id' # will wait for a new popup window to appear. Also selects the popup window for you provide `:select => true`
+ # * go_back :wait_for => :ajax # will wait for all ajax requests to be completed (Prototype only)
+ # * go_back :wait_for => :effects # will wait for all Prototype effects to be rendered
+ # * go_back :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
+ # * go_back :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
+ # * go_back :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
+ # * go_back :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
+ # * go_back :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
+ # * go_back :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
+ # * go_back :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
#
# Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
# is used.
def go_back(options={})
remote_control_command "goBack"
@@ -308,11 +332,11 @@
# 'nameValuePair' is name and value of the cookie in a format "name=value"
# 'optionsString' is options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'.
# the optionsString's format is "path=/path/, max_age=60, domain=.foo.com". The order of options are irrelevant, the unit of the value of 'max_age' is second. Note that specifying a domain that isn't a subset of the current domain will usually fail.
def create_cookie(name_value_pair, options="")
if options.kind_of? Hash
- options = options.keys.collect {|key| "#{key}=#{options[key]}" }.join(", ")
+ options = options.keys.collect {|key| "#{key}=#{options[key]}" }.sort.join(", ")
end
remote_control_command "createCookie", [name_value_pair,options,]
end
# Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you
@@ -332,9 +356,26 @@
if options.kind_of? Hash
ordered_keys = options.keys.sort {|a,b| a.to_s <=> b.to_s }
options = ordered_keys.collect {|key| "#{key}=#{options[key]}" }.join(", ")
end
remote_control_command "deleteCookie", [name,options,]
+ end
+
+ # Returns the IDs of all windows that the browser knows about.
+ def all_window_ids
+ string_array_command "getAllWindowIds"
+ end
+
+
+ # Returns the names of all windows that the browser knows about.
+ def all_window_names
+ string_array_command "getAllWindowNames"
+ end
+
+
+ # Returns the titles of all windows that the browser knows about.
+ def all_window_titles
+ string_array_command "getAllWindowTitles"
end
end
end