lib/selenium/client/idiomatic.rb in selenium-client-1.2.16 vs lib/selenium/client/idiomatic.rb in selenium-client-1.2.17

- old
+ new

@@ -40,22 +40,22 @@ # 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 - remote_control_command "waitForPageToLoad", [actual_timeout * 1000,] + remote_control_command "waitForPageToLoad", + [actual_timeout_in_milliseconds(timeout_in_seconds),] 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 ,] + remote_control_command "waitForPopUp", + [window_id, actual_timeout_in_milliseconds(timeout_in_seconds) ,] 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 @@ -72,10 +72,12 @@ # * wait :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear # * wait :wait_for => :no_text, :text => /A Regexp/ # 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 => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value' # * wait :wait_for => :no_value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to not be 'some value' + # * wait :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible + # * wait :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible # * 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) @@ -98,10 +100,14 @@ select_window options[:window] if options[:select] elsif options[:wait_for] == :value wait_for_field_value options[:element], options[:value], options elsif options[:wait_for] == :no_value wait_for_no_field_value options[:element], options[:value], options + elsif options[:wait_for] == :visible + wait_for_visible options[:element], options + elsif options[:wait_for] == :not_visible + wait_for_not_visible options[:element], options elsif options[:wait_for] == :condition wait_for_condition options[:javascript], options[:timeout_in_seconds] end end @@ -131,10 +137,12 @@ # * click "a_locator", :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear # * click "a_locator", :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear # * click "a_locator", :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text' # * click "a_locator", :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value' # * click "a_locator", :wait_for => :no_value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to not be 'some value' + # * click "a_locator", :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible + # * click "a_locator", :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible # * click "a_locator", :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={}) @@ -282,11 +290,11 @@ # 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,] + remote_control_command "setTimeout", [actual_timeout_in_milliseconds(timeout_in_seconds),] end # Returns the text from a cell of a table. The cellAddress syntax # tableLocator.row.column, where row and column start at 0. # @@ -306,11 +314,12 @@ # # # * 'script' is the JavaScript snippet to run # * 'timeout_in_seconds' is a timeout in seconds, after which this command will return with an error def wait_for_condition(script, timeout_in_seconds = nil) - remote_control_command "waitForCondition", [script, (timeout_in_seconds || default_timeout_in_seconds) * 1000,] + remote_control_command "waitForCondition", + [script, actual_timeout_in_milliseconds(timeout_in_seconds),] end # 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. @@ -329,10 +338,12 @@ # * go_back :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear # * go_back "a_locator", :wait_for => :no_text, :text => /A Regexp/ # 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 # * go_back :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value' + # * go_back :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible + # * go_back :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible # * go_back :wait_for => :no_value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to not be 'some value' # # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout # is used. def go_back(options={}) @@ -464,9 +475,14 @@ # Setting an execution can be useful to troubleshoot of capture videos def execution_delay=(delay_in_milliseconds) remote_control_command "setSpeed", [delay_in_milliseconds] end + def actual_timeout_in_milliseconds(timeout_in_seconds) + actual_timeout = (timeout_in_seconds || + default_timeout_in_seconds).to_i + actual_timeout * 1000 + end end end end