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,66 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ describe Zipper do
6
+
7
+ #
8
+ # TODO: clean this spec up
9
+ #
10
+
11
+ let(:base_file_name) { "file.txt" }
12
+ let(:file_content) { "content" }
13
+ let(:zip_file) { File.join(Dir.tmpdir, "test.zip") }
14
+ let(:dir_to_zip) { Dir.mktmpdir("zipper") }
15
+
16
+ def create_file
17
+ filename = File.join(dir_to_zip, base_file_name)
18
+ File.open(filename, "w") { |io| io << file_content }
19
+
20
+ filename
21
+ end
22
+
23
+ after {
24
+ FileUtils.rm_rf zip_file
25
+ }
26
+
27
+ it "zips and unzips a folder" do
28
+ create_file
29
+
30
+ File.open(zip_file, "wb") do |io|
31
+ io << Base64.decode64(Zipper.zip(dir_to_zip))
32
+ end
33
+
34
+ unzipped = Zipper.unzip(zip_file)
35
+ File.read(File.join(unzipped, base_file_name)).should == file_content
36
+ end
37
+
38
+ it "zips and unzips a single file" do
39
+ file_to_zip = create_file
40
+
41
+ File.open(zip_file, "wb") do |io|
42
+ io << Base64.decode64(Zipper.zip_file(file_to_zip))
43
+ end
44
+
45
+ unzipped = Zipper.unzip(zip_file)
46
+ File.read(File.join(unzipped, base_file_name)).should == file_content
47
+ end
48
+
49
+ not_compliant_on :platform => :windows do
50
+ it "follows symlinks when zipping" do
51
+ filename = create_file
52
+ File.symlink(filename, File.join(dir_to_zip, "link"))
53
+
54
+ zip_file = File.join(Dir.tmpdir, "test.zip")
55
+ File.open(zip_file, "wb") do |io|
56
+ io << Base64.decode64(Zipper.zip(dir_to_zip))
57
+ end
58
+
59
+ unzipped = Zipper.unzip(zip_file)
60
+ File.read(File.join(unzipped, "link")).should == file_content
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,239 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe Selenium::Client::Base do
4
+
5
+ class BaseClient
6
+ include Selenium::Client::Base
7
+ end
8
+
9
+ describe "#initialize with hash" do
10
+ it "sets the host" do
11
+ client = BaseClient.new :host => "the.host.com"
12
+ client.host.should == "the.host.com"
13
+ end
14
+
15
+ it "sets the port" do
16
+ client = BaseClient.new :port => 4000
17
+ client.port.should == 4000
18
+ end
19
+
20
+ it "sets the port as a string" do
21
+ client = BaseClient.new :port => "4000"
22
+ client.port.should == 4000
23
+ end
24
+
25
+ it "sets the browser string" do
26
+ client = BaseClient.new :browser => "*safari"
27
+ client.browser_string.should == "*safari"
28
+ end
29
+
30
+ it "sets the browser url" do
31
+ client = BaseClient.new :url => "http://ph7spot.com"
32
+ client.browser_url.should == "http://ph7spot.com"
33
+ end
34
+
35
+ it "sets the default timeout" do
36
+ client = BaseClient.new :timeout_in_seconds => 24
37
+ client.default_timeout_in_seconds.should == 24
38
+ end
39
+
40
+ it "sets the default javascript framework " do
41
+ client = BaseClient.new :javascript_framework => :jquery
42
+ client.default_javascript_framework.should == :jquery
43
+ end
44
+
45
+ it "sets the default javascript framework to prototype when not explicitely set" do
46
+ BaseClient.new.default_javascript_framework.should == :prototype
47
+ end
48
+
49
+ it "sets highlight_located_element_by_default" do
50
+ client = BaseClient.new :highlight_located_element => true
51
+
52
+ client.highlight_located_element_by_default.should be_true
53
+ end
54
+
55
+ it "sets highlight_located_element_by_default to false by default" do
56
+ client = BaseClient.new :host => :a_host
57
+ client.highlight_located_element_by_default.should be_false
58
+ end
59
+ end
60
+
61
+ describe "#initialize" do
62
+ it "sets the default timeout to 5 minutes when not explicitely set" do
63
+ BaseClient.new.default_timeout_in_seconds.should == 5 * 60
64
+ end
65
+
66
+ it "sets default_timeout_in_seconds to the client driver default timeout in seconds" do
67
+ client = BaseClient.new :host, 1234, :browser, :url, 24
68
+ client.default_timeout_in_seconds.should == 24
69
+ end
70
+
71
+ it "sets default_timeout_in_seconds to 5 minutes by default" do
72
+ client = BaseClient.new :host, 24, :browser, :url
73
+ client.default_timeout_in_seconds.should == 5 * 60
74
+ end
75
+
76
+ it "sets highlight_located_element_by_default to false by default" do
77
+ BaseClient.new.highlight_located_element_by_default.should be_false
78
+ end
79
+ end
80
+
81
+ describe "#start_new_browser_session" do
82
+ it "executes a getNewBrowserSession command with the browser string an url" do
83
+ client = BaseClient.new :host, 24, :the_browser, :the_url
84
+
85
+ client.stub!(:remote_control_command)
86
+ client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, "", ""])
87
+
88
+ client.start_new_browser_session
89
+ end
90
+
91
+ it "submits the javascript extension when previously defined" do
92
+ client = BaseClient.new :host, 24, :the_browser, :the_url
93
+ client.javascript_extension = :the_javascript_extension
94
+
95
+ client.stub!(:remote_control_command)
96
+ client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, ""])
97
+
98
+ client.start_new_browser_session
99
+ end
100
+
101
+ it "submits an option when provided" do
102
+ client = BaseClient.new :host, 24, :the_browser, :the_url
103
+ client.javascript_extension = :the_javascript_extension
104
+
105
+ client.stub!(:remote_control_command)
106
+ client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, "captureNetworkTraffic=true"])
107
+
108
+ client.start_new_browser_session(:captureNetworkTraffic => true)
109
+ end
110
+
111
+ it "submits multiple options when provided" do
112
+ client = BaseClient.new :host, 24, :the_browser, :the_url
113
+ client.javascript_extension = :the_javascript_extension
114
+
115
+ client.stub!(:remote_control_command)
116
+ client.should_receive(:string_command).with("getNewBrowserSession", [:the_browser, :the_url, :the_javascript_extension, "captureNetworkTraffic=true;quack=false"])
117
+
118
+ client.start_new_browser_session(:captureNetworkTraffic => true, :quack => false)
119
+ end
120
+
121
+ it "sets the current sessionId with getNewBrowserSession response" do
122
+ client = BaseClient.new :host, 24, :the_browser, :the_url
123
+
124
+ client.stub!(:remote_control_command)
125
+ client.should_receive(:string_command).with("getNewBrowserSession", instance_of(Array)).
126
+ and_return("the new session id")
127
+
128
+ client.start_new_browser_session
129
+
130
+ client.session_id.should == "the new session id"
131
+ end
132
+
133
+ it "sets remote control timeout to the driver default timeout" do
134
+ client = BaseClient.new :host, 24, :the_browser, :the_url, 24
135
+
136
+ client.should_receive(:string_command).with("getNewBrowserSession", instance_of(Array))
137
+ client.should_receive(:remote_control_timeout_in_seconds=).with(24)
138
+
139
+ client.start_new_browser_session
140
+ end
141
+
142
+ it "sets up auto-higlight of located element when option is set" do
143
+ client = BaseClient.new :highlight_located_element => true
144
+
145
+ client.stub!(:remote_control_command)
146
+ client.should_receive(:highlight_located_element=).with(true)
147
+
148
+ client.start_new_browser_session
149
+ end
150
+
151
+ it "does not set up auto-higlight of located element when option is not set" do
152
+ client = BaseClient.new :highlight_located_element => false
153
+
154
+ client.stub!(:remote_control_command)
155
+ client.should_not_receive(:highlight_located_element=)
156
+
157
+ client.start_new_browser_session
158
+ end
159
+ end
160
+
161
+ describe "session_started?" do
162
+ it "returns false when no session has been started" do
163
+ client = BaseClient.new :host, 24, :browser, :url
164
+ client.session_started?.should be_false
165
+ end
166
+
167
+ it "returns true when session has been started" do
168
+ client = BaseClient.new :host, 24, :browser, :url
169
+
170
+ client.stub!(:string_command).and_return("A Session Id")
171
+ client.stub!(:remote_control_command)
172
+
173
+ client.start_new_browser_session
174
+
175
+ client.session_started?.should be_true
176
+ end
177
+
178
+ it "returns false when session has been stopped" do
179
+ client = BaseClient.new :host, 24, :browser, :url
180
+
181
+ client.stub!(:string_command).and_return("A Session Id")
182
+ client.stub!(:remote_control_command)
183
+
184
+ client.start_new_browser_session
185
+ client.stop
186
+
187
+ client.session_started?.should be_false
188
+ end
189
+ end
190
+
191
+ describe "chrome_backend?" do
192
+ it "returns true when the browser string is *firefox" do
193
+ client = BaseClient.new :host, 24, "*firefox", :url
194
+ client.chrome_backend?.should be_true
195
+ end
196
+
197
+ it "returns false when the browser string is *iexplore" do
198
+ client = BaseClient.new :host, 24, "*iexplore", :url
199
+ client.chrome_backend?.should be_false
200
+ end
201
+
202
+ it "returns false when the browser string is *safari" do
203
+ client = BaseClient.new :host, 24, "*safari", :url
204
+ client.chrome_backend?.should be_false
205
+ end
206
+
207
+ it "returns false when the browser string is *opera" do
208
+ client = BaseClient.new :host, 24, "*opera", :url
209
+ client.chrome_backend?.should be_false
210
+ end
211
+
212
+ it "returns true when the browser string is *chrome" do
213
+ client = BaseClient.new :host, 24, "*chrome", :url
214
+ client.chrome_backend?.should be_true
215
+ end
216
+
217
+ it "returns true when the browser string is *firefox2" do
218
+ client = BaseClient.new :host, 24, "*firefox2", :url
219
+ client.chrome_backend?.should be_true
220
+ end
221
+
222
+ it "returns true when the browser string is *firefox3" do
223
+ client = BaseClient.new :host, 24, "*firefox3", :url
224
+ client.chrome_backend?.should be_true
225
+ end
226
+
227
+ it "returns false when the browser string is *firefoxproxy" do
228
+ client = BaseClient.new :host, 24, "*firefoxproxy", :url
229
+ client.chrome_backend?.should be_false
230
+ end
231
+
232
+ it "returns false when the browser string is *pifirefox" do
233
+ client = BaseClient.new :host, 24, "*pifirefox", :url
234
+ client.chrome_backend?.should be_false
235
+ end
236
+ end
237
+
238
+
239
+ end
@@ -0,0 +1,174 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe Selenium::Client::Extensions do
4
+ class ExtensionsClient
5
+ include Selenium::Client::Extensions
6
+ end
7
+
8
+ let(:client) { ExtensionsClient.new }
9
+
10
+ describe "#wait_for_text" do
11
+ it "waits for the innerHTML content of an element when a locator is provided" do
12
+ client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything)
13
+ client.wait_for_text "some text", :element => "a_locator"
14
+ end
15
+
16
+ it "waits for the page content when no locator is provided" do
17
+ client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything)
18
+ client.wait_for_text "some text"
19
+ end
20
+
21
+ it "waits for the page content regexp when no locator is provided" do
22
+ client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything)
23
+ client.wait_for_text(/some text/)
24
+ end
25
+
26
+ it "uses default timeout when none is provided" do
27
+ client.should_receive(:wait_for_condition).with(anything, nil)
28
+ client.wait_for_text "some text"
29
+ end
30
+
31
+ it "uses explicit timeout when provided" do
32
+ client.should_receive(:wait_for_condition).with(anything, :explicit_timeout)
33
+ client.wait_for_text "some text", :timeout_in_seconds => :explicit_timeout
34
+ end
35
+ end
36
+
37
+ describe "#wait_for_no_text" do
38
+ it "waits for the innerHTML content of an element when a locator is provided" do
39
+ client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything)
40
+ client.wait_for_no_text "some text", :element => "a_locator"
41
+ end
42
+
43
+ it "waits for the page content for regexp when no locator is provided" do
44
+ client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything)
45
+ client.wait_for_no_text(/some text/)
46
+ end
47
+
48
+ it "waits for the page content when no locator is provided" do
49
+ client.should_receive(:wait_for_condition).with(%r{document.body.innerHTML.match\(/some text/\)}m, anything)
50
+ client.wait_for_no_text "some text"
51
+ end
52
+
53
+ it "uses default timeout when none is provided" do
54
+ client.should_receive(:wait_for_condition).with(anything, nil)
55
+ client.wait_for_no_text "some text"
56
+ end
57
+
58
+ it "uses explicit timeout when provided" do
59
+ client.should_receive(:wait_for_condition).with(anything, :explicit_timeout)
60
+ client.wait_for_no_text "some text", :timeout_in_seconds => :explicit_timeout
61
+ end
62
+ end
63
+
64
+ describe "#wait_for_ajax" do
65
+ it "uses Ajax.activeRequestCount when default js framework is prototype" do
66
+ client.stub!(:default_javascript_framework).and_return(:prototype)
67
+ client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;", anything)
68
+ client.wait_for_ajax
69
+ end
70
+
71
+ it "uses jQuery.active when default js framework is jQuery" do
72
+ client.stub!(:default_javascript_framework).and_return(:jquery)
73
+ client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().jQuery.active == 0;", anything)
74
+ client.wait_for_ajax
75
+ end
76
+
77
+ it "can override default js framework" do
78
+ client.stub!(:default_javascript_framework).and_return(:prototype)
79
+ client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().jQuery.active == 0;", anything)
80
+ client.wait_for_ajax :javascript_framework => :jquery
81
+ end
82
+
83
+ it "uses default timeout when none is provided" do
84
+ client.stub!(:default_javascript_framework).and_return(:prototype)
85
+ client.should_receive(:wait_for_condition).with(anything, nil)
86
+ client.wait_for_ajax
87
+ end
88
+
89
+ it "uses explicit timeout when provided" do
90
+ client.stub!(:default_javascript_framework).and_return(:prototype)
91
+ client.should_receive(:wait_for_condition).with(anything, :explicit_timeout)
92
+ client.wait_for_ajax :timeout_in_seconds => :explicit_timeout
93
+ end
94
+
95
+ end
96
+
97
+ describe "#wait_for_effect" do
98
+ it "uses Effect.Queue.size() when default js framework is prototype" do
99
+ client.stub!(:default_javascript_framework).and_return(:prototype)
100
+ client.should_receive(:wait_for_condition).with("selenium.browserbot.getCurrentWindow().Effect.Queue.size() == 0;", anything)
101
+ client.wait_for_effects
102
+ end
103
+
104
+ it "uses default timeout when none is provided" do
105
+ client.stub!(:default_javascript_framework).and_return(:prototype)
106
+ client.should_receive(:wait_for_condition).with(anything, nil)
107
+ client.wait_for_effects
108
+ end
109
+
110
+ it "uses explicit timeout when provided" do
111
+ client.stub!(:default_javascript_framework).and_return(:prototype)
112
+ client.should_receive(:wait_for_condition).with(anything, :explicit_timeout)
113
+ client.wait_for_effects :timeout_in_seconds => :explicit_timeout
114
+ end
115
+ end
116
+
117
+ describe "#wait_for_field_value" do
118
+ it "uses provided locator" do
119
+ client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything)
120
+ client.wait_for_field_value "a_locator", "a value"
121
+ end
122
+
123
+ it "uses provided field value" do
124
+ client.should_receive(:wait_for_condition).with(/element.value == 'a value'/, anything)
125
+ client.wait_for_field_value "a_locator", "a value"
126
+ end
127
+
128
+ it "uses explicit timeout when provided" do
129
+ client.should_receive(:wait_for_condition).with(anything, :the_timeout)
130
+ client.wait_for_field_value "a_locator", "a value", :timeout_in_seconds => :the_timeout
131
+ end
132
+ end
133
+
134
+ describe "#wait_for_no_field_value" do
135
+ it "uses provided locator" do
136
+ client.should_receive(:wait_for_condition).with(/findElement\('a_locator'\)/, anything)
137
+ client.wait_for_no_field_value "a_locator", "a value"
138
+ end
139
+
140
+ it "uses provided field value" do
141
+ client.should_receive(:wait_for_condition).with(/element.value != 'a value'/, anything)
142
+ client.wait_for_no_field_value "a_locator", "a value"
143
+ end
144
+
145
+ it "uses explicit timeout when provided" do
146
+ client.should_receive(:wait_for_condition).with(anything, :the_timeout)
147
+ client.wait_for_no_field_value "a_locator", "a value", :timeout_in_seconds => :the_timeout
148
+ end
149
+ end
150
+
151
+ describe "#wait_for_visible" do
152
+ it "uses provided locator" do
153
+ client.should_receive(:wait_for_condition).with("selenium.isVisible('a_locator')", anything)
154
+ client.wait_for_visible "a_locator"
155
+ end
156
+
157
+ it "uses explicit timeout when provided" do
158
+ client.should_receive(:wait_for_condition).with(anything, :the_timeout)
159
+ client.wait_for_visible "a_locator", :timeout_in_seconds => :the_timeout
160
+ end
161
+ end
162
+
163
+ describe "#wait_for_not_visible" do
164
+ it "uses provided locator" do
165
+ client.should_receive(:wait_for_condition).with("!selenium.isVisible('a_locator')", anything)
166
+ client.wait_for_not_visible "a_locator"
167
+ end
168
+
169
+ it "uses explicit timeout when provided" do
170
+ client.should_receive(:wait_for_condition).with(anything, :the_timeout)
171
+ client.wait_for_not_visible "a_locator", :timeout_in_seconds => :the_timeout
172
+ end
173
+ end
174
+ end