bbc-selenium-webdriver 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/CHANGES +473 -0
  2. data/README +31 -0
  3. data/lib/selenium-client.rb +2 -0
  4. data/lib/selenium-webdriver.rb +1 -0
  5. data/lib/selenium/client.rb +37 -0
  6. data/lib/selenium/client/base.rb +118 -0
  7. data/lib/selenium/client/driver.rb +10 -0
  8. data/lib/selenium/client/errors.rb +9 -0
  9. data/lib/selenium/client/extensions.rb +118 -0
  10. data/lib/selenium/client/idiomatic.rb +488 -0
  11. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  12. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  13. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  14. data/lib/selenium/client/legacy_driver.rb +1720 -0
  15. data/lib/selenium/client/protocol.rb +104 -0
  16. data/lib/selenium/client/selenium_helper.rb +34 -0
  17. data/lib/selenium/rake/server_task.rb +157 -0
  18. data/lib/selenium/server.rb +223 -0
  19. data/lib/selenium/webdriver.rb +64 -0
  20. data/lib/selenium/webdriver/android.rb +9 -0
  21. data/lib/selenium/webdriver/android/bridge.rb +51 -0
  22. data/lib/selenium/webdriver/chrome.rb +26 -0
  23. data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
  24. data/lib/selenium/webdriver/chrome/profile.rb +83 -0
  25. data/lib/selenium/webdriver/chrome/service.rb +74 -0
  26. data/lib/selenium/webdriver/common.rb +30 -0
  27. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  28. data/lib/selenium/webdriver/common/alert.rb +26 -0
  29. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  30. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  31. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  32. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  33. data/lib/selenium/webdriver/common/driver.rb +301 -0
  34. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  35. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  38. data/lib/selenium/webdriver/common/element.rb +262 -0
  39. data/lib/selenium/webdriver/common/error.rb +212 -0
  40. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  41. data/lib/selenium/webdriver/common/keyboard.rb +52 -0
  42. data/lib/selenium/webdriver/common/keys.rb +109 -0
  43. data/lib/selenium/webdriver/common/mouse.rb +65 -0
  44. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  45. data/lib/selenium/webdriver/common/options.rb +128 -0
  46. data/lib/selenium/webdriver/common/platform.rb +166 -0
  47. data/lib/selenium/webdriver/common/port_prober.rb +25 -0
  48. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  49. data/lib/selenium/webdriver/common/proxy.rb +120 -0
  50. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  51. data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
  52. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  53. data/lib/selenium/webdriver/common/timeouts.rb +29 -0
  54. data/lib/selenium/webdriver/common/wait.rb +60 -0
  55. data/lib/selenium/webdriver/common/window.rb +96 -0
  56. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  57. data/lib/selenium/webdriver/firefox.rb +37 -0
  58. data/lib/selenium/webdriver/firefox/binary.rb +161 -0
  59. data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
  60. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  61. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  62. data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
  63. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  64. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  65. data/lib/selenium/webdriver/firefox/profile.rb +315 -0
  66. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  67. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  68. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  69. data/lib/selenium/webdriver/ie.rb +19 -0
  70. data/lib/selenium/webdriver/ie/bridge.rb +60 -0
  71. data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
  72. data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
  73. data/lib/selenium/webdriver/ie/server.rb +64 -0
  74. data/lib/selenium/webdriver/iphone.rb +9 -0
  75. data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
  76. data/lib/selenium/webdriver/opera.rb +24 -0
  77. data/lib/selenium/webdriver/opera/bridge.rb +113 -0
  78. data/lib/selenium/webdriver/opera/service.rb +49 -0
  79. data/lib/selenium/webdriver/remote.rb +21 -0
  80. data/lib/selenium/webdriver/remote/bridge.rb +473 -0
  81. data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
  82. data/lib/selenium/webdriver/remote/commands.rb +181 -0
  83. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  84. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  85. data/lib/selenium/webdriver/remote/http/default.rb +102 -0
  86. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  87. data/lib/selenium/webdriver/remote/response.rb +99 -0
  88. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  89. data/lib/selenium/webdriver/support.rb +4 -0
  90. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  91. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  92. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  93. data/lib/selenium/webdriver/support/select.rb +293 -0
  94. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  95. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  96. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  97. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  98. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  99. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  100. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  101. data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
  102. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  103. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  104. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  105. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  106. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  107. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  108. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  109. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  110. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  111. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  112. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  113. data/spec/integration/selenium/client/spec_helper.rb +125 -0
  114. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  115. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
  116. data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
  117. data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
  118. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  119. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  120. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  121. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  122. data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
  123. data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
  124. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  125. data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
  126. data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
  127. data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
  128. data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
  129. data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
  130. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
  131. data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
  132. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  133. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
  134. data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
  135. data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
  136. data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
  137. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  138. data/spec/unit/selenium/client/base_spec.rb +239 -0
  139. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  140. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  141. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  142. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  143. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  144. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  145. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  146. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  147. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  148. data/spec/unit/selenium/server_spec.rb +131 -0
  149. data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
  150. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
  151. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
  152. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  153. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  154. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  155. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
  156. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
  157. data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
  158. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  159. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
  160. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  161. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
  162. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  163. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  164. data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
  165. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  166. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  167. data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
  168. metadata +215 -0
