selenium-webdriver 2.53.3 → 3.142.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +665 -8
  3. data/Gemfile +2 -0
  4. data/LICENSE +1 -1
  5. data/README.md +2 -3
  6. data/lib/selenium/server.rb +76 -73
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +7 -0
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +102 -0
  9. data/lib/selenium/webdriver/{phantomjs.rb → atoms.rb} +10 -14
  10. data/lib/selenium/webdriver/chrome/bridge.rb +30 -101
  11. data/lib/selenium/webdriver/chrome/driver.rb +127 -0
  12. data/lib/selenium/webdriver/chrome/options.rb +190 -0
  13. data/lib/selenium/webdriver/chrome/profile.rb +21 -20
  14. data/lib/selenium/webdriver/chrome/service.rb +26 -93
  15. data/lib/selenium/webdriver/chrome.rb +15 -6
  16. data/lib/selenium/webdriver/common/action_builder.rb +52 -58
  17. data/lib/selenium/webdriver/common/alert.rb +7 -15
  18. data/lib/selenium/webdriver/common/bridge_helper.rb +18 -22
  19. data/lib/selenium/webdriver/common/driver.rb +72 -72
  20. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +45 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +50 -0
  22. data/lib/selenium/webdriver/common/driver_extensions/{has_input_devices.rb → has_debugger.rb} +11 -27
  23. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +6 -10
  24. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +51 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +7 -8
  26. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +51 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +2 -4
  28. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +2 -4
  29. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +3 -5
  30. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +2 -5
  31. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +6 -9
  32. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +9 -7
  33. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +3 -8
  34. data/lib/selenium/webdriver/common/element.rb +59 -39
  35. data/lib/selenium/webdriver/common/error.rb +259 -104
  36. data/lib/selenium/webdriver/common/file_reaper.rb +6 -14
  37. data/lib/selenium/webdriver/common/html5/local_storage.rb +8 -10
  38. data/lib/selenium/webdriver/common/html5/session_storage.rb +8 -10
  39. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +8 -16
  40. data/lib/selenium/webdriver/common/interactions/input_device.rb +54 -0
  41. data/lib/selenium/webdriver/common/interactions/interaction.rb +53 -0
  42. data/lib/selenium/webdriver/{safari/browser.rb → common/interactions/interactions.rb} +17 -14
  43. data/lib/selenium/webdriver/common/interactions/key_actions.rb +145 -0
  44. data/lib/selenium/webdriver/common/interactions/key_input.rb +66 -0
  45. data/lib/selenium/webdriver/{android.rb → common/interactions/none_input.rb} +14 -6
  46. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +363 -0
  47. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +139 -0
  48. data/lib/selenium/webdriver/common/keyboard.rb +10 -14
  49. data/lib/selenium/webdriver/common/keys.rb +102 -82
  50. data/lib/selenium/webdriver/common/log_entry.rb +7 -8
  51. data/lib/selenium/webdriver/common/logger.rb +115 -0
  52. data/lib/selenium/webdriver/common/logs.rb +4 -6
  53. data/lib/selenium/webdriver/common/manager.rb +177 -0
  54. data/lib/selenium/webdriver/common/mouse.rb +12 -14
  55. data/lib/selenium/webdriver/common/navigation.rb +4 -6
  56. data/lib/selenium/webdriver/common/options.rb +26 -127
  57. data/lib/selenium/webdriver/common/platform.rb +75 -101
  58. data/lib/selenium/webdriver/common/port_prober.rb +7 -19
  59. data/lib/selenium/webdriver/common/profile_helper.rb +8 -11
  60. data/lib/selenium/webdriver/common/proxy.rb +68 -74
  61. data/lib/selenium/webdriver/common/search_context.rb +28 -37
  62. data/lib/selenium/webdriver/common/service.rb +219 -0
  63. data/lib/selenium/webdriver/common/socket_lock.rb +15 -16
  64. data/lib/selenium/webdriver/common/socket_poller.rb +30 -28
  65. data/lib/selenium/webdriver/common/target_locator.rb +16 -18
  66. data/lib/selenium/webdriver/common/timeouts.rb +6 -8
  67. data/lib/selenium/webdriver/common/touch_action_builder.rb +5 -10
  68. data/lib/selenium/webdriver/common/touch_screen.rb +22 -23
  69. data/lib/selenium/webdriver/common/w3c_action_builder.rb +212 -0
  70. data/lib/selenium/webdriver/common/w3c_manager.rb +45 -0
  71. data/lib/selenium/webdriver/common/wait.rb +17 -16
  72. data/lib/selenium/webdriver/common/window.rb +50 -17
  73. data/lib/selenium/webdriver/common/zipper.rb +9 -13
  74. data/lib/selenium/webdriver/common.rb +21 -7
  75. data/lib/selenium/webdriver/edge/bridge.rb +34 -63
  76. data/lib/selenium/webdriver/edge/driver.rb +66 -0
  77. data/lib/selenium/webdriver/edge/options.rb +80 -0
  78. data/lib/selenium/webdriver/edge/service.rb +23 -95
  79. data/lib/selenium/webdriver/edge.rb +13 -13
  80. data/lib/selenium/webdriver/firefox/binary.rb +45 -60
  81. data/lib/selenium/webdriver/firefox/driver.rb +50 -0
  82. data/lib/selenium/webdriver/firefox/extension/prefs.json +3 -12
  83. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  84. data/lib/selenium/webdriver/firefox/extension.rb +20 -10
  85. data/lib/selenium/webdriver/firefox/launcher.rb +16 -22
  86. data/lib/selenium/webdriver/firefox/legacy/driver.rb +83 -0
  87. data/lib/selenium/webdriver/firefox/marionette/bridge.rb +49 -0
  88. data/lib/selenium/webdriver/firefox/marionette/driver.rb +90 -0
  89. data/lib/selenium/webdriver/firefox/options.rb +162 -0
  90. data/lib/selenium/webdriver/firefox/profile.rb +47 -48
  91. data/lib/selenium/webdriver/firefox/profiles_ini.rb +11 -18
  92. data/lib/selenium/webdriver/firefox/service.rb +24 -95
  93. data/lib/selenium/webdriver/firefox/util.rb +2 -4
  94. data/lib/selenium/webdriver/firefox.rb +27 -12
  95. data/lib/selenium/webdriver/ie/driver.rb +85 -0
  96. data/lib/selenium/webdriver/ie/options.rb +138 -0
  97. data/lib/selenium/webdriver/ie/service.rb +54 -0
  98. data/lib/selenium/webdriver/ie.rb +12 -10
  99. data/lib/selenium/webdriver/remote/bridge.rb +100 -564
  100. data/lib/selenium/webdriver/remote/capabilities.rb +98 -100
  101. data/lib/selenium/webdriver/remote/driver.rb +51 -0
  102. data/lib/selenium/webdriver/remote/http/common.rb +34 -22
  103. data/lib/selenium/webdriver/remote/http/curb.rb +13 -14
  104. data/lib/selenium/webdriver/remote/http/default.rb +62 -43
  105. data/lib/selenium/webdriver/remote/http/persistent.rb +12 -9
  106. data/lib/selenium/webdriver/remote/oss/bridge.rb +594 -0
  107. data/lib/selenium/webdriver/remote/oss/commands.rb +223 -0
  108. data/lib/selenium/webdriver/remote/response.rb +48 -28
  109. data/lib/selenium/webdriver/remote/server_error.rb +3 -5
  110. data/lib/selenium/webdriver/remote/w3c/bridge.rb +605 -0
  111. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +310 -0
  112. data/lib/selenium/webdriver/remote/w3c/commands.rb +157 -0
  113. data/lib/selenium/webdriver/remote.rb +10 -16
  114. data/lib/selenium/webdriver/safari/bridge.rb +17 -101
  115. data/lib/selenium/webdriver/{firefox/w3c_bridge.rb → safari/driver.rb} +27 -25
  116. data/lib/selenium/webdriver/safari/options.rb +29 -31
  117. data/lib/selenium/webdriver/safari/service.rb +38 -0
  118. data/lib/selenium/webdriver/safari.rb +27 -27
  119. data/lib/selenium/webdriver/support/abstract_event_listener.rb +19 -4
  120. data/lib/selenium/webdriver/support/block_event_listener.rb +3 -5
  121. data/lib/selenium/webdriver/support/color.rb +60 -43
  122. data/lib/selenium/webdriver/support/escaper.rb +43 -0
  123. data/lib/selenium/webdriver/support/event_firing_bridge.rb +39 -41
  124. data/lib/selenium/webdriver/support/select.rb +45 -97
  125. data/lib/selenium/webdriver/support.rb +3 -2
  126. data/lib/selenium/webdriver/{iphone.rb → version.rb} +3 -7
  127. data/lib/selenium/webdriver.rb +36 -23
  128. data/lib/selenium-webdriver.rb +2 -2
  129. data/selenium-webdriver.gemspec +42 -29
  130. metadata +331 -262
  131. data/lib/selenium/client/base.rb +0 -151
  132. data/lib/selenium/client/driver.rb +0 -29
  133. data/lib/selenium/client/errors.rb +0 -28
  134. data/lib/selenium/client/extensions.rb +0 -132
  135. data/lib/selenium/client/idiomatic.rb +0 -507
  136. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  137. data/lib/selenium/client/javascript_frameworks/jquery.rb +0 -32
  138. data/lib/selenium/client/javascript_frameworks/prototype.rb +0 -32
  139. data/lib/selenium/client/legacy_driver.rb +0 -1722
  140. data/lib/selenium/client/protocol.rb +0 -123
  141. data/lib/selenium/client/selenium_helper.rb +0 -49
  142. data/lib/selenium/client.rb +0 -57
  143. data/lib/selenium/rake/server_task.rb +0 -176
  144. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  145. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  146. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  147. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  148. data/lib/selenium/webdriver/common/w3c_error.rb +0 -194
  149. data/lib/selenium/webdriver/edge/legacy_support.rb +0 -117
  150. data/lib/selenium/webdriver/firefox/bridge.rb +0 -89
  151. data/lib/selenium/webdriver/ie/bridge.rb +0 -88
  152. data/lib/selenium/webdriver/ie/server.rb +0 -133
  153. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
  154. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -78
  155. data/lib/selenium/webdriver/phantomjs/service.rb +0 -130
  156. data/lib/selenium/webdriver/remote/commands.rb +0 -211
  157. data/lib/selenium/webdriver/remote/w3c_bridge.rb +0 -668
  158. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +0 -236
  159. data/lib/selenium/webdriver/remote/w3c_commands.rb +0 -132
  160. data/lib/selenium/webdriver/safari/resources/client.js +0 -7255
  161. data/lib/selenium/webdriver/safari/server.rb +0 -187
  162. data/lib/selenium-client.rb +0 -21
