selenium-webdriver 2.45.0 → 3.142.7

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