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,97 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe Selenium::WebDriver::ActionBuilder do
4
+ let(:bridge) { double("Bridge").as_null_object }
5
+ let(:keyboard) { double(Selenium::WebDriver::Keyboard) }
6
+ let(:mouse) { double(Selenium::WebDriver::Mouse) }
7
+ let(:element) { Selenium::WebDriver::Element.new(bridge, 'element') }
8
+ let(:builder) { Selenium::WebDriver::ActionBuilder.new(mouse, keyboard) }
9
+
10
+ it "should create all keyboard actions" do
11
+ keyboard.should_receive(:press).with(:shift)
12
+ keyboard.should_receive(:send_keys).with("abc")
13
+ keyboard.should_receive(:release).with(:control)
14
+
15
+ builder.key_down(:shift).
16
+ send_keys("abc").
17
+ key_up(:control).perform
18
+ end
19
+
20
+ it "should pass an element to keyboard actions" do
21
+ mouse.should_receive(:click).with(element)
22
+ keyboard.should_receive(:press).with(:shift)
23
+
24
+ builder.key_down(element, :shift).perform
25
+ end
26
+
27
+ it "should allow supplying individual elements to keyboard actions" do
28
+ element2 = Selenium::WebDriver::Element.new(bridge, 'element2')
29
+ element3 = Selenium::WebDriver::Element.new(bridge, 'element3')
30
+
31
+ mouse.should_receive(:click).with(element)
32
+ keyboard.should_receive(:press).with(:shift)
33
+ mouse.should_receive(:click).with(element2)
34
+ keyboard.should_receive(:send_keys).with("abc")
35
+ mouse.should_receive(:click).with(element3)
36
+ keyboard.should_receive(:release).with(:control)
37
+
38
+ builder.key_down(element, :shift ).
39
+ send_keys(element2, "abc").
40
+ key_up(element3, :control).perform
41
+ end
42
+
43
+ it "should create all mouse actions" do
44
+ mouse.should_receive(:down).with(element)
45
+ mouse.should_receive(:up).with(element)
46
+ mouse.should_receive(:click).with(element)
47
+ mouse.should_receive(:double_click).with(element)
48
+ mouse.should_receive(:move_to).with(element)
49
+ mouse.should_receive(:context_click).with(element)
50
+
51
+ builder.click_and_hold(element).
52
+ release(element).
53
+ click(element).
54
+ double_click(element).
55
+ move_to(element).
56
+ context_click(element).perform
57
+ end
58
+
59
+ it "should drag and drop" do
60
+ source = element
61
+ target = Selenium::WebDriver::Element.new(bridge, 'element2')
62
+
63
+ mouse.should_receive(:down).with(source)
64
+ mouse.should_receive(:move_to).with(target)
65
+ mouse.should_receive(:up)
66
+
67
+ builder.drag_and_drop(source, target).perform
68
+ end
69
+
70
+ it "should drag and drop with offsets" do
71
+ source = element
72
+
73
+ mouse.should_receive(:down).with(source)
74
+ mouse.should_receive(:move_by).with(-300, 400)
75
+ mouse.should_receive(:up)
76
+
77
+ builder.drag_and_drop_by(source, -300, 400).perform
78
+ end
79
+
80
+ it "can move the mouse by coordinates" do
81
+ mouse.should_receive(:down).with(element)
82
+ mouse.should_receive(:move_by).with(-300, 400)
83
+ mouse.should_receive(:up)
84
+
85
+ builder.click_and_hold(element).
86
+ move_by(-300, 400).
87
+ release.perform
88
+ end
89
+
90
+ it 'can click, hold and release at the current location' do
91
+ mouse.should_receive(:down).with(nil)
92
+ mouse.should_receive(:up)
93
+
94
+ builder.click_and_hold.release.perform
95
+ end
96
+
97
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module Android
7
+ describe Android do
8
+ let(:default_url) { URI.parse(Android::Bridge::DEFAULT_URL) }
9
+ let(:resp) { {"sessionId" => "foo", "value" => Remote::Capabilities.android.as_json }}
10
+ let(:http) { double(Remote::Http::Default, :call => resp).as_null_object }
11
+
12
+ it "uses the default Android driver URL" do
13
+ http.should_receive(:server_url=).with default_url
14
+ Bridge.new(:http_client => http)
15
+ end
16
+
17
+ it "uses the user-provided URL" do
18
+ http.should_receive(:server_url=).with URI.parse("http://example.com")
19
+ Bridge.new(:http_client => http, :url => "http://example.com")
20
+ end
21
+
22
+ it "uses the default HTTP client when none is specified" do
23
+ Remote::Http::Default.should_receive(:new).and_return http
24
+ Bridge.new
25
+ end
26
+
27
+ it 'takes desired capabilities' do
28
+ custom_caps = Remote::Capabilities.new
29
+ custom_caps['foo'] = 'bar'
30
+
31
+ http.should_receive(:call).with do |_, _, payload|
32
+ payload[:desiredCapabilities]['foo'].should == 'bar'
33
+ resp
34
+ end
35
+
36
+ Bridge.new(:http_client => http, :desired_capabilities => custom_caps)
37
+ end
38
+ end
39
+
40
+ end # IPhone
41
+ end # WebDriver
42
+ end # Selenium
43
+
@@ -0,0 +1,137 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module Chrome
7
+
8
+ describe Bridge do
9
+ let(:resp) { {"sessionId" => "foo", "value" => @default_capabilities }}
10
+ let(:service) { double(Service, :start => true, :uri => "http://example.com") }
11
+ let(:caps) { {} }
12
+ let(:http) { double(Remote::Http::Default, :call => resp).as_null_object }
13
+
14
+ before do
15
+ @default_capabilities = Remote::Capabilities.chrome.as_json
16
+
17
+ Remote::Capabilities.stub(:chrome).and_return(caps)
18
+ Service.stub(:default_service).and_return(service)
19
+ end
20
+
21
+ it "sets the nativeEvents capability" do
22
+ Bridge.new(:http_client => http, :native_events => true)
23
+
24
+ caps['chromeOptions']['nativeEvents'].should be_true
25
+ caps['chrome.nativeEvents'].should be_true
26
+ end
27
+
28
+ it "sets the args capability" do
29
+ Bridge.new(:http_client => http, :args => %w[--foo=bar])
30
+
31
+ caps['chromeOptions']['args'].should == %w[--foo=bar]
32
+ caps['chrome.switches'].should == %w[--foo=bar]
33
+ end
34
+
35
+ it "sets the proxy capabilitiy" do
36
+ proxy = Proxy.new(:http => "localhost:1234")
37
+ Bridge.new(:http_client => http, :proxy => proxy)
38
+
39
+ caps['proxy'].should == proxy
40
+ end
41
+
42
+ it "sets the chrome.verbose capability" do
43
+ Bridge.new(:http_client => http, :verbose => true)
44
+
45
+ caps['chromeOptions']['verbose'].should be_true
46
+ caps['chrome.verbose'].should be_true
47
+ end
48
+
49
+ it "sets the chrome.detach capability" do
50
+ Bridge.new(:http_client => http) # true by default
51
+
52
+ caps['chromeOptions']['detach'].should be_true
53
+ caps['chrome.detach'].should be_true
54
+ end
55
+
56
+ it "sets the prefs capability" do
57
+ Bridge.new(:http_client => http, :prefs => {:foo => "bar"})
58
+
59
+ caps['chromeOptions']['prefs'].should == {:foo => "bar"}
60
+ caps['chrome.prefs'].should == {:foo => "bar"}
61
+ end
62
+
63
+ it "lets the user override chrome.detach" do
64
+ Bridge.new(:http_client => http, :detach => false)
65
+
66
+ caps['chromeOptions']['detach'].should be_false
67
+ caps['chrome.detach'].should be_false
68
+ end
69
+
70
+ it "lets the user override chrome.noWebsiteTestingDefaults" do
71
+ Bridge.new(:http_client => http, :no_website_testing_defaults => true)
72
+
73
+ caps['chromeOptions']['noWebsiteTestingDefaults'].should be_true
74
+ caps['chrome.noWebsiteTestingDefaults'].should be_true
75
+ end
76
+
77
+ it "uses the user-provided server URL if given" do
78
+ Service.should_not_receive(:default_service)
79
+ http.should_receive(:server_url=).with(URI.parse("http://example.com"))
80
+
81
+ Bridge.new(:http_client => http, :url => "http://example.com")
82
+ end
83
+
84
+ it "raises an ArgumentError if args is not an Array" do
85
+ lambda { Bridge.new(:args => "--foo=bar")}.should raise_error(ArgumentError)
86
+ end
87
+
88
+ it "uses the given profile" do
89
+ profile = Profile.new
90
+
91
+ profile['some_pref'] = true
92
+ profile.add_extension(__FILE__)
93
+
94
+ Bridge.new(:http_client => http, :profile => profile)
95
+
96
+ profile_data = profile.as_json
97
+ caps['chromeOptions']['profile'].should == profile_data['zip']
98
+ caps['chromeOptions']['extensions'].should == profile_data['extensions']
99
+
100
+ caps['chrome.profile'].should == profile_data['zip']
101
+ caps['chrome.extensions'].should == profile_data['extensions']
102
+ end
103
+
104
+ it 'takes desired capabilities' do
105
+ custom_caps = Remote::Capabilities.new
106
+ custom_caps['chromeOptions'] = {'foo' => 'bar'}
107
+
108
+ http.should_receive(:call).with do |_, _, payload|
109
+ payload[:desiredCapabilities]['chromeOptions'].should include('foo' => 'bar')
110
+ resp
111
+ end
112
+
113
+ Bridge.new(:http_client => http, :desired_capabilities => custom_caps)
114
+ end
115
+
116
+ it 'lets direct arguments take presedence over capabilities' do
117
+ custom_caps = Remote::Capabilities.new
118
+ custom_caps['chromeOptions'] = {'args' => %w[foo bar]}
119
+
120
+ http.should_receive(:call).with do |_, _, payload|
121
+ payload[:desiredCapabilities]['chromeOptions']['args'].should == ['baz']
122
+ resp
123
+ end
124
+
125
+ Bridge.new(:http_client => http, :desired_capabilities => custom_caps, :args => %w[baz])
126
+ end
127
+
128
+ it 'accepts :service_log_path' do
129
+ Service.should_receive(:default_service).with("--log-path=/foo/bar")
130
+ Bridge.new(:http_client => http, :service_log_path => "/foo/bar")
131
+ end
132
+ end
133
+
134
+ end # Chrome
135
+ end # WebDriver
136
+ end # Selenium
137
+
@@ -0,0 +1,57 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module Chrome
7
+
8
+ describe Profile do
9
+ let(:profile) { Profile.new }
10
+ let(:model) { "/some/path" }
11
+ let(:model_profile) { Profile.new(model) }
12
+
13
+ before do
14
+ File.stub(:exist?).with(model).and_return true
15
+ File.stub(:directory?).with(model).and_return true
16
+
17
+ Dir.stub(:mktmpdir => "/tmp/some/path")
18
+ FileUtils.stub(:rm_rf)
19
+ FileUtils.stub(:mkdir_p)
20
+ FileUtils.stub(:cp_r)
21
+ end
22
+
23
+ it "should set and get preference paths" do
24
+ profile['foo.bar.baz'] = true
25
+ profile['foo.bar.baz'].should == true
26
+ end
27
+
28
+ it "reads existing prefs" do
29
+ File.should_receive(:read).with("/some/path/Default/Preferences").
30
+ and_return('{"autofill": {"enabled": false}}')
31
+
32
+ model_profile['autofill.enabled'].should == false
33
+ end
34
+
35
+ it "writes out prefs" do
36
+ File.should_receive(:read).with("/some/path/Default/Preferences").
37
+ and_return('{"autofill": {"enabled": false}}')
38
+
39
+ model_profile['some.other.pref'] = 123
40
+
41
+ mock_io = StringIO.new
42
+ FileUtils.should_receive(:mkdir_p).with("/tmp/some/path/Default")
43
+ File.should_receive(:open).with("/tmp/some/path/Default/Preferences", "w").and_yield(mock_io)
44
+
45
+ model_profile.layout_on_disk
46
+
47
+ result = WebDriver.json_load(mock_io.string)
48
+
49
+ result['autofill']['enabled'].should == false
50
+ result['some']['other']['pref'].should == 123
51
+ end
52
+ end
53
+
54
+ end # Chrome
55
+ end # WebDriver
56
+ end # Selenium
57
+
@@ -0,0 +1,44 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Chrome
6
+
7
+ describe Service do
8
+ let(:mock_process) do
9
+ double("ChildProcess", :io => double.as_null_object, :start => true)
10
+ end
11
+
12
+ # ugh.
13
+ before { Service.instance_variable_set("@executable_path", nil) }
14
+
15
+ it "uses the user-provided path if set" do
16
+ Platform.stub(:os => :unix)
17
+ Platform.stub(:assert_executable).with("/some/path")
18
+ Chrome.driver_path = "/some/path"
19
+
20
+ ChildProcess.should_receive(:build).
21
+ with { |*args| args.first.should == "/some/path" }.
22
+ and_return(mock_process)
23
+
24
+ Service.default_service
25
+ end
26
+
27
+ it "finds the Chrome server binary by searching PATH" do
28
+ Platform.stub(:os => :unix)
29
+ Platform.should_receive(:find_binary).once.and_return("/some/path")
30
+ Platform.should_receive(:assert_executable).with("/some/path")
31
+
32
+ Service.executable_path.should == "/some/path"
33
+ end
34
+
35
+ it "raises a nice error if the server binary can't be found" do
36
+ Platform.stub(:find_binary).and_return(nil)
37
+
38
+ lambda { Service.executable_path }.should raise_error(Error::WebDriverError, /code\.google\.com/)
39
+ end
40
+
41
+ end
42
+ end # Chrome
43
+ end # WebDriver
44
+ end # Selenium
@@ -0,0 +1,41 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ describe Error do
6
+
7
+ context "backwards compatibility" do
8
+ it "aliases StaleElementReferenceError as ObsoleteElementError" do
9
+ lambda {
10
+ raise Error::StaleElementReferenceError
11
+ }.should raise_error(Error::ObsoleteElementError)
12
+ end
13
+
14
+ it "aliases UnknownError as UnhandledError" do
15
+ lambda {
16
+ raise Error::UnknownError
17
+ }.should raise_error(Error::UnhandledError)
18
+ end
19
+
20
+ it "aliases JavascriptError as UnexpectedJavascriptError" do
21
+ lambda {
22
+ raise Error::JavascriptError
23
+ }.should raise_error(Error::UnexpectedJavascriptError)
24
+ end
25
+
26
+ it "aliases NoAlertPresentError as NoAlertOpenError" do
27
+ lambda {
28
+ raise Error::NoAlertPresentError
29
+ }.should raise_error(Error::NoAlertOpenError)
30
+ end
31
+
32
+ it "aliases ElementNotVisibleError as ElementNotDisplayedError" do
33
+ lambda {
34
+ raise Error::ElementNotVisibleError
35
+ }.should raise_error(Error::ElementNotDisplayedError)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module Firefox
7
+
8
+ describe Bridge do
9
+ let(:launcher) { double(Launcher, :launch => nil, :url => "http://localhost:4444/wd/hub") }
10
+ let(:resp) { {"sessionId" => "foo", "value" => @default_capabilities }}
11
+ let(:http) { double(Remote::Http::Default, :call => resp).as_null_object }
12
+ let(:caps) { {} }
13
+
14
+ before do
15
+ @default_capabilities = Remote::Capabilities.firefox.as_json
16
+ Remote::Capabilities.stub(:firefox).and_return(caps)
17
+ Launcher.stub(:new).and_return(launcher)
18
+ end
19
+
20
+ it "sets the proxy capability" do
21
+ proxy = Proxy.new(:http => "localhost:9090")
22
+ caps.should_receive(:proxy=).with proxy
23
+
24
+ Bridge.new(:http_client => http, :proxy => proxy)
25
+ end
26
+
27
+ it "raises ArgumentError if passed invalid options" do
28
+ lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError)
29
+ end
30
+
31
+ it 'takes desired capabilities' do
32
+ custom_caps = Remote::Capabilities.new
33
+ custom_caps['foo'] = 'bar'
34
+
35
+ http.should_receive(:call).with do |_, _, payload|
36
+ payload[:desiredCapabilities]['foo'].should == 'bar'
37
+ resp
38
+ end
39
+
40
+ Bridge.new(:http_client => http, :desired_capabilities => custom_caps)
41
+ end
42
+ end
43
+
44
+ end # Firefox
45
+ end # WebDriver
46
+ end # Selenium
47
+