@@ -1,507 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
-
23
- # Provide a more idiomatic API than the generated Ruby driver.
24
- #
25
- # Work in progress...
26
- module Idiomatic
27
-
28
- # Return the text content of an HTML element (rendered text shown to
29
- # the user). Works for any HTML element that contains text.
30
- #
31
- #
32
- # This command uses either the textContent (Mozilla-like browsers)
33
- # or the innerText (IE-like browsers) of the element, which is the
34
- # rendered text shown to the user.
35
- #
36
- # * 'locator' is an Selenium element locator
37
- #
38
- def text(locator)
39
- string_command "getText", [locator,]
40
- end
41
- alias :text_content :text
42
-
43
- # Return the title of the current HTML page.
44
- def title
45
- string_command "getTitle"
46
- end
47
-
48
- # Returns the absolute URL of the current page.
49
- def location
50
- string_command "getLocation"
51
- end
52
-
53
- # Waits for a new page to load.
54
- #
55
- # Selenium constantly keeps track of new pages loading, and sets a
56
- # "newPageLoaded" flag when it first notices a page load. Running
57
- # any other Selenium command after turns the flag to false. Hence,
58
- # if you want to wait for a page to load, you must wait immediately
59
- # after a Selenium command that caused a page-load.
60
- #
61
- # * 'timeout_in_seconds' is a timeout in seconds, after which this
62
- # command will return with an error
63
- def wait_for_page(timeout_in_seconds=nil)
64
- remote_control_command "waitForPageToLoad",
65
- [actual_timeout_in_milliseconds(timeout_in_seconds),]
66
- end
67
- alias_method :wait_for_page_to_load, :wait_for_page
68
-
69
- # Waits for a popup window to appear and load up.
70
- #
71
- # window_id is the JavaScript window "name" of the window that will appear (not the text of the title bar)
72
- # timeout_in_seconds is a timeout in seconds, after which the action will return with an error
73
- def wait_for_popup(window_id, timeout_in_seconds=nil)
74
- remote_control_command "waitForPopUp",
75
- [window_id, actual_timeout_in_milliseconds(timeout_in_seconds) ,]
76
- end
77
-
78
- # Flexible wait semantics. ait is happening browser side. Useful for testing AJAX application.
79
- #
80
- # * wait :wait_for => :page # will wait for a new page to load
81
- # * 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`
82
- # * wait :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
83
- # * wait :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
84
- # * wait :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
85
- # * wait :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
86
- # * wait :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
87
- # * wait :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
88
- # * wait :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
89
- # * wait :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
90
- # * wait :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
91
- # * wait :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
92
- # * wait :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
93
- # * wait :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
94
- # * wait :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value'
95
- # * 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'
96
- # * wait :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible
97
- # * wait :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible
98
- # * wait :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
99
- #
100
- # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
101
- # is used.
102
- def wait_for(options)
103
- if options[:wait_for] == :page
104
- wait_for_page options[:timeout_in_seconds]
105
- elsif options[:wait_for] == :ajax
106
- wait_for_ajax options
107
- elsif options[:wait_for] == :element
108
- wait_for_element options[:element], options
109
- elsif options[:wait_for] == :no_element
110
- wait_for_no_element options[:element], options
111
- elsif options[:wait_for] == :text
112
- wait_for_text options[:text], options
113
- elsif options[:wait_for] == :no_text
114
- wait_for_no_text options[:text], options
115
- elsif options[:wait_for] == :effects
116
- wait_for_effects options
117
- elsif options[:wait_for] == :popup
118
- wait_for_popup options[:window], options[:timeout_in_seconds]
119
- select_window options[:window] if options[:select]
120
- elsif options[:wait_for] == :value
121
- wait_for_field_value options[:element], options[:value], options
122
- elsif options[:wait_for] == :no_value
123
- wait_for_no_field_value options[:element], options[:value], options
124
- elsif options[:wait_for] == :visible
125
- wait_for_visible options[:element], options
126
- elsif options[:wait_for] == :not_visible
127
- wait_for_not_visible options[:element], options
128
- elsif options[:wait_for] == :condition
129
- wait_for_condition options[:javascript], options[:timeout_in_seconds]
130
- end
131
- end
132
-
133
- # Gets the entire text of the page.
134
- def body_text
135
- string_command "getBodyText"
136
- end
137
-
138
- # Clicks on a link, button, checkbox or radio button.
139
- #
140
- # 'locator' is an element locator
141
- #
142
- # Using 'options' you can automatically wait for an event to happen after the
143
- # click. e.g.
144
- #
145
- # * click "a_locator", :wait_for => :page # will wait for a new page to load
146
- # * click "a_locator", :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`
147
- # * click "a_locator", :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
148
- # * click "a_locator", :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
149
- # * click "a_locator", :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
150
- # * click "a_locator", :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
151
- # * click "a_locator", :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
152
- # * click "a_locator", :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
153
- # * click "a_locator", :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
154
- # * click "a_locator", :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
155
- # * click "a_locator", :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
156
- # * click "a_locator", :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
157
- # * click "a_locator", :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
158
- # * 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'
159
- # * 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'
160
- # * 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'
161
- # * click "a_locator", :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible
162
- # * click "a_locator", :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible
163
- # * click "a_locator", :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
164
- #
165
- # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
166
- # is used.
167
- def click(locator, options={})
168
- remote_control_command "click", [locator,]
169
- wait_for options
170
- end
171
-
172
- # Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
173
- #
174
- # * 'pattern' is a pattern to match with the text of the page
175
- def text?(pattern)
176
- boolean_command "isTextPresent", [pattern,]
177
- end
178
-
179
- # Verifies that the specified element is somewhere on the page.
180
- #
181
- # * 'locator' is an element locator
182
- def element?(locator)
183
- boolean_command "isElementPresent", [locator,]
184
- end
185
-
186
- # Determines if the specified element is visible. An
187
- # element can be rendered invisible by setting the CSS "visibility"
188
- # property to "hidden", or the "display" property to "none", either for the
189
- # element itself or one if its ancestors. This method will fail if
190
- # the element is not present.
191
- #
192
- # 'locator' is an element locator
193
- def visible?(locator)
194
- boolean_command "isVisible", [locator,]
195
- end
196
-
197
- # Gets the (whitespace-trimmed) value of an input field
198
- # (or anything else with a value parameter).
199
- # For checkbox/radio elements, the value will be "on" or "off"
200
- # depending on whether the element is checked or not.
201
- #
202
- # * 'locator' is an element locator
203
- def field(locator)
204
- string_command "getValue", [locator,]
205
- end
206
-
207
- # Alias for +field+
208
- def value(locator)
209
- field locator
210
- end
211
-
212
- # Returns whether a toggle-button (checkbox/radio) is checked.
213
- # Fails if the specified element doesn't exist or isn't a toggle-button.
214
- #
215
- # * 'locator' is an element locator pointing to a checkbox or radio button
216
- def checked?(locator)
217
- boolean_command "isChecked", [locator,]
218
- end
219
-
220
- # Whether an alert occurred
221
- def alert?
222
- boolean_command "isAlertPresent"
223
- end
224
-
225
- # Retrieves the message of a JavaScript alert generated during the previous action,
226
- # or fail if there were no alerts.
227
- #
228
- # Getting an alert has the same effect as manually clicking OK. If an
229
- # alert is generated but you do not consume it with getAlert, the next Selenium action
230
- # will fail.
231
- #
232
- # Under Selenium, JavaScript alerts will NOT pop up a visible alert
233
- # dialog.
234
- #
235
- # Selenium does NOT support JavaScript alerts that are generated in a
236
- # page's onload() event handler. In this case a visible dialog WILL be
237
- # generated and Selenium will hang until someone manually clicks OK.
238
- #
239
- def alert
240
- string_command "getAlert"
241
- end
242
-
243
- # Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
244
- def confirmation?
245
- boolean_command "isConfirmationPresent"
246
- end
247
-
248
- # Retrieves the message of a JavaScript confirmation dialog generated during
249
- # the previous action.
250
- #
251
- # By default, the confirm function will return true, having the same effect
252
- # as manually clicking OK. This can be changed by prior execution of the
253
- # chooseCancelOnNextConfirmation command.
254
- #
255
- # If an confirmation is generated but you do not consume it with getConfirmation,
256
- # the next Selenium action will fail.
257
- #
258
- # NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
259
- # dialog.
260
- #
261
- # NOTE: Selenium does NOT support JavaScript confirmations that are
262
- # generated in a page's onload() event handler. In this case a visible
263
- # dialog WILL be generated and Selenium will hang until you manually click
264
- # OK.
265
- def confirmation
266
- string_command "getConfirmation"
267
- end
268
-
269
- # Whether a prompt occurred
270
- def prompt?
271
- boolean_command "isPromptPresent"
272
- end
273
-
274
- # Retrieves the message of a JavaScript question prompt dialog generated during
275
- # the previous action.
276
- #
277
- # Successful handling of the prompt requires prior execution of the
278
- # answerOnNextPrompt command. If a prompt is generated but you
279
- # do not get/verify it, the next Selenium action will fail.
280
- #
281
- # NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
282
- # dialog.
283
- #
284
- # NOTE: Selenium does NOT support JavaScript prompts that are generated in a
285
- # page's onload() event handler. In this case a visible dialog WILL be
286
- # generated and Selenium will hang until someone manually clicks OK.
287
- def prompt
288
- string_command "getPrompt"
289
- end
290
-
291
- # Returns the result of evaluating the specified JavaScript snippet whithin the browser.
292
- # The snippet may have multiple lines, but only the result of the last line will be returned.
293
- #
294
- # Note that, by default, the snippet will run in the context of the "selenium"
295
- # object itself, so <tt>this</tt> will refer to the Selenium object. Use <tt>window</tt> to
296
- # refer to the window of your application, e.g. <tt>window.document.getElementById('foo')</tt>
297
- # If you need to use
298
- # a locator to refer to a single element in your application page, you can
299
- # use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
300
- #
301
- # * 'script' is the JavaScript snippet to run
302
- def js_eval(script)
303
- string_command "getEval", [script,]
304
- end
305
-
306
- # Set the Remote Control timeout (as opposed to the client side driver timeout).
307
- # This timout specifies the amount of time that Selenium Core will wait for actions to complete.
308
- #
309
- # The default timeout is 30 seconds.
310
- # 'timeout' is a timeout in seconds, after which the action will return with an error
311
- #
312
- # Actions that require waiting include "open" and the "waitFor*" actions.
313
- def remote_control_timeout_in_seconds=(timeout_in_seconds)
314
- remote_control_command "setTimeout", [actual_timeout_in_milliseconds(timeout_in_seconds),]
315
- end
316
-
317
- # Returns the text from a cell of a table. The cellAddress syntax
318
- # tableLocator.row.column, where row and column start at 0.
319
- #
320
- # * 'tableCellAddress' is a cell address, e.g. "foo.1.4"
321
- def table_cell_text(tableCellAddress)
322
- string_command "getTable", [tableCellAddress,]
323
- end
324
-
325
- # Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
326
- # The snippet may have multiple lines, but only the result of the last line
327
- # will be considered.
328
- #
329
- # Note that, by default, the snippet will be run in the runner's test window, not in the window
330
- # of your application. To get the window of your application, you can use
331
- # the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
332
- # run your JavaScript in there
333
- #
334
- #
335
- # * 'script' is the JavaScript snippet to run
336
- # * 'timeout_in_seconds' is a timeout in seconds, after which this command will return with an error
337
- def wait_for_condition(script, timeout_in_seconds = nil)
338
- remote_control_command "waitForCondition",
339
- [script, actual_timeout_in_milliseconds(timeout_in_seconds),]
340
- end
341
-
342
- # Simulates the user clicking the "back" button on their browser.
343
- # Using 'options' you can automatically wait for an event to happen after the
344
- # click. e.g.
345
- #
346
- # * go_back :wait_for => :page # will wait for a new page to load
347
- # * 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`
348
- # * go_back :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
349
- # * go_back :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
350
- # * go_back :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
351
- # * go_back :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
352
- # * go_back :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
353
- # * go_back :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
354
- # * go_back :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
355
- # * go_back "a_locator", :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
356
- # * go_back :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
357
- # * go_back :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
358
- # * go_back "a_locator", :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
359
- # * 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'
360
- # * go_back :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
361
- # * go_back :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value'
362
- # * go_back :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible
363
- # * go_back :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible
364
- # * 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'
365
- #
366
- # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
367
- # is used.
368
- def go_back(options={})
369
- remote_control_command "goBack"
370
- wait_for options
371
- end
372
-
373
- # Return all cookies for the current page under test.
374
- def cookies
375
- string_command "getCookie"
376
- end
377
-
378
- # Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
379
- #
380
- # 'name' is the name of the cookie
381
- def cookie(name)
382
- string_command "getCookieByName", [name,]
383
- end
384
-
385
- # Returns true if a cookie with the specified name is present, or false otherwise.
386
- #
387
- # 'name' is the name of the cookie
388
- def cookie?(name)
389
- boolean_command "isCookiePresent", [name,]
390
- end
391
-
392
- # Create a new cookie whose path and domain are same with those of current page
393
- # under test, unless you specified a path for this cookie explicitly.
394
- #
395
- # 'nameValuePair' is name and value of the cookie in a format "name=value"
396
- # 'optionsString' is options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'.
397
- # 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.
398
- def create_cookie(name_value_pair, options="")
399
- if options.kind_of? Hash
400
- options = options.keys.collect {|key| "#{key}=#{options[key]}" }.sort.join(", ")
401
- end
402
- remote_control_command "createCookie", [name_value_pair,options,]
403
- end
404
-
405
- # Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you
406
- # need to delete it using the exact same path and domain that were used to create the cookie.
407
- # If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also
408
- # note that specifying a domain that isn't a subset of the current domain will usually fail.
409
- #
410
- # Since there's no way to discover at runtime the original path and domain of a given cookie,
411
- # we've added an option called 'recurse' to try all sub-domains of the current domain with
412
- # all paths that are a subset of the current path. Beware; this option can be slow. In
413
- # big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain
414
- # name and m is the number of slashes in the path.
415
- #
416
- # 'name' is the name of the cookie to be deleted
417
- # 'optionsString' is options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
418
- def delete_cookie(name, options="")
419
- if options.kind_of? Hash
420
- ordered_keys = options.keys.sort {|a,b| a.to_s <=> b.to_s }
421
- options = ordered_keys.collect {|key| "#{key}=#{options[key]}" }.join(", ")
422
- end
423
- remote_control_command "deleteCookie", [name,options,]
424
- end
425
-
426
- # Returns the IDs of all windows that the browser knows about.
427
- def all_window_ids
428
- string_array_command "getAllWindowIds"
429
- end
430
-
431
-
432
- # Returns the names of all windows that the browser knows about.
433
- def all_window_names
434
- string_array_command "getAllWindowNames"
435
- end
436
-
437
-
438
- # Returns the titles of all windows that the browser knows about.
439
- def all_window_titles
440
- string_array_command "getAllWindowTitles"
441
- end
442
-
443
- # Returns a string representation of the network traffic seen by the
444
- # browser, including headers, AJAX requests, status codes, and timings.
445
- # When this function is called, the traffic log is cleared, so the
446
- # returned content is only the traffic seen since the last call.
447
- #
448
- # The network traffic is returned in the format it was requested. Valid
449
- # values are: :json, :xml, or :plain.
450
- #
451
- # Warning: For browser_network_traffic to work you need to start your
452
- # browser session with the option "captureNetworkTraffic=true", which
453
- # will force ALL traffic to go to the Remote Control proxy even for
454
- # more efficient browser modes like `*firefox` and `*safari`.
455
- def browser_network_traffic(format = :plain)
456
- raise "format must be :plain, :json, or :xml" \
457
- unless [:plain, :json, :xml].include?(format)
458
-
459
- remote_control_command "captureNetworkTraffic", [format.to_s]
460
- end
461
-
462
- # Allows choice of a specific XPath libraries for Xpath evualuation
463
- # in the browser (e.g. to resolve XPath locators).
464
- #
465
- # `library_name' can be:
466
- # * :ajaxslt : Google's library
467
- # * :javascript-xpath : Cybozu Labs' faster library
468
- # * :default : Selenium default library.
469
- def browser_xpath_library=(library_name)
470
- raise "library name must be :ajaxslt, :javascript-xpath, or :default" \
471
- unless [:ajaxslt, :'javascript-xpath', :default].include?(library_name)
472
- remote_control_command "useXpathLibrary", [library_name.to_s]
473
- end
474
-
475
- #
476
- # Turn on/off the automatic hightlighting of the element driven or
477
- # inspected by Selenium core. Useful when recording videos
478
- #
479
- def highlight_located_element=(enabled)
480
- boolean = (true == enabled)
481
- js_eval "selenium.browserbot.shouldHighlightLocatedElement = #{boolean}"
482
- end
483
-
484
- # Get execution delay in milliseconds, i.e. a pause delay following
485
- # each selenium operation. By default, there is no such delay
486
- # (value is 0).
487
- def execution_delay
488
- string_command "getSpeed"
489
- end
490
-
491
- # Set the execution delay in milliseconds, i.e. a pause delay following
492
- # each selenium operation. By default, there is no such delay.
493
- #
494
- # Setting an execution can be useful to troubleshoot or capture videos
495
- def execution_delay=(delay_in_milliseconds)
496
- remote_control_command "setSpeed", [delay_in_milliseconds]
497
- end
498
-
499
- def actual_timeout_in_milliseconds(timeout_in_seconds)
500
- actual_timeout = (timeout_in_seconds ||
501
- default_timeout_in_seconds).to_i
502
- actual_timeout * 1000
503
- end
504
- end
505
-
506
- end
507
- end
@@ -1,135 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
-
23
- class JavascriptExpressionBuilder
24
- attr_reader :script
25
-
26
- def initialize(javascript_framework_name=nil)
27
- @framework = javascript_framework_for(javascript_framework_name) if javascript_framework_name
28
- @script = ""
29
- end
30
-
31
- def append(text)
32
- @script << text
33
- self
34
- end
35
-
36
- def no_pending_ajax_requests
37
- append window_script("#{@framework.ajax_request_tracker} == 0")
38
- end
39
-
40
- def no_pending_effects
41
- append window_script("Effect.Queue.size() == 0")
42
- end
43
-
44
- def visible(locator)
45
- append "selenium.isVisible('#{quote_escaped(locator)}')"
46
- end
47
-
48
- def not_visible(locator)
49
- append "!selenium.isVisible('#{quote_escaped(locator)}')"
50
- end
51
-
52
- def find_element(locator)
53
- append <<-EOS
54
- var element;
55
-
56
- try {
57
- element = selenium.browserbot.findElement('#{quote_escaped(locator)}');
58
- } catch(e) {
59
- element = null;
60
- }
61
- EOS
62
- end
63
-
64
- def element_value_is(expected_value)
65
- append "(element != null && element.value == '#{quote_escaped(expected_value)}')"
66
- end
67
-
68
- def element_value_is_not(expected_value)
69
- append "(element == null || element.value != '#{quote_escaped(expected_value)}')"
70
- end
71
-
72
- def find_text(pattern, options)
73
- if options[:element].nil?
74
- find_text_in_document pattern, options
75
- else
76
- find_text_in_element pattern, options
77
- end
78
-
79
- self
80
- end
81
-
82
- def find_text_in_document(pattern, options)
83
- js_regexp = case pattern
84
- when Regexp
85
- pattern.inspect
86
- else
87
- /#{pattern}/.inspect
88
- end
89
- append <<-EOS
90
- var text_match;
91
- text_match = (null != selenium.browserbot.getCurrentWindow().document.body.innerHTML.match(#{js_regexp}));
92
- EOS
93
-
94
- end
95
-
96
- def find_text_in_element(pattern, options)
97
- find_element(options[:element])
98
- append <<-EOS
99
- var text_match;
100
- text_match = (element != null && #{text_match(pattern)});
101
- EOS
102
-
103
- self
104
- end
105
-
106
- def text_match(pattern)
107
- case pattern
108
- when Regexp
109
- "null != element.innerHTML.match(#{pattern.inspect})"
110
- else
111
- "element.innerHTML == '#{quote_escaped(pattern)}'"
112
- end
113
- end
114
-
115
- def javascript_framework_for(framework_name)
116
- case framework_name.to_sym
117
- when :prototype
118
- JavascriptFrameworks::Prototype
119
- when :jquery
120
- JavascriptFrameworks::JQuery
121
- else
122
- raise "Unsupported Javascript Framework: #{framework_name}"
123
- end
124
- end
125
-
126
- def window_script(expression)
127
- "selenium.browserbot.getCurrentWindow().#{expression};"
128
- end
129
-
130
- def quote_escaped(a_string)
131
- a_string.gsub(/\\/, "\\\\\\").gsub(/'/, %q<\\\'>)
132
- end
133
- end
134
- end
135
- end
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
- module JavascriptFrameworks
23
- module JQuery
24
-
25
- def self.ajax_request_tracker
26
- "jQuery.active"
27
- end
28
-
29
- end
30
- end
31
- end
32
- end