@@ -0,0 +1,500 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe Selenium::Client::Idiomatic do
4
+ class IdiomaticClient
5
+ include Selenium::Client::Idiomatic
6
+ end
7
+
8
+ let(:client) { IdiomaticClient.new }
9
+
10
+ it "has #text is an alias for get_text" do
11
+ client.should_receive(:string_command).with("getText", [:the_locator,]).and_return(:the_text)
12
+ client.text(:the_locator).should == :the_text
13
+ end
14
+
15
+ it "#title returns the result of the getTitle command" do
16
+ client.should_receive(:string_command).with("getTitle").and_return(:the_title)
17
+ client.title.should == :the_title
18
+ end
19
+
20
+ it "#location returns the result of the getLocation command" do
21
+ client.should_receive(:string_command).with("getLocation").and_return(:the_location)
22
+ client.location.should == :the_location
23
+ end
24
+
25
+ describe "#wait_for_page" do
26
+ it "waits for a page to load, converting seconds timeout to milliseconds" do
27
+ client.should_receive(:remote_control_command).with("waitForPageToLoad", [2000,])
28
+ client.wait_for_page 2
29
+ end
30
+
31
+ it "waits for a page to load with the default timeout when none is specified" do
32
+ client.should_receive(:remote_control_command).with("waitForPageToLoad", [7000,])
33
+ client.stub!(:default_timeout_in_seconds).and_return(7)
34
+ client.wait_for_page
35
+ end
36
+
37
+ it "waits for a page to load with a string timeout for backward compatibility" do
38
+ client.should_receive(:remote_control_command).with("waitForPageToLoad", [2000,])
39
+ client.wait_for_page "2"
40
+ end
41
+
42
+ it "has #wait_for_page_to_load as an alias providing easy transition to people used to the old API" do
43
+ client.should_receive(:remote_control_command).with("waitForPageToLoad", [24000,])
44
+ client.wait_for_page_to_load 24
45
+ end
46
+ end
47
+
48
+ describe "#wait_for_popup" do
49
+ it "returns the result of the waitForPopUp command" do
50
+ client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 0]).and_return(:the_value)
51
+ client.wait_for_popup(:the_window_id, 0).should == :the_value
52
+ end
53
+
54
+ it "converts the timeout from seconds to milliseconds" do
55
+ client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 3000]).and_return(:the_value)
56
+ client.wait_for_popup(:the_window_id, 3).should == :the_value
57
+ end
58
+
59
+ it "accepts timeout as a string for backward compatibility" do
60
+ client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 5000]).and_return(:the_value)
61
+ client.wait_for_popup(:the_window_id, "5").should == :the_value
62
+ end
63
+
64
+ it "uses the default timeout when none is specified" do
65
+ client.should_receive(:remote_control_command).with("waitForPopUp", [:the_window_id, 7000]).and_return(:the_value)
66
+ client.stub!(:default_timeout_in_seconds).and_return(7)
67
+ client.wait_for_popup :the_window_id
68
+ end
69
+ end
70
+
71
+ describe "#wait_for_condition" do
72
+ it "waits for a page to load using the default timeout when none is specified" do
73
+ client.should_receive(:remote_control_command).with("waitForCondition", ["some javascript", 7000,])
74
+ client.stub!(:default_timeout_in_seconds).and_return(7)
75
+ client.wait_for_condition "some javascript"
76
+ end
77
+
78
+ it "waits for a page to load using the given timeout converted to milliseconds" do
79
+ client.should_receive(:remote_control_command).with("waitForCondition", ["some javascript", 24000,])
80
+ client.stub!(:default_timeout_in_seconds).and_return(7)
81
+ client.wait_for_condition "some javascript", 24
82
+ end
83
+
84
+ it "accepts timeout as a string for backward compatibility" do
85
+ client.should_receive(:remote_control_command).with("waitForCondition", ["some javascript", 64000,])
86
+ client.stub!(:default_timeout_in_seconds).and_return(7)
87
+ client.wait_for_condition "some javascript", "64"
88
+ end
89
+ end
90
+
91
+ describe "#wait_for" do
92
+ it "does nothing when no options are given" do
93
+ client.should_receive(:remote_control_command).never
94
+ client.wait_for({})
95
+ end
96
+
97
+ it "waits for page with explicit timeout when one is provided" do
98
+ client.should_receive(:wait_for_page).with(:the_timeout)
99
+ client.wait_for :wait_for => :page, :timeout_in_seconds => :the_timeout
100
+ end
101
+
102
+ it "waits for ajax to complete when ajax option is provided" do
103
+ client.should_receive(:wait_for_ajax)
104
+ client.wait_for :wait_for => :ajax
105
+ end
106
+
107
+ it "waits for ajax using the given javascript framework override" do
108
+ client.should_receive(:wait_for_ajax).with(hash_including(:javascript_framework => :jquery))
109
+ client.wait_for :wait_for => :ajax, :javascript_framework => :jquery
110
+ end
111
+
112
+ it "waits for ajax with explicit timeout when one is provided" do
113
+ client.should_receive(:wait_for_ajax).with(hash_including(:timeout_in_seconds => :the_timeout))
114
+ client.wait_for :wait_for => :ajax, :timeout_in_seconds => :the_timeout
115
+ end
116
+
117
+ it "waits for element to be present when element option is provided" do
118
+ client.should_receive(:wait_for_element).with(:the_new_element_id, anything)
119
+ client.wait_for :wait_for => :element, :element => :the_new_element_id
120
+ end
121
+
122
+ it "waits for element with explicit timeout when one is provided" do
123
+ client.should_receive(:wait_for_element).with(:the_new_element_id, hash_including(:timeout_in_seconds => :the_timeout))
124
+ client.wait_for :wait_for => :element, :element => :the_new_element_id,
125
+ :timeout_in_seconds => :the_timeout
126
+ end
127
+
128
+ it "waits for no element to be present when no_element option is provided" do
129
+ client.should_receive(:wait_for_no_element).with(:the_new_element_id, hash_including(:element => :the_new_element_id))
130
+ client.wait_for :wait_for => :no_element, :element => :the_new_element_id
131
+ end
132
+
133
+ it "waits for no element with explicit timeout when one is provided" do
134
+ client.should_receive(:wait_for_no_element).with(:the_new_element_id, hash_including(:element => :the_new_element_id, :timeout_in_seconds => :the_timeout))
135
+ client.wait_for :wait_for => :no_element, :element => :the_new_element_id,
136
+ :timeout_in_seconds => :the_timeout
137
+ end
138
+
139
+ it "waits for text to be present when text option is provided" do
140
+ client.should_receive(:wait_for_text).with("some text", hash_including(:element => "a locator", :text => "some text"))
141
+ client.wait_for :wait_for => :text, :element => "a locator", :text => "some text"
142
+ end
143
+
144
+ it "waits for text with explicit timeout when one is provided" do
145
+ client.should_receive(:wait_for_text).with("some text", hash_including(:timeout_in_seconds => :the_timeout))
146
+ client.wait_for :wait_for => :text,
147
+ :text => "some text",
148
+ :timeout_in_seconds => :the_timeout
149
+ end
150
+
151
+ it "waits for text to NOT be present when no_text option is provided" do
152
+ client.should_receive(:wait_for_no_text).with("some text", hash_including(:element => 'a_locator'))
153
+ client.wait_for :wait_for => :no_text, :element => 'a_locator', :text => "some text"
154
+ end
155
+
156
+ it "waits for no text with explicit timeout and locator when none are provided" do
157
+ client.should_receive(:wait_for_no_text).with("some text", hash_including(:timeout_in_seconds => :the_timeout))
158
+ client.wait_for :wait_for => :no_text, :text => "some text",
159
+ :timeout_in_seconds => :the_timeout
160
+ end
161
+
162
+ it "waits for effects to complete when effects option is provided" do
163
+ client.should_receive(:wait_for_effects)
164
+ client.wait_for :wait_for => :effects
165
+ end
166
+
167
+ it "waits for effects with explicit timeout when one is provided" do
168
+ client.should_receive(:wait_for_effects).with(hash_including(:timeout_in_seconds => :the_timeout))
169
+ client.wait_for :wait_for => :effects, :timeout_in_seconds => :the_timeout
170
+ end
171
+
172
+ it "waits for effects using the given javascript framework override" do
173
+ client.should_receive(:wait_for_effects).with(hash_including(:javascript_framework => :jquery))
174
+ client.wait_for :wait_for => :effects, :javascript_framework => :jquery
175
+ end
176
+
177
+ it "waits for popup to appear when popup option is provided" do
178
+ client.should_receive(:wait_for_popup).with(:the_window_id, nil)
179
+ client.wait_for :wait_for => :popup, :window => :the_window_id
180
+ end
181
+
182
+ it "waits for popup with explicit timeout when provided" do
183
+ client.should_receive(:wait_for_popup).with(:the_window_id, :the_timeout)
184
+ client.wait_for :wait_for => :popup, :window => :the_window_id, :timeout_in_seconds => :the_timeout
185
+ end
186
+
187
+ it "selects the popup when the select option is true" do
188
+ client.should_receive(:wait_for_popup).with(:the_window_id, nil)
189
+ client.should_receive(:select_window).with(:the_window_id)
190
+ client.wait_for :wait_for => :popup, :window => :the_window_id, :select => true
191
+ end
192
+
193
+ it "does not select the popup when the select option is false" do
194
+ client.should_receive(:wait_for_popup).with(:the_window_id, nil)
195
+ client.should_receive(:select_window).with(:the_window_id).never
196
+ client.wait_for :wait_for => :popup, :window => :the_window_id
197
+ end
198
+
199
+ it "waits for field value when value option is provided" do
200
+ client.should_receive(:wait_for_field_value).with(:the_locator, :expected_value, anything)
201
+ client.wait_for :wait_for => :value, :element => :the_locator, :value => :expected_value
202
+ end
203
+
204
+ it "waits for field using explicit timeout when provided" do
205
+ client.should_receive(:wait_for_field_value).with(:the_locator, :expected_value,
206
+ hash_including(:timeout_in_seconds => :the_timeout))
207
+
208
+ client.wait_for :wait_for => :value, :element => :the_locator,
209
+ :value => :expected_value,
210
+ :timeout_in_seconds => :the_timeout
211
+ end
212
+
213
+ it "waits for no field value when value option is provided" do
214
+ client.should_receive(:wait_for_no_field_value).with(:the_locator, :expected_value, anything)
215
+ client.wait_for :wait_for => :no_value, :element => :the_locator, :value => :expected_value
216
+ end
217
+
218
+ it "waits for no field value using explicit timeout when provided" do
219
+ client.should_receive(:wait_for_no_field_value).with(:the_locator,
220
+ :expected_value,
221
+ hash_including(:timeout_in_seconds => :the_timeout))
222
+ client.wait_for :wait_for => :no_value, :element => :the_locator,
223
+ :value => :expected_value,
224
+ :timeout_in_seconds => :the_timeout
225
+ end
226
+
227
+ it "waits for element to be visible when visible option is provided" do
228
+ client.should_receive(:wait_for_visible).with(:the_locator, anything)
229
+ client.wait_for :wait_for => :visible, :element => :the_locator, :value => :expected_value
230
+ end
231
+
232
+ it "waits for element to be visible using explicit timeout when provided" do
233
+ client.should_receive(:wait_for_visible).with(:the_locator,
234
+ hash_including(:timeout_in_seconds => :the_timeout))
235
+ client.wait_for :wait_for => :visible, :element => :the_locator,
236
+ :timeout_in_seconds => :the_timeout
237
+ end
238
+
239
+ it "waits for element to not be visible when visible option is provided" do
240
+ client.should_receive(:wait_for_not_visible).with(:the_locator, anything)
241
+ client.wait_for :wait_for => :not_visible, :element => :the_locator, :value => :expected_value
242
+ end
243
+
244
+ it "waits for element to not be visible using explicit timeout when provided" do
245
+ client.should_receive(:wait_for_not_visible).with(:the_locator,
246
+ hash_including(:timeout_in_seconds => :the_timeout))
247
+ client.wait_for :wait_for => :not_visible, :element => :the_locator,
248
+ :timeout_in_seconds => :the_timeout
249
+ end
250
+
251
+ it "waits for given javascript to return true when condition option is provided" do
252
+ client.should_receive(:wait_for_condition).with("some javascript", nil)
253
+ client.wait_for :wait_for => :condition, :javascript => "some javascript"
254
+ end
255
+ end
256
+
257
+ describe "#body_text" do
258
+ it "returns the result of the getBodyText command" do
259
+ client.should_receive(:string_command).with("getBodyText").and_return(:the_text)
260
+ client.body_text.should == :the_text
261
+ end
262
+ end
263
+
264
+ describe "#click" do
265
+ it "clicks on an element when no options are given" do
266
+ client.should_receive(:remote_control_command).with("click", [:the_locator,])
267
+ client.click :the_locator
268
+ end
269
+
270
+ it "calls wait_for with options provided" do
271
+ client.should_receive(:remote_control_command).with("click", [:the_locator,])
272
+ client.should_receive(:wait_for).with(:wait_for => :page)
273
+ client.click :the_locator, :wait_for => :page
274
+ end
275
+ end
276
+
277
+ describe "#value" do
278
+ it "value returns the result of the getValue command" do
279
+ client.should_receive(:string_command).with("getValue", [:the_locator,]).and_return(:the_value)
280
+ client.value(:the_locator).should == :the_value
281
+ end
282
+ end
283
+
284
+ describe "#field" do
285
+ it "field returns the result of the getValue command" do
286
+ client.should_receive(:string_command).with("getValue", [:the_locator,]).and_return(:the_value)
287
+ client.field(:the_locator).should == :the_value
288
+ end
289
+ end
290
+
291
+ describe "#checked?" do
292
+ it "checked? returns the result of the isChecked command" do
293
+ client.should_receive(:boolean_command).with("isChecked", [:the_locator,]).and_return(:the_value)
294
+ client.checked?(:the_locator).should == :the_value
295
+ end
296
+ end
297
+
298
+ describe "#text?" do
299
+ it "returns the result of the isTextPresent command" do
300
+ client.should_receive(:boolean_command).with("isTextPresent", [:the_pattern,]).and_return(:the_result)
301
+ client.text?(:the_pattern).should == :the_result
302
+ end
303
+ end
304
+
305
+ describe "#element?" do
306
+ it "returns the result of the isElementPresent command" do
307
+ client.should_receive(:boolean_command).with("isElementPresent", [:the_locator,]).and_return(:the_result)
308
+ client.element?(:the_locator).should == :the_result
309
+ end
310
+ end
311
+
312
+ describe "visible?" do
313
+ it "returns the result of the isTextPresent command" do
314
+ client.should_receive(:boolean_command).with("isVisible", [:the_locator,]).and_return(:the_result)
315
+ client.visible?(:the_locator).should == :the_result
316
+ end
317
+ end
318
+
319
+ describe "#alert? or #alert" do
320
+ it "returns the result of the isAlertPresent command" do
321
+ client.should_receive(:boolean_command).with("isAlertPresent").and_return(:the_result)
322
+ client.alert?.should == :the_result
323
+ end
324
+
325
+ it "returns the result of the getAlert command" do
326
+ client.should_receive(:string_command).with("getAlert").and_return(:the_result)
327
+ client.alert.should == :the_result
328
+ end
329
+ end
330
+
331
+ describe "#confirmation? or #confirmation" do
332
+ it "returns the result of the isConfirmationPresent command" do
333
+ client.should_receive(:boolean_command).with("isConfirmationPresent").and_return(:the_result)
334
+ client.confirmation?.should == :the_result
335
+ end
336
+
337
+ it "returns the result of the getConfirmation command" do
338
+ client.should_receive(:string_command).with("getConfirmation").and_return(:the_result)
339
+ client.confirmation.should == :the_result
340
+ end
341
+ end
342
+
343
+ describe "#prompt? and #prompt" do
344
+ it "prompt? returns the result of the isPromptPresent command" do
345
+ client.should_receive(:boolean_command).with("isPromptPresent").and_return(:the_result)
346
+ client.prompt?.should == :the_result
347
+ end
348
+
349
+ it "prompt returns the result of the getPrompt command" do
350
+ client.should_receive(:string_command).with("getPrompt").and_return(:the_result)
351
+ client.prompt.should == :the_result
352
+ end
353
+
354
+ it "prompt returns the result of the getEval command" do
355
+ client.should_receive(:string_command).with("getEval", [:the_script,]).and_return(:the_result)
356
+ client.js_eval(:the_script).should == :the_result
357
+ end
358
+ end
359
+
360
+ describe "table_cell_text" do
361
+ it "table_cell_text returns the result of the getTable command" do
362
+ client.should_receive(:string_command).with("getTable", [:the_cell_address,]).and_return(:the_value)
363
+ client.table_cell_text(:the_cell_address).should == :the_value
364
+ end
365
+ end
366
+
367
+ describe "#cookies, #cookie, #cookie?" do
368
+ it "returns the result of the getCookie command" do
369
+ client.should_receive(:string_command).with("getCookie").and_return(:the_value)
370
+ client.cookies.should == :the_value
371
+ end
372
+
373
+ it "returns the result of the getCookieByName command" do
374
+ client.should_receive(:string_command).with("getCookieByName", [:the_name,]).and_return(:the_value)
375
+ client.cookie(:the_name).should == :the_value
376
+ end
377
+
378
+ it "returns the result of the isCookiePresent command" do
379
+ client.should_receive(:boolean_command).with("isCookiePresent", [:the_name,]).and_return(:the_value)
380
+ client.cookie?(:the_name).should == :the_value
381
+ end
382
+ end
383
+
384
+ describe "#create_cookie" do
385
+
386
+ it "returns the result of the createCookie command" do
387
+ client.should_receive(:remote_control_command).with("createCookie", [:the_name_value_pair, "options"]).and_return(:the_value)
388
+ client.create_cookie(:the_name_value_pair, "options").should == :the_value
389
+ end
390
+
391
+ it "returns the result of the createCookie command when no options are given" do
392
+ client.should_receive(:remote_control_command).with("createCookie", [:the_name_value_pair, ""]).and_return(:the_value)
393
+ client.create_cookie(:the_name_value_pair).should == :the_value
394
+ end
395
+
396
+ it "converts hash options to cookie strings" do
397
+ client.should_receive(:remote_control_command).with do |cmd, args|
398
+ cmd.should == "createCookie"
399
+
400
+ args.size.should == 2
401
+ args.first.should == :the_name_value_pair
402
+ [ "max_age=60, domain=.foo.com",
403
+ "domain=.foo.com, max_age=60" ].should include(args.last)
404
+ end.and_return(:the_value)
405
+
406
+ result = client.create_cookie(:the_name_value_pair, {:max_age => 60, :domain => ".foo.com"})
407
+ result.should == :the_value
408
+ end
409
+ end
410
+
411
+ describe "#delete_cookie" do
412
+ it "returns the result of the createCookie command" do
413
+ client.should_receive(:remote_control_command).with("deleteCookie", [:the_name, "options"]).and_return(:the_value)
414
+ client.delete_cookie(:the_name, "options").should == :the_value
415
+ end
416
+
417
+ it "options are optional for delete_cookie when no options are given" do
418
+ client.should_receive(:remote_control_command).with("deleteCookie", [:the_name, ""]).and_return(:the_value)
419
+ client.delete_cookie(:the_name).should == :the_value
420
+ end
421
+
422
+ it "converts hash options to cookie strings" do
423
+ client.should_receive(:remote_control_command).with("deleteCookie", [:the_name, "domain=.foo.com, max_age=60"]).and_return(:the_value)
424
+ result = client.delete_cookie(:the_name, {:max_age => 60, :domain => ".foo.com"})
425
+ result.should == :the_value
426
+ end
427
+ end
428
+
429
+ describe "#all_window_ids, #all_window_titles or #all_window_names" do
430
+ it "returns the result of the getAllWindowIds command" do
431
+ client.should_receive(:string_array_command).with("getAllWindowIds").and_return(:the_value)
432
+ client.all_window_ids.should == :the_value
433
+ end
434
+
435
+ it "returns the result of the getAllWindowNames command" do
436
+ client.should_receive(:string_array_command).with("getAllWindowNames").and_return(:the_value)
437
+ client.all_window_names.should == :the_value
438
+ end
439
+
440
+ it "returns the result of the getAllWindowTitles command" do
441
+ client.should_receive(:string_array_command).with("getAllWindowTitles").and_return(:the_value)
442
+ client.all_window_titles.should == :the_value
443
+ end
444
+ end
445
+
446
+ describe "#browser_network_traffic" do
447
+ it "returns the result of the captureNetworkTraffic command" do
448
+ client.should_receive(:remote_control_command).with("captureNetworkTraffic", ["json"]).and_return(:the_value)
449
+ client.browser_network_traffic(:json).should == :the_value
450
+ end
451
+
452
+ it "uses plain as the default format" do
453
+ client.should_receive(:remote_control_command).with("captureNetworkTraffic", ["plain"]).and_return(:the_value)
454
+ client.browser_network_traffic.should == :the_value
455
+ end
456
+
457
+ it "raises a RuntimeError when format is nil" do
458
+ lambda { client.browser_network_traffic(nil) }.should raise_error(RuntimeError)
459
+ end
460
+
461
+ it "raises a RuntimeError when format is an unknown format" do
462
+ lambda { client.browser_network_traffic(:random_format) }.should raise_error(RuntimeError)
463
+ end
464
+ end
465
+
466
+ describe "#browser_xpath_library=" do
467
+ it "invokes the useXpathLibrary command" do
468
+ client.should_receive(:remote_control_command).with("useXpathLibrary", ["ajaxslt"]).and_return(:the_value)
469
+ client.browser_xpath_library = :ajaxslt
470
+ end
471
+
472
+ it "raises a RuntimeError whe library name is unknown" do
473
+ lambda { client.browser_xpath_library = :random_library }.should raise_error(RuntimeError)
474
+ end
475
+ end
476
+
477
+ describe "#highlight_located_element=" do
478
+ it "setting highlight_located_element to true enables auto-hilighting in selenium core" do
479
+ client.should_receive(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = true")
480
+ client.highlight_located_element = true
481
+ end
482
+
483
+ it "setting highlight_located_element to false disables auto-hilighting in selenium core" do
484
+ client.should_receive(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = false")
485
+ client.highlight_located_element = false
486
+ end
487
+ end
488
+
489
+ describe "#execution_delay or #execution_delay=" do
490
+ it "execution_delay returns the result of the getSpeed command" do
491
+ client.should_receive(:string_command).with("getSpeed").and_return(:the_speed)
492
+ client.execution_delay.should == :the_speed
493
+ end
494
+
495
+ it "execution_delay= executes the setSpeed command" do
496
+ client.should_receive(:remote_control_command).with("setSpeed", [24])
497
+ client.execution_delay= 24
498
+ end
499
+ end
500
+ end