selenium-webdriver 2.18.0 → 2.19.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  module Selenium
2
2
  module Client
3
-
3
+
4
4
  # Driver constructor and session management commands
5
5
  module Base
6
6
  include Selenium::Client::Protocol
@@ -8,11 +8,11 @@ module Selenium
8
8
  include Selenium::Client::Extensions
9
9
  include Selenium::Client::Idiomatic
10
10
 
11
- attr_reader :host, :port, :browser_string, :browser_url,
12
- :default_timeout_in_seconds,
11
+ attr_reader :host, :port, :browser_string, :browser_url,
12
+ :default_timeout_in_seconds,
13
13
  :default_javascript_framework,
14
14
  :highlight_located_element_by_default
15
-
15
+
16
16
  #
17
17
  # Create a new client driver
18
18
  #
@@ -73,7 +73,7 @@ module Selenium
73
73
  not @session_id.nil?
74
74
  end
75
75
 
76
- # Starts a new browser session (launching a new browser matching
76
+ # Starts a new browser session (launching a new browser matching
77
77
  # configuration provided at driver creation time).
78
78
  #
79
79
  # Browser session specific option can also be provided. e.g.
@@ -81,28 +81,42 @@ module Selenium
81
81
  # driver.start_new_browser_session(:captureNetworkTraffic => true)
82
82
  #
83
83
  def start_new_browser_session(options={})
84
- options_as_string = options.collect {|key,value| "#{key.to_s}=#{value.to_s}"}.sort.join(";")
85
- result = string_command "getNewBrowserSession", [@browser_string, @browser_url, @extension_js, options_as_string]
86
- @session_id = result
84
+ start_args = [@browser_string, @browser_url, @extension_js]
85
+
86
+ if driver = options.delete(:driver)
87
+ expected_browser_string = "*webdriver"
88
+ unless @browser_string == expected_browser_string
89
+ raise ArgumentError, "can't use :driver unless the browser string is #{expected_browser_string.inspect} (got #{@browser_string.inspect})"
90
+ end
91
+
92
+ sid = driver.capabilities['webdriver.remote.sessionid']
93
+ sid or raise ArgumentError, "This driver can not be wrapped in the RC API."
94
+
95
+ start_args << "webdriver.remote.sessionid=#{sid}"
96
+ end
97
+
98
+ start_args << options.collect {|key,value| "#{key.to_s}=#{value.to_s}"}.sort.join(";")
99
+
100
+ @session_id = string_command "getNewBrowserSession", start_args
87
101
  # Consistent timeout on the remote control and driver side.
88
102
  # Intuitive and this is what you want 90% of the time
89
- self.remote_control_timeout_in_seconds = @default_timeout_in_seconds
103
+ self.remote_control_timeout_in_seconds = @default_timeout_in_seconds
90
104
  self.highlight_located_element = true if highlight_located_element_by_default
91
105
  end
92
-
106
+
93
107
  def close_current_browser_session
94
108
  remote_control_command "testComplete" if @session_id
95
109
  @session_id = nil
96
110
  end
97
-
98
- def start
99
- start_new_browser_session
111
+
112
+ def start(opts = {})
113
+ start_new_browser_session opts
100
114
  end
101
-
115
+
102
116
  def stop
103
117
  close_current_browser_session
104
118
  end
105
-
119
+
106
120
  def chrome_backend?
107
121
  ["*chrome", "*firefox", "*firefox2", "*firefox3"].include?(@browser_string)
108
122
  end
@@ -111,8 +125,8 @@ module Selenium
111
125
  @extension_js = new_javascript_extension
112
126
  end
113
127
  alias :set_extension_js :javascript_extension=
114
-
128
+
115
129
  end
116
-
130
+
117
131
  end
118
132
  end
@@ -5,6 +5,6 @@ module Selenium
5
5
  class Driver
6
6
  include Selenium::Client::Base
7
7
  end
8
-
8
+
9
9
  end
10
10
  end
@@ -1,9 +1,9 @@
1
1
  module Selenium
2
2
  module Client
3
- class CommandError < RuntimeError
3
+ class CommandError < RuntimeError
4
4
  end
5
-
6
- class ProtocolError < RuntimeError
5
+
6
+ class ProtocolError < RuntimeError
7
7
  end
8
8
  end
9
9
  end
@@ -3,17 +3,17 @@ module Selenium
3
3
 
