browserstack-webdriver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +791 -0
  3. data/README.md +31 -0
  4. data/build.desc +334 -0
  5. data/lib/selenium-client.rb +2 -0
  6. data/lib/selenium-webdriver.rb +1 -0
  7. data/lib/selenium/client.rb +37 -0
  8. data/lib/selenium/client/base.rb +132 -0
  9. data/lib/selenium/client/driver.rb +10 -0
  10. data/lib/selenium/client/errors.rb +9 -0
  11. data/lib/selenium/client/extensions.rb +118 -0
  12. data/lib/selenium/client/idiomatic.rb +488 -0
  13. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  14. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  15. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  16. data/lib/selenium/client/legacy_driver.rb +1720 -0
  17. data/lib/selenium/client/protocol.rb +104 -0
  18. data/lib/selenium/client/selenium_helper.rb +34 -0
  19. data/lib/selenium/rake/server_task.rb +157 -0
  20. data/lib/selenium/server.rb +248 -0
  21. data/lib/selenium/webdriver.rb +71 -0
  22. data/lib/selenium/webdriver/android.rb +9 -0
  23. data/lib/selenium/webdriver/android/bridge.rb +47 -0
  24. data/lib/selenium/webdriver/chrome.rb +26 -0
  25. data/lib/selenium/webdriver/chrome/bridge.rb +120 -0
  26. data/lib/selenium/webdriver/chrome/profile.rb +90 -0
  27. data/lib/selenium/webdriver/chrome/service.rb +75 -0
  28. data/lib/selenium/webdriver/common.rb +44 -0
  29. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  30. data/lib/selenium/webdriver/common/alert.rb +30 -0
  31. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  32. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  33. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  34. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  35. data/lib/selenium/webdriver/common/driver.rb +301 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/has_browser_connection.rb +17 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  38. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +25 -0
  39. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +13 -0
  40. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +22 -0
  41. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +19 -0
  42. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +22 -0
  43. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +45 -0
  44. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  46. data/lib/selenium/webdriver/common/element.rb +293 -0
  47. data/lib/selenium/webdriver/common/error.rb +207 -0
  48. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  49. data/lib/selenium/webdriver/common/html5/local_storage.rb +42 -0
  50. data/lib/selenium/webdriver/common/html5/location.rb +0 -0
  51. data/lib/selenium/webdriver/common/html5/session_storage.rb +44 -0
  52. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +42 -0
  53. data/lib/selenium/webdriver/common/json_helper.rb +34 -0
  54. data/lib/selenium/webdriver/common/keyboard.rb +55 -0
  55. data/lib/selenium/webdriver/common/keys.rb +109 -0
  56. data/lib/selenium/webdriver/common/log_entry.rb +29 -0
  57. data/lib/selenium/webdriver/common/logs.rb +23 -0
  58. data/lib/selenium/webdriver/common/mouse.rb +72 -0
  59. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  60. data/lib/selenium/webdriver/common/options.rb +136 -0
  61. data/lib/selenium/webdriver/common/platform.rb +218 -0
  62. data/lib/selenium/webdriver/common/port_prober.rb +42 -0
  63. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  64. data/lib/selenium/webdriver/common/proxy.rb +149 -0
  65. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  66. data/lib/selenium/webdriver/common/socket_poller.rb +105 -0
  67. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  68. data/lib/selenium/webdriver/common/timeouts.rb +38 -0
  69. data/lib/selenium/webdriver/common/touch_action_builder.rb +64 -0
  70. data/lib/selenium/webdriver/common/touch_screen.rb +105 -0
  71. data/lib/selenium/webdriver/common/wait.rb +63 -0
  72. data/lib/selenium/webdriver/common/window.rb +104 -0
  73. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  74. data/lib/selenium/webdriver/firefox.rb +37 -0
  75. data/lib/selenium/webdriver/firefox/binary.rb +158 -0
  76. data/lib/selenium/webdriver/firefox/bridge.rb +70 -0
  77. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  78. data/lib/selenium/webdriver/firefox/launcher.rb +106 -0
  79. data/lib/selenium/webdriver/firefox/profile.rb +263 -0
  80. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  81. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  82. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  83. data/lib/selenium/webdriver/ie.rb +19 -0
  84. data/lib/selenium/webdriver/ie/bridge.rb +68 -0
  85. data/lib/selenium/webdriver/ie/server.rb +86 -0
  86. data/lib/selenium/webdriver/iphone.rb +9 -0
  87. data/lib/selenium/webdriver/iphone/bridge.rb +45 -0
  88. data/lib/selenium/webdriver/opera.rb +24 -0
  89. data/lib/selenium/webdriver/opera/bridge.rb +112 -0
  90. data/lib/selenium/webdriver/opera/service.rb +49 -0
  91. data/lib/selenium/webdriver/phantomjs.rb +22 -0
  92. data/lib/selenium/webdriver/phantomjs/bridge.rb +59 -0
  93. data/lib/selenium/webdriver/phantomjs/service.rb +90 -0
  94. data/lib/selenium/webdriver/remote.rb +22 -0
  95. data/lib/selenium/webdriver/remote/bridge.rb +644 -0
  96. data/lib/selenium/webdriver/remote/capabilities.rb +267 -0
  97. data/lib/selenium/webdriver/remote/commands.rb +193 -0
  98. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  99. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  100. data/lib/selenium/webdriver/remote/http/default.rb +139 -0
  101. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  102. data/lib/selenium/webdriver/remote/response.rb +97 -0
  103. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  104. data/lib/selenium/webdriver/safari.rb +46 -0
  105. data/lib/selenium/webdriver/safari/bridge.rb +110 -0
  106. data/lib/selenium/webdriver/safari/browser.rb +20 -0
  107. data/lib/selenium/webdriver/safari/extension.rb +120 -0
  108. data/lib/selenium/webdriver/safari/server.rb +145 -0
  109. data/lib/selenium/webdriver/support.rb +5 -0
  110. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  111. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  112. data/lib/selenium/webdriver/support/color.rb +110 -0
  113. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  114. data/lib/selenium/webdriver/support/select.rb +293 -0
  115. data/ruby.iml +13 -0
  116. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  117. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  118. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  119. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  120. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  121. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  122. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  123. data/spec/integration/selenium/client/api/screenshot_spec.rb +31 -0
  124. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  125. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  126. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  127. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  128. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  129. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  130. data/spec/integration/selenium/client/api/webdriver_backed_spec.rb +21 -0
  131. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  132. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  133. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  134. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  135. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  136. data/spec/integration/selenium/client/spec_helper.rb +139 -0
  137. data/spec/integration/selenium/webdriver/app_cache_spec.rb +47 -0
  138. data/spec/integration/selenium/webdriver/browser_connection_spec.rb +20 -0
  139. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  140. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +63 -0
  141. data/spec/integration/selenium/webdriver/driver_spec.rb +266 -0
  142. data/spec/integration/selenium/webdriver/element_spec.rb +191 -0
  143. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  144. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  145. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  146. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  147. data/spec/integration/selenium/webdriver/location_spec.rb +29 -0
  148. data/spec/integration/selenium/webdriver/mouse_spec.rb +57 -0
  149. data/spec/integration/selenium/webdriver/navigation_spec.rb +46 -0
  150. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  151. data/spec/integration/selenium/webdriver/options_spec.rb +77 -0
  152. data/spec/integration/selenium/webdriver/remote/driver_spec.rb +19 -0
  153. data/spec/integration/selenium/webdriver/remote/element_spec.rb +26 -0
  154. data/spec/integration/selenium/webdriver/spec_helper.rb +36 -0
  155. data/spec/integration/selenium/webdriver/spec_support.rb +12 -0
  156. data/spec/integration/selenium/webdriver/spec_support/guards.rb +110 -0
  157. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +51 -0
  158. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  159. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +239 -0
  160. data/spec/integration/selenium/webdriver/sql_database_spec.rb +59 -0
  161. data/spec/integration/selenium/webdriver/storage_spec.rb +96 -0
  162. data/spec/integration/selenium/webdriver/target_locator_spec.rb +186 -0
  163. data/spec/integration/selenium/webdriver/timeout_spec.rb +69 -0
  164. data/spec/integration/selenium/webdriver/touch_spec.rb +176 -0
  165. data/spec/integration/selenium/webdriver/window_spec.rb +70 -0
  166. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  167. data/spec/unit/selenium/client/base_spec.rb +239 -0
  168. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  169. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  170. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  171. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  172. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  173. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  174. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  175. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  176. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  177. data/spec/unit/selenium/server_spec.rb +150 -0
  178. data/spec/unit/selenium/webdriver/action_builder_spec.rb +97 -0
  179. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +43 -0
  180. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +137 -0
  181. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  182. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  183. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  184. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +47 -0
  185. data/spec/unit/selenium/webdriver/ie/bridge_spec.rb +91 -0
  186. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +42 -0
  187. data/spec/unit/selenium/webdriver/log_entry_spec.rb +11 -0
  188. data/spec/unit/selenium/webdriver/opera/bridge_spec.rb +44 -0
  189. data/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb +55 -0
  190. data/spec/unit/selenium/webdriver/proxy_spec.rb +106 -0
  191. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  192. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +115 -0
  193. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  194. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +124 -0
  195. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  196. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  197. data/spec/unit/selenium/webdriver/spec_helper.rb +27 -0
  198. data/spec/unit/selenium/webdriver/support/color_spec.rb +119 -0
  199. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  200. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  201. data/spec/unit/selenium/webdriver/wait_spec.rb +49 -0
  202. metadata +370 -0
