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,90 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe Selenium::WebDriver::ActionBuilder do
4
+ let(:bridge) { mock("Bridge").as_null_object }
5
+ let(:keyboard) { mock(Selenium::WebDriver::Keyboard) }
6
+ let(:mouse) { mock(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
+ end
@@ -0,0 +1,31 @@
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) { mock(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
+ end
27
+
28
+ end # IPhone
29
+ end # WebDriver
30
+ end # Selenium
31
+
@@ -0,0 +1,94 @@
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) { mock(Service, :start => true, :uri => "http://example.com") }
11
+ let(:caps) { {} }
12
+ let(:http) { mock(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 "lets the user override chrome.detach" do
57
+ Bridge.new(:http_client => http, :detach => false)
58
+
59
+ caps['chromeOptions']['detach'].should be_false
60
+ caps['chrome.detach'].should be_false
61
+ end
62
+
63
+ it "uses the user-provided server URL if given" do
64
+ Service.should_not_receive(:default_service)
65
+ http.should_receive(:server_url=).with(URI.parse("http://example.com"))
66
+
67
+ Bridge.new(:http_client => http, :url => "http://example.com")
68
+ end
69
+
70
+ it "raises an ArgumentError if args is not an Array" do
71
+ lambda { Bridge.new(:args => "--foo=bar")}.should raise_error(ArgumentError)
72
+ end
73
+
74
+ it "uses the given profile" do
75
+ profile = Profile.new
76
+
77
+ profile['some_pref'] = true
78
+ profile.add_extension(__FILE__)
79
+
80
+ Bridge.new(:http_client => http, :profile => profile)
81
+
82
+ profile_data = profile.as_json
83
+ caps['chromeOptions']['profile'].should == profile_data['zip']
84
+ caps['chromeOptions']['extensions'].should == profile_data['extensions']
85
+
86
+ caps['chrome.profile'].should == profile_data['zip']
87
+ caps['chrome.extensions'].should == profile_data['extensions']
88
+ end
89
+ end
90
+
91
+ end # Chrome
92
+ end # WebDriver
93
+ end # Selenium
94
+
@@ -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 = MultiJson.decode(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
+ mock("ChildProcess", :io => mock.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,17 @@
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
+ it "raises ArgumentError if passed invalid options" do
10
+ lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError)
11
+ end
12
+ end
13
+
14
+ end # Firefox
15
+ end # WebDriver
16
+ end # Selenium
17
+
@@ -0,0 +1,30 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module IPhone
7
+ describe Bridge do
8
+ let(:default_url) { URI.parse(IPhone::Bridge::DEFAULT_URL) }
9
+ let(:resp) { {"sessionId" => "foo", "value" => Remote::Capabilities.iphone.as_json }}
10
+ let(:http) { mock(Remote::Http::Default, :call => resp).as_null_object }
11
+
12
+ it "uses the default iPhone 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
+ end
27
+
28
+ end # IPhone
29
+ end # WebDriver
30
+ end # Selenium
@@ -0,0 +1,87 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ describe Proxy do
6
+ let :proxy_settings do
7
+ {
8
+ :ftp => "mythicalftpproxy:21",
9
+ :http => "mythicalproxy:80",
10
+ :no_proxy => "noproxy",
11
+ :ssl => "mythicalsslproxy",
12
+ }
13
+ end
14
+
15
+ it "raises ArgumentError if passed invalid options" do
16
+ lambda { Proxy.new(:invalid_options => 'invalid') }.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it "raises ArgumentError if passed an invalid proxy type" do
20
+ lambda { Proxy.new(:type => :invalid) }.should raise_error(ArgumentError)
21
+ end
22
+
23
+ it "raises ArgumentError if the proxy type is changed" do
24
+ proxy = Proxy.new(:type => :manual)
25
+ lambda { proxy.type = :pac }.should raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should allow valid options for a manual proxy" do
29
+ proxy = Proxy.new(proxy_settings)
30
+
31
+ proxy.ftp.should == proxy_settings[:ftp]
32
+ proxy.http.should == proxy_settings[:http]
33
+ proxy.no_proxy.should == proxy_settings[:no_proxy]
34
+ proxy.ssl.should == proxy_settings[:ssl]
35
+ end
36
+
37
+ it "should return a hash of the json properties to serialize" do
38
+ proxy_json = Proxy.new(proxy_settings).as_json
39
+
40
+ proxy_json['proxyType'].should == "MANUAL"
41
+ proxy_json['ftpProxy'].should == proxy_settings[:ftp]
42
+ proxy_json['httpProxy'].should == proxy_settings[:http]
43
+ proxy_json['noProxy'].should == proxy_settings[:no_proxy]
44
+ proxy_json['sslProxy'].should == proxy_settings[:ssl]
45
+ end
46
+
47
+ it "should configure a PAC proxy" do
48
+ proxy_json = Proxy.new(:pac => "http://example.com/foo.pac").as_json
49
+
50
+ proxy_json['proxyType'].should == "PAC"
51
+ proxy_json['proxyAutoconfigUrl'].should == "http://example.com/foo.pac"
52
+ end
53
+
54
+ it "should configure an auto-detected proxy" do
55
+ proxy_json = Proxy.new(:auto_detect => true).as_json
56
+
57
+ proxy_json['proxyType'].should == "AUTODETECT"
58
+ proxy_json['autodetect'].should be_true
59
+ end
60
+
61
+ it "should only add settings that are not nil" do
62
+ settings = {:type => :manual, :http => "http proxy"}
63
+
64
+ proxy = Proxy.new(settings)
65
+ proxy_json = proxy.as_json
66
+
67
+ proxy_json.delete('proxyType').should == settings[:type].to_s.upcase
68
+ proxy_json.delete('httpProxy').should == settings[:http]
69
+
70
+ proxy_json.should be_empty
71
+ end
72
+
73
+ it "returns a JSON string" do
74
+ proxy = Proxy.new(proxy_settings)
75
+ proxy.to_json.should be_kind_of(String)
76
+ end
77
+
78
+ it "can be serialized and deserialized" do
79
+ proxy = Proxy.new(proxy_settings)
80
+ other = Proxy.json_create(proxy.as_json)
81
+
82
+ proxy.should == other
83
+ end
84
+
85
+ end
86
+ end
87
+ end