4
4
  # Convenience methods not explicitely part of the protocol
5
5
  module Extensions
6
-
6
+
7
7
  # These for all Ajax request to finish (Only works if you are using prototype, the wait happens in the browser)
8
8
  #
9
9
  # See http://davidvollbracht.com/2008/6/4/30-days-of-tech-day-3-waitforajax for
10
10
  # more background.
11
11
  def wait_for_ajax(options={})
12
12
  builder = JavascriptExpressionBuilder.new active_javascript_framework(options)
13
- wait_for_condition builder.no_pending_ajax_requests.script,
13
+ wait_for_condition builder.no_pending_ajax_requests.script,
14
14
  options[:timeout_in_seconds]
15
15
  end
16
-
16
+
17
17
  # Wait for all Prototype effects to be processed (the wait happens in the browser).
18
18
  #
19
19
  # Credits to http://github.com/brynary/webrat/tree/master
@@ -22,17 +22,17 @@ module Selenium
22
22
  wait_for_condition builder.no_pending_effects.script,
23
23
  options[:timeout_in_seconds]
24
24
  end
25
-
25
+
26
26
  # Wait for an element to be present (the wait happens in the browser).
27
27
  def wait_for_element(locator, options={})
28
- builder = JavascriptExpressionBuilder.new
28
+ builder = JavascriptExpressionBuilder.new
29
29
  builder.find_element(locator).append("element != null;")
30
30
  wait_for_condition builder.script, options[:timeout_in_seconds]
31
31
  end
32
32
 
33
33
  # Wait for an element to NOT be present (the wait happens in the browser).
34
34
  def wait_for_no_element(locator, options={})
35
- builder = JavascriptExpressionBuilder.new
35
+ builder = JavascriptExpressionBuilder.new
36
36
  builder.find_element(locator).append("element == null;")
37
37
  wait_for_condition builder.script, options[:timeout_in_seconds]
38
38
  end
@@ -45,15 +45,15 @@ module Selenium
45
45
  #
46
46
  # ==== Parameters
47
47
  # wait_for_text accepts an optional hash of parameters:
48
- # * <tt>:element</tt> - a selenium locator for an element limiting
48
+ # * <tt>:element</tt> - a selenium locator for an element limiting
49
49
  # the search scope.
50
50
  # * <tt>:timeout_in_seconds</tt> - duration in seconds after which we
51
51
  # time out if text cannot be found.
52
- #
52
+ #
53
53
  # ==== Regular Expressions
54
54
  # In addition to plain strings, wait_for_text accepts regular expressions
55
55
  # as the pattern specification.
56
- #
56
+ #
57
57
  # ==== Examples
58
58
  # The following are equivalent, and will match "some text" anywhere
59
59
  # within the document:
@@ -64,47 +64,47 @@ module Selenium
64
64
  # wait_for_text /some text/, :element => "container"
65
65
  #
66
66
  # This will match "some text" only if it exactly matches the complete
67
- # innerHTML of the specified element:
67
+ # innerHTML of the specified element:
68
68
  # wait_for_text "some text", :element => "container"
69
69
  #
70
70
  def wait_for_text(pattern, options={})
71
- builder = JavascriptExpressionBuilder.new
71
+ builder = JavascriptExpressionBuilder.new
72
72
  builder.find_text(pattern, options).append("text_match == true;")
73
73
  wait_for_condition builder.script, options[:timeout_in_seconds]
74
74
  end
75
-
75
+
76
76
  # Wait for some text to NOT be present (the wait happens in the browser).
77
77
  #
78
78
  # See wait_for_text for usage details.
79
79
  def wait_for_no_text(pattern, options={})
80
- builder = JavascriptExpressionBuilder.new
80
+ builder = JavascriptExpressionBuilder.new
81
81
  builder.find_text(pattern, options).append("text_match == false;")
82
82
  wait_for_condition builder.script, options[:timeout_in_seconds]
83
83
  end
84
84
 
85
85
  # Wait for a field to get a specific value (the wait happens in the browser).
86
86
  def wait_for_field_value(locator, expected_value, options={})
87
- builder = JavascriptExpressionBuilder.new
87
+ builder = JavascriptExpressionBuilder.new
88
88
  builder.find_element(locator).element_value_is(expected_value)
89
89
  wait_for_condition builder.script, options[:timeout_in_seconds]
90
90
  end
91
91
 