@@ -0,0 +1,24 @@
1
+ require File.expand_path("../../../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+ module Http
7
+ describe Common do
8
+
9
+ it "sends non-empty body header for POST requests without command data" do
10
+ common = Common.new
11
+ common.server_url = URI.parse("http://server")
12
+
13
+ common.should_receive(:request).
14
+ with(:post, URI.parse("http://server/clear"),
15
+ hash_including("Content-Length" => "2"), "{}")
16
+
17
+ common.call(:post, "clear", nil)
18
+ end
19
+
20
+ end # Common
21
+ end # Http
22
+ end # Remote
23
+ end # WebDriver
24
+ end # Selenium
@@ -0,0 +1,124 @@
1
+ require File.expand_path("../../../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+ module Http
7
+ describe Default do
8
+ let(:client) {
9
+ client = Default.new
10
+ client.server_url = URI.parse("http://example.com")
11
+
12
+ client
13
+ }
14
+
15
+ it "uses the specified timeout" do
16
+ client.timeout = 10
17
+ http = client.send :http
18
+
19
+ http.open_timeout.should == 10
20
+ http.read_timeout.should == 10
21
+ end
22
+
23
+ it "uses the specified proxy" do
24
+ client.proxy = Proxy.new(:http => "http://foo:bar@proxy.org:8080")
25
+ http = client.send :http
26
+
27
+ http.should be_proxy
28
+ http.proxy_address.should == "proxy.org"
29
+ http.proxy_port.should == 8080
30
+ http.proxy_user.should == "foo"
31
+ http.proxy_pass.should == "bar"
32
+
33
+ http.address.should == "example.com"
34
+ end
35
+
36
+ it "raises an error if the proxy is not an HTTP proxy" do
37
+ client.proxy = Proxy.new(:ftp => "ftp://example.com")
38
+ lambda { client.send :http }.should raise_error(Error::WebDriverError)
39
+ end
40
+
41
+ ["http_proxy", "HTTP_PROXY"].each { |proxy_var|
42
+ it "honors the #{proxy_var} environment varable" do
43
+ with_env(proxy_var => "http://proxy.org:8080") do
44
+ http = client.send :http
45
+
46
+ http.should be_proxy
47
+ http.proxy_address.should == "proxy.org"
48
+ http.proxy_port.should == 8080
49
+ end
50
+ end
51
+
52
+ it "handles #{proxy_var} without http://" do
53
+ with_env(proxy_var => "proxy.org:8080") do
54
+ http = client.send :http
55
+
56
+ http.should be_proxy
57
+ http.proxy_address.should == "proxy.org"
58
+ http.proxy_port.should == 8080
59
+ end
60
+ end
61
+ }
62
+
63
+ ["no_proxy", "NO_PROXY"].each do |no_proxy_var|
64
+ it "honors the #{no_proxy_var} environment variable when matching" do
65
+ with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "example.com") do
66
+ http = client.send :http
67
+ http.should_not be_proxy
68
+ end
69
+ end
70
+
71
+ it "ignores the #{no_proxy_var} environment variable when not matching" do
72
+ with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "foo.com") do
73
+ http = client.send :http
74
+
75
+ http.should be_proxy
76
+ http.proxy_address.should == "proxy.org"
77
+ http.proxy_port.should == 8080
78
+ end
79
+ end
80
+
81
+ it "understands a comma separated list of domains in #{no_proxy_var}" do
82
+ with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "example.com,foo.com") do
83
+ http = client.send :http
84
+ http.should_not be_proxy
85
+ end
86
+ end
87
+
88
+ unless RUBY_VERSION > "2.0" # Ruby 2.0 does its own proxy handling in net/http, which breaks this behaviour
89
+ it "understands an asterisk in #{no_proxy_var}" do
90
+ with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "*") do
91
+ http = client.send :http
92
+ http.should_not be_proxy
93
+ end
94
+ end
95
+ end
96
+
97
+ it "understands subnetting in #{no_proxy_var}" do
98
+ with_env("HTTP_PROXY" => "proxy.org:8080", no_proxy_var => "localhost,127.0.0.0/8") do
99
+ client.server_url = URI.parse("http://127.0.0.1:4444/wd/hub")
100
+
101
+ http = client.send :http
102
+ http.should_not be_proxy
103
+ end
104
+ end
105
+ end
106
+
107
+ it "raises a sane error if a proxy is refusing connections" do
108
+ with_env("http_proxy" => "http://localhost:1234") do
109
+ http = client.send :http
110
+ http.should_receive(:request).and_raise Errno::ECONNREFUSED.new("Connection refused")
111
+
112
+ lambda {
113
+ client.call :post, 'http://example.com/foo/bar', {}
114
+ }.should raise_error(Errno::ECONNREFUSED, %r[using proxy: http://localhost:1234])
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ end # Http
121
+ end # Remote
122
+ end # WebDriver
123
+ end # Selenium
124
+
@@ -0,0 +1,61 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "SearchContext" do
4
+ class TestSearchContext
5
+ attr_reader :bridge, :ref
6
+
7
+ include Selenium::WebDriver::SearchContext
8
+
9
+ def initialize(bridge)
10
+ @bridge = bridge
11
+ end
12
+ end
13
+
14
+ let(:element) { double(:Element)}
15
+ let(:bridge) { double(:Bridge).as_null_object }
16
+ let(:search_context) { TestSearchContext.new(bridge) }
17
+
18
+ context "finding a single element" do
19
+ it "accepts a hash" do
20
+ bridge.should_receive(:find_element_by).with('id', "bar", nil).and_return(element)
21
+ search_context.find_element(:id => "bar").should == element
22
+ end
23
+
24
+ it "accepts two arguments" do
25
+ bridge.should_receive(:find_element_by).with('id', "bar", nil).and_return(element)
26
+ search_context.find_element(:id, "bar").should == element
27
+ end
28
+
29
+ it "raises an error if given an invalid 'by'" do
30
+ lambda {
31
+ search_context.find_element(:foo => "bar")
32
+ }.should raise_error(ArgumentError, 'cannot find element by :foo')
33
+ end
34
+
35
+ it "does not modify the hash given" do
36
+ selector = {:id => "foo"}
37
+
38
+ search_context.find_element(selector)
39
+
40
+ selector.should == {:id => "foo"}
41
+ end
42
+ end
43
+
44
+ context "finding multiple elements" do
45
+ it "accepts a hash" do
46
+ bridge.should_receive(:find_elements_by).with('id', "bar", nil).and_return([])
47
+ search_context.find_elements(:id => "bar").should == []
48
+ end
49
+
50
+ it "accepts two arguments" do
51
+ bridge.should_receive(:find_elements_by).with('id', "bar", nil).and_return([])
52
+ search_context.find_elements(:id, "bar").should == []
53
+ end
54
+
55
+ it "raises an error if given an invalid 'by'" do
56
+ lambda {
57
+ search_context.find_elements(:foo => "bar")
58
+ }.should raise_error(ArgumentError, 'cannot find elements by :foo')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ describe SocketPoller do
6
+ let(:poller) { Selenium::WebDriver::SocketPoller.new("localhost", 1234, 5, 0.05) }
7
+ let(:socket) { double Socket, :close => true}
8
+
9
+ def setup_connect(*states)
10
+ # TODO(jari): find a cleaner way to solve the platform-specific collaborators
11
+ if Platform.jruby?
12
+ states.each { |state|
13
+ if state
14
+ TCPSocket.should_receive(:new).and_return socket
15
+ else
16
+ TCPSocket.should_receive(:new).and_raise Errno::ECONNREFUSED
17
+ end
18
+ }
19
+ else
20
+ Socket.stub(:new).and_return socket
21
+ states.each { |state|
22
+ socket.should_receive(:connect_nonblock).
23
+ and_raise(state ? Errno::EISCONN.new("connection in progress") : Errno::ECONNREFUSED.new("connection refused"))
24
+ }
25
+ end
26
+ end
27
+
28
+ describe "#connected?" do
29
+ it "returns true when the socket is listening" do
30
+ setup_connect false, true
31
+ poller.should be_connected
32
+ end
33
+
34
+ it "returns false if the socket is not listening after the given timeout" do
35
+ setup_connect false
36
+
37
+ start = Time.parse("2010-01-01 00:00:00")
38
+ wait = Time.parse("2010-01-01 00:00:04")
39
+ stop = Time.parse("2010-01-01 00:00:06")
40
+
41
+ Time.should_receive(:now).and_return(start, wait, stop)
42
+ poller.should_not be_connected
43
+ end
44
+ end
45
+
46
+ describe "#closed?" do
47
+ it "returns true when the socket is closed" do
48
+ setup_connect true, true, false
49
+
50
+ poller.should be_closed
51
+ end
52
+
53
+ it "returns false if the socket is still listening after the given timeout" do
54
+ setup_connect true
55
+
56
+ start = Time.parse("2010-01-01 00:00:00")
57
+ wait = Time.parse("2010-01-01 00:00:04")
58
+ stop = Time.parse("2010-01-01 00:00:06")
59
+
60
+ # on rbx, we can't add expectations to Time.now since it will be called by the kernel code.
61
+ poller.should_receive(:time_now).and_return(start, wait, stop)
62
+ poller.should_not be_closed
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'time'
3
+ require 'rspec'
4
+ require 'ci/reporter/rspec'
5
+ require 'webmock/rspec'
6
+ require 'selenium-webdriver'
7
+
8
+ module Selenium
9
+ module WebDriver
10
+ module UnitSpecHelper
11
+
12
+ def with_env(hash, &blk)
13
+ hash.each { |k,v| ENV[k.to_s] = v.to_s }
14
+ yield
15
+ ensure
16
+ hash.each_key { |k| ENV.delete(k) }
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ RSpec.configure do |c|
24
+ c.include Selenium::WebDriver::UnitSpecHelper
25
+
26
+ c.filter_run :focus => true if ENV['focus']
27
+ end
@@ -0,0 +1,119 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Support
6
+ describe Color do
7
+ it "converts rgb to rgb" do
8
+ str = "rgb(1, 2, 3)"
9
+ Color.from_string(str).rgb.should == str
10
+ end
11
+
12
+ it "converts rgb to rgba" do
13
+ str = "rgb(1, 2, 3)"
14
+ Color.from_string(str).rgba.should == "rgba(1, 2, 3, 1)"
15
+ end
16
+
17
+ it "converts rgb percent to rgba" do
18
+ str = "rgb(10%, 20%, 30%)"
19
+ Color.from_string(str).rgba.should == "rgba(25, 51, 76, 1)"
20
+ end
21
+
22
+ it "allows whitespace in rgb string" do
23
+ str = "rgb(\t1, 2 , 3)"
24
+ Color.from_string(str).rgb.should == "rgb(1, 2, 3)"
25
+ end
26
+
27
+ it "converts rgba to rgba" do
28
+ str = "rgba(1, 2, 3, 0.5)"
29
+ Color.from_string(str).rgba.should == str
30
+ end
31
+
32
+ it "converts rgba percent to rgba" do
33
+ str = "rgba(10%, 20%, 30%, 0.5)"
34
+ Color.from_string(str).rgba.should == "rgba(25, 51, 76, 0.5)"
35
+ end
36
+
37
+ it "converts hex to hex" do
38
+ str = "#ff00a0"
39
+ Color.from_string(str).hex.should == str
40
+ end
41
+
42
+ it "converts hex to rgb" do
43
+ hex = "#01Ff03"
44
+ rgb = "rgb(1, 255, 3)"
45
+
46
+ Color.from_string(hex).rgb.should == rgb
47
+ end
48
+
49
+ it "converts hex to rgba" do
50
+ hex = "#01Ff03"
51
+ rgba = "rgba(1, 255, 3, 1)"
52
+
53
+ Color.from_string(hex).rgba.should == rgba
54
+
55
+ hex = "#00ff33";
56
+ rgba = "rgba(0, 255, 51, 1)"
57
+
58
+ Color.from_string(hex).rgba.should == rgba
59
+ end
60
+
61
+ it "converts rgb to hex" do
62
+ Color.from_string("rgb(1, 255, 3)").hex.should == "#01ff03"
63
+ end
64
+
65
+ it "converts hex3 to rgba" do
66
+ Color.from_string("#0f3").rgba.should == "rgba(0, 255, 51, 1)"
67
+ end
68
+
69
+ it "converts hsl to rgba" do
70
+ hsl = "hsl(120, 100%, 25%)"
71
+ rgba = "rgba(0, 128, 0, 1)"
72
+
73
+ Color.from_string(hsl).rgba.should == rgba
74
+
75
+ hsl = "hsl(100, 0%, 50%)"
76
+ rgba = "rgba(128, 128, 128, 1)"
77
+
78
+ Color.from_string(hsl).rgba.should == "rgba(128, 128, 128, 1)"
79
+ end
80
+
81
+ it "converts hsla to rgba" do
82
+ hsla = "hsla(120, 100%, 25%, 1)"
83
+ rgba = "rgba(0, 128, 0, 1)"
84
+
85
+ Color.from_string(hsla).rgba.should == rgba
86
+
87
+ hsla = "hsla(100, 0%, 50%, 0.5)"
88
+ rgba = "rgba(128, 128, 128, 0.5)"
89
+
90
+ Color.from_string(hsla).rgba.should == rgba
91
+ end
92
+
93
+ it "is equal to a color with the same values" do
94
+ rgba = "rgba(30, 30, 30, 0.2)"
95
+ other = "rgba(30, 30, 30, 1)"
96
+
97
+ Color.from_string(rgba).should == Color.from_string(rgba)
98
+ Color.from_string(rgba).should_not == Color.from_string(other)
99
+ end
100
+
101
+ it "implements #hash correctly" do
102
+ a = Color.from_string("#000")
103
+ b = Color.from_string("#001")
104
+ c = Color.from_string("#000")
105
+
106
+ h = {}
107
+ h[a] = 1
108
+ h[b] = 2
109
+ h[c] = 3
110
+
111
+ h.values.sort.should == [2, 3]
112
+ end
113
+
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+
@@ -0,0 +1,111 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Support
6
+
7
+ describe EventFiringBridge do
8
+ let(:bridge) { double(Remote::Bridge, :driver_extensions => []) }
9
+ let(:listener) { double("EventListener") }
10
+ let(:event_firing_bridge) { EventFiringBridge.new(bridge, listener) }
11
+ let(:driver) { Driver.new(event_firing_bridge) }
12
+ let(:element) { Element.new(event_firing_bridge, "ref") }
13
+
14
+ context "navigation" do
15
+ it "fires events for navigate.to" do
16
+ url = "http://example.com"
17
+
18
+ listener.should_receive(:before_navigate_to).with(url, instance_of(Driver))
19
+ bridge.should_receive(:get).with(url)
20
+ listener.should_receive(:after_navigate_to).with(url, instance_of(Driver))
21
+
22
+ driver.navigate.to(url)
23
+ end
24
+
25
+ it "fires events for navigate.back" do
26
+ listener.should_receive(:before_navigate_back).with instance_of(Driver)
27
+ bridge.should_receive(:goBack)
28
+ listener.should_receive(:after_navigate_back).with instance_of(Driver)
29
+
30
+ driver.navigate.back
31
+ end
32
+
33
+ it "fires events for navigate.forward" do
34
+ listener.should_receive(:before_navigate_forward).with instance_of(Driver)
35
+ bridge.should_receive(:goForward)
36
+ listener.should_receive(:after_navigate_forward).with instance_of(Driver)
37
+
38
+ driver.navigate.forward
39
+ end
40
+ end
41
+
42
+ context "finding elements" do
43
+ it "fires events for find_element" do
44
+ listener.should_receive(:before_find).with('id', "foo", instance_of(Driver))
45
+ bridge.should_receive(:find_element_by).with('id', "foo", nil).and_return(element)
46
+ listener.should_receive(:after_find).with('id', "foo", instance_of(Driver))
47
+
48
+ driver.find_element(:id => "foo")
49
+ end
50
+
51
+ it "fires events for find_elements" do
52
+ listener.should_receive(:before_find).with('class name', "foo", instance_of(Driver))
53
+ bridge.should_receive(:find_elements_by).with('class name', "foo", nil).and_return([element])
54
+ listener.should_receive(:after_find).with('class name', "foo", instance_of(Driver))
55
+
56
+ driver.find_elements(:class => "foo")
57
+ end
58
+ end
59
+
60
+ context "changing elements" do
61
+ it "fires events for send_keys" do
62
+ listener.should_receive(:before_change_value_of).with(instance_of(Element), instance_of(Driver))
63
+ bridge.should_receive(:sendKeysToElement).with("ref", ["cheese"])
64
+ listener.should_receive(:after_change_value_of).with(instance_of(Element), instance_of(Driver))
65
+
66
+ element.send_keys "cheese"
67
+ end
68
+
69
+ it "fires events for clear" do
70
+ listener.should_receive(:before_change_value_of).with(instance_of(Element), instance_of(Driver))
71
+ bridge.should_receive(:clearElement).with("ref")
72
+ listener.should_receive(:after_change_value_of).with(instance_of(Element), instance_of(Driver))
73
+
74
+ element.clear
75
+ end
76
+ end
77
+
78
+ context "executing scripts" do
79
+ it "fires events for execute_script" do
80
+ script, arg = 'script', 'arg'
81
+
82
+ listener.should_receive(:before_execute_script).with(script, instance_of(Driver))
83
+ bridge.should_receive(:executeScript).with(script, arg)
84
+ listener.should_receive(:after_execute_script).with(script, instance_of(Driver))
85
+
86
+ driver.execute_script script, arg
87
+ end
88
+ end
89
+
90
+ context "closing and quitting" do
91
+ it "fires events for close" do
92
+ listener.should_receive(:before_close).with instance_of(Driver)
93
+ bridge.should_receive(:close)
94
+ listener.should_receive(:after_close).with instance_of(Driver)
95
+
96
+ driver.close
97
+ end
98
+
99
+ it "fires events for quit" do
100
+ listener.should_receive(:before_quit).with instance_of(Driver)
101
+ bridge.should_receive(:quit)
102
+ listener.should_receive(:after_quit).with instance_of(Driver)
103
+
104
+ driver.quit
105
+ end
106
+ end
107
+ end
108
+
109
+ end # Support
110
+ end # WebDriver
111
+ end # Selenium