92
92
  # Wait for a field to not have a specific value (the wait happens in the browser).
93
93
  def wait_for_no_field_value(locator, expected_value, options={})
94
- builder = JavascriptExpressionBuilder.new
94
+ builder = JavascriptExpressionBuilder.new
95
95
  builder.find_element(locator).element_value_is_not(expected_value)
96
96
  wait_for_condition builder.script, options[:timeout_in_seconds]
97
97
  end
98
98
 
99
99
  # Wait for something to be visible (the wait happens in the browser).
100
100
  def wait_for_visible(locator, options={})
101
- builder = JavascriptExpressionBuilder.new
101
+ builder = JavascriptExpressionBuilder.new
102
102
  wait_for_condition builder.visible(locator).script, options[:timeout_in_seconds]
103
103
  end
104
104
 
105
105
  # Wait for something to not be visible (the wait happens in the browser).
106
106
  def wait_for_not_visible(locator, options={})
107
- builder = JavascriptExpressionBuilder.new
107
+ builder = JavascriptExpressionBuilder.new
108
108
  wait_for_condition builder.not_visible(locator).script, options[:timeout_in_seconds]
109
109
  end
110
110
 
@@ -1,6 +1,6 @@
1
1
  module Selenium
2
2
  module Client
3
-
3
+
4
4
  # Provide a more idiomatic API than the generated Ruby driver.
5
5
  #
6
6
  # Work in progress...
@@ -8,7 +8,7 @@ module Selenium
8
8
 
9
9
  # Return the text content of an HTML element (rendered text shown to
10
10
  # the user). Works for any HTML element that contains text.
11
- #
11
+ #
12
12
  #
13
13
  # This command uses either the textContent (Mozilla-like browsers)
14
14
  # or the innerText (IE-like browsers) of the element, which is the
@@ -20,7 +20,7 @@ module Selenium
20
20
  string_command "getText", [locator,]
21
21
  end
22
22
  alias :text_content :text
23
-
23
+
24
24
  # Return the title of the current HTML page.
25
25
  def title
26
26
  string_command "getTitle"
@@ -32,17 +32,17 @@ module Selenium
32
32
  end
33
33
 
34
34
  # Waits for a new page to load.
35
- #
36
- # Selenium constantly keeps track of new pages loading, and sets a
37
- # "newPageLoaded" flag when it first notices a page load. Running
38
- # any other Selenium command after turns the flag to false. Hence,
39
- # if you want to wait for a page to load, you must wait immediately
35
+ #
36
+ # Selenium constantly keeps track of new pages loading, and sets a
37
+ # "newPageLoaded" flag when it first notices a page load. Running
38
+ # any other Selenium command after turns the flag to false. Hence,
39
+ # if you want to wait for a page to load, you must wait immediately
40
40
  # after a Selenium command that caused a page-load.
41
- #
42
- # * 'timeout_in_seconds' is a timeout in seconds, after which this
41
+ #
42
+ # * 'timeout_in_seconds' is a timeout in seconds, after which this
43
43
  # command will return with an error
44
44
  def wait_for_page(timeout_in_seconds=nil)
45
- remote_control_command "waitForPageToLoad",
45
+ remote_control_command "waitForPageToLoad",
46
46
  [actual_timeout_in_milliseconds(timeout_in_seconds),]
47
47
  end
48
48
  alias_method :wait_for_page_to_load, :wait_for_page
@@ -52,7 +52,7 @@ module Selenium
52
52
  # window_id is the JavaScript window "name" of the window that will appear (not the text of the title bar)
53
53
  # timeout_in_seconds is a timeout in seconds, after which the action will return with an error
54
54
  def wait_for_popup(window_id, timeout_in_seconds=nil)
55
- remote_control_command "waitForPopUp",
55
+ remote_control_command "waitForPopUp",
56
56
  [window_id, actual_timeout_in_milliseconds(timeout_in_seconds) ,]
57
57
  end
58
58
 
@@ -110,7 +110,7 @@ module Selenium
110
110
  wait_for_condition options[:javascript], options[:timeout_in_seconds]
111
111
  end
112
112
  end
113
-
113
+
114
114
  # Gets the entire text of the page.
115
115
  def body_text
116
116
  string_command "getBodyText"
@@ -118,9 +118,9 @@ module Selenium
118
118
 
119
119
  # Clicks on a link, button, checkbox or radio button.
120
120
  #
121
- # 'locator' is an element locator
122
- #
123
- # Using 'options' you can automatically wait for an event to happen after the
121
+ # 'locator' is an element locator
122
+ #
123
+ # Using 'options' you can automatically wait for an event to happen after the
124
124
  # click. e.g.
125
125
  #
126
126
  # * click "a_locator", :wait_for => :page # will wait for a new page to load
@@ -175,9 +175,9 @@ module Selenium
175
175
  boolean_command "isVisible", [locator,]
176
176
  end
177
177
 
178
- # Gets the (whitespace-trimmed) value of an input field
178
+ # Gets the (whitespace-trimmed) value of an input field
179
179
  # (or anything else with a value parameter).
180
- # For checkbox/radio elements, the value will be "on" or "off"
180
+ # For checkbox/radio elements, the value will be "on" or "off"
181
181
  # depending on whether the element is checked or not.
182
182
  #
183
183
  # * 'locator' is an element locator
@@ -185,12 +185,12 @@ module Selenium
185
185
  string_command "getValue", [locator,]
186
186
  end
187
187
 
188
- # Alias for +field+
188
+ # Alias for +field+
189
189
  def value(locator)
190
190
  field locator
191
191
  end
192
192
 
193
- # Returns whether a toggle-button (checkbox/radio) is checked.
193
+ # Returns whether a toggle-button (checkbox/radio) is checked.
194
194
  # Fails if the specified element doesn't exist or isn't a toggle-button.
195
195
  #
196
196
  # * 'locator' is an element locator pointing to a checkbox or radio button
@@ -203,9 +203,9 @@ module Selenium
203
203
  boolean_command "isAlertPresent"
204
204
  end
205
205
 
206
- # Retrieves the message of a JavaScript alert generated during the previous action,
206
+ # Retrieves the message of a JavaScript alert generated during the previous action,
207
207
  # or fail if there were no alerts.
208
- #
208
+ #
209
209
  # Getting an alert has the same effect as manually clicking OK. If an
210
210
  # alert is generated but you do not consume it with getAlert, the next Selenium action
211
211
  # will fail.
@@ -216,11 +216,11 @@ module Selenium
216
216
  # Selenium does NOT support JavaScript alerts that are generated in a
217
217
  # page's onload() event handler. In this case a visible dialog WILL be
218
218
  # generated and Selenium will hang until someone manually clicks OK.
219
- #
219
+ #
220
220
  def alert
221
221
  string_command "getAlert"
222
222
  end
223
-
223
+
224
224
  # Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
225
225
  def confirmation?
226
226
  boolean_command "isConfirmationPresent"
@@ -228,17 +228,17 @@ module Selenium
228
228
 
229
229
  # Retrieves the message of a JavaScript confirmation dialog generated during
230
230
  # the previous action.
231
- #
231
+ #
232
232
  # By default, the confirm function will return true, having the same effect
233
233
  # as manually clicking OK. This can be changed by prior execution of the
234
- # chooseCancelOnNextConfirmation command.
235
- #
234
+ # chooseCancelOnNextConfirmation command.
235
+ #
236
236
  # If an confirmation is generated but you do not consume it with getConfirmation,
237
237
  # the next Selenium action will fail.
238
- #
238
+ #
239
239
  # NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
240
240
  # dialog.
241
- #
241
+ #
242
242
  # NOTE: Selenium does NOT support JavaScript confirmations that are
243
243
  # generated in a page's onload() event handler. In this case a visible
244
244
  # dialog WILL be generated and Selenium will hang until you manually click
@@ -254,7 +254,7 @@ module Selenium
254
254
 
255
255
  # Retrieves the message of a JavaScript question prompt dialog generated during
256
256
  # the previous action.
257
- #
257
+ #
258
258
  # Successful handling of the prompt requires prior execution of the
259
259
  # answerOnNextPrompt command. If a prompt is generated but you
260
260
  # do not get/verify it, the next Selenium action will fail.
@@ -271,14 +271,14 @@ module Selenium
271
271
 
272
272
  # Returns the result of evaluating the specified JavaScript snippet whithin the browser.
273
273
  # The snippet may have multiple lines, but only the result of the last line will be returned.
274
- #
274
+ #
275
275
  # Note that, by default, the snippet will run in the context of the "selenium"
276
276
  # object itself, so <tt>this</tt> will refer to the Selenium object. Use <tt>window</tt> to
277
277
  # refer to the window of your application, e.g. <tt>window.document.getElementById('foo')</tt>
278
278
  # If you need to use
279
279
  # a locator to refer to a single element in your application page, you can
280
280
  # use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
281
- #
281
+ #
282
282
  # * 'script' is the JavaScript snippet to run
283
283
  def js_eval(script)
284
284
  string_command "getEval", [script,]
@@ -286,7 +286,7 @@ module Selenium
286
286
 
287
287
  # Set the Remote Control timeout (as opposed to the client side driver timeout).
288
288
  # This timout specifies the amount of time that Selenium Core will wait for actions to complete.
289
- #
289
+ #
290
290
  # The default timeout is 30 seconds.
291
291
  # 'timeout' is a timeout in seconds, after which the action will return with an error
292
292
  #
@@ -306,22 +306,22 @@ module Selenium
306
306
  # Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
307
307
  # The snippet may have multiple lines, but only the result of the last line
308
308
  # will be considered.
309
- #
309
+ #
310
310
  # Note that, by default, the snippet will be run in the runner's test window, not in the window
311
311
  # of your application. To get the window of your application, you can use
312
312
  # the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
313
313
  # run your JavaScript in there
314
- #
314
+ #
315
315
  #
316
316
  # * 'script' is the JavaScript snippet to run
317
317
  # * 'timeout_in_seconds' is a timeout in seconds, after which this command will return with an error
318
318
  def wait_for_condition(script, timeout_in_seconds = nil)
319
- remote_control_command "waitForCondition",
319
+ remote_control_command "waitForCondition",
320
320
  [script, actual_timeout_in_milliseconds(timeout_in_seconds),]
321
321
  end
322
322
 
323
323
  # Simulates the user clicking the "back" button on their browser.
324
- # Using 'options' you can automatically wait for an event to happen after the
324
+ # Using 'options' you can automatically wait for an event to happen after the
325
325
  # click. e.g.
326
326
  #
327
327
  # * go_back :wait_for => :page # will wait for a new page to load
@@ -387,7 +387,7 @@ module Selenium
387
387
  # need to delete it using the exact same path and domain that were used to create the cookie.
388
388
  # If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also
389
389
  # note that specifying a domain that isn't a subset of the current domain will usually fail.
390
- #
390
+ #
391
391
  # Since there's no way to discover at runtime the original path and domain of a given cookie,
392
392
  # we've added an option called 'recurse' to try all sub-domains of the current domain with
393
393
  # all paths that are a subset of the current path. Beware; this option can be slow. In
@@ -428,15 +428,15 @@ module Selenium
428
428
  #
429
429
  # The network traffic is returned in the format it was requested. Valid
430
430
  # values are: :json, :xml, or :plain.
431
- #
432
- # Warning: For browser_network_traffic to work you need to start your
433
- # browser session with the option "captureNetworkTraffic=true", which
431
+ #
432
+ # Warning: For browser_network_traffic to work you need to start your
433
+ # browser session with the option "captureNetworkTraffic=true", which
434
434
  # will force ALL traffic to go to the Remote Control proxy even for
435
435
  # more efficient browser modes like `*firefox` and `*safari`.
436
436
  def browser_network_traffic(format = :plain)
437
437
  raise "format must be :plain, :json, or :xml" \
438
438
  unless [:plain, :json, :xml].include?(format)
439
-
439
+
440
440
  remote_control_command "captureNetworkTraffic", [format.to_s]
441
441
  end
442
442
 
@@ -462,8 +462,8 @@ module Selenium
462
462
  js_eval "selenium.browserbot.shouldHighlightLocatedElement = #{boolean}"
463
463
  end
464
464
 
465
- # Get execution delay in milliseconds, i.e. a pause delay following
466
- # each selenium operation. By default, there is no such delay
465
+ # Get execution delay in milliseconds, i.e. a pause delay following
466
+ # each selenium operation. By default, there is no such delay
467
467
  # (value is 0).
468
468
  def execution_delay
469
469
  string_command "getSpeed"
@@ -478,7 +478,7 @@ module Selenium
478
478
  end
479
479
 
480
480
  def actual_timeout_in_milliseconds(timeout_in_seconds)
481
- actual_timeout = (timeout_in_seconds ||
481
+ actual_timeout = (timeout_in_seconds ||
482
482
  default_timeout_in_seconds).to_i
483
483
  actual_timeout * 1000
484
484
  end