bbc-selenium-webdriver 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +473 -0
- data/README +31 -0
- data/lib/selenium-client.rb +2 -0
- data/lib/selenium-webdriver.rb +1 -0
- data/lib/selenium/client.rb +37 -0
- data/lib/selenium/client/base.rb +118 -0
- data/lib/selenium/client/driver.rb +10 -0
- data/lib/selenium/client/errors.rb +9 -0
- data/lib/selenium/client/extensions.rb +118 -0
- data/lib/selenium/client/idiomatic.rb +488 -0
- data/lib/selenium/client/javascript_expression_builder.rb +116 -0
- data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
- data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
- data/lib/selenium/client/legacy_driver.rb +1720 -0
- data/lib/selenium/client/protocol.rb +104 -0
- data/lib/selenium/client/selenium_helper.rb +34 -0
- data/lib/selenium/rake/server_task.rb +157 -0
- data/lib/selenium/server.rb +223 -0
- data/lib/selenium/webdriver.rb +64 -0
- data/lib/selenium/webdriver/android.rb +9 -0
- data/lib/selenium/webdriver/android/bridge.rb +51 -0
- data/lib/selenium/webdriver/chrome.rb +26 -0
- data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
- data/lib/selenium/webdriver/chrome/profile.rb +83 -0
- data/lib/selenium/webdriver/chrome/service.rb +74 -0
- data/lib/selenium/webdriver/common.rb +30 -0
- data/lib/selenium/webdriver/common/action_builder.rb +352 -0
- data/lib/selenium/webdriver/common/alert.rb +26 -0
- data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
- data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
- data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
- data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
- data/lib/selenium/webdriver/common/driver.rb +301 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
- data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
- data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
- data/lib/selenium/webdriver/common/element.rb +262 -0
- data/lib/selenium/webdriver/common/error.rb +212 -0
- data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
- data/lib/selenium/webdriver/common/keyboard.rb +52 -0
- data/lib/selenium/webdriver/common/keys.rb +109 -0
- data/lib/selenium/webdriver/common/mouse.rb +65 -0
- data/lib/selenium/webdriver/common/navigation.rb +43 -0
- data/lib/selenium/webdriver/common/options.rb +128 -0
- data/lib/selenium/webdriver/common/platform.rb +166 -0
- data/lib/selenium/webdriver/common/port_prober.rb +25 -0
- data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
- data/lib/selenium/webdriver/common/proxy.rb +120 -0
- data/lib/selenium/webdriver/common/search_context.rb +92 -0
- data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
- data/lib/selenium/webdriver/common/target_locator.rb +81 -0
- data/lib/selenium/webdriver/common/timeouts.rb +29 -0
- data/lib/selenium/webdriver/common/wait.rb +60 -0
- data/lib/selenium/webdriver/common/window.rb +96 -0
- data/lib/selenium/webdriver/common/zipper.rb +82 -0
- data/lib/selenium/webdriver/firefox.rb +37 -0
- data/lib/selenium/webdriver/firefox/binary.rb +161 -0
- data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
- data/lib/selenium/webdriver/firefox/extension.rb +52 -0
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
- data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/profile.rb +315 -0
- data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
- data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
- data/lib/selenium/webdriver/firefox/util.rb +29 -0
- data/lib/selenium/webdriver/ie.rb +19 -0
- data/lib/selenium/webdriver/ie/bridge.rb +60 -0
- data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/server.rb +64 -0
- data/lib/selenium/webdriver/iphone.rb +9 -0
- data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
- data/lib/selenium/webdriver/opera.rb +24 -0
- data/lib/selenium/webdriver/opera/bridge.rb +113 -0
- data/lib/selenium/webdriver/opera/service.rb +49 -0
- data/lib/selenium/webdriver/remote.rb +21 -0
- data/lib/selenium/webdriver/remote/bridge.rb +473 -0
- data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
- data/lib/selenium/webdriver/remote/commands.rb +181 -0
- data/lib/selenium/webdriver/remote/http/common.rb +74 -0
- data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
- data/lib/selenium/webdriver/remote/http/default.rb +102 -0
- data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
- data/lib/selenium/webdriver/remote/response.rb +99 -0
- data/lib/selenium/webdriver/remote/server_error.rb +17 -0
- data/lib/selenium/webdriver/support.rb +4 -0
- data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
- data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
- data/lib/selenium/webdriver/support/select.rb +293 -0
- data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
- data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
- data/spec/integration/selenium/client/api/click_spec.rb +39 -0
- data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
- data/spec/integration/selenium/client/api/element_spec.rb +14 -0
- data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
- data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
- data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
- data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
- data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
- data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
- data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
- data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
- data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
- data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
- data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
- data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
- data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
- data/spec/integration/selenium/client/spec_helper.rb +125 -0
- data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
- data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
- data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
- data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
- data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
- data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
- data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
- data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
- data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
- data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
- data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
- data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
- data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
- data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
- data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
- data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
- data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
- data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
- data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
- data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
- data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
- data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
- data/spec/unit/selenium/client/base_spec.rb +239 -0
- data/spec/unit/selenium/client/extensions_spec.rb +174 -0
- data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
- data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
- data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
- data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
- data/spec/unit/selenium/client/protocol_spec.rb +124 -0
- data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
- data/spec/unit/selenium/client/spec_helper.rb +24 -0
- data/spec/unit/selenium/rake/task_spec.rb +79 -0
- data/spec/unit/selenium/server_spec.rb +131 -0
- data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
- data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
- data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
- data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
- data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
- data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
- data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
- data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
- data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
- data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
- data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
- data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
- data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
- data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
- data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
- data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
- data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
- metadata +215 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
module Remote
|
6
|
+
|
7
|
+
describe Bridge do
|
8
|
+
it "raises ArgumentError if passed invalid options" do
|
9
|
+
lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end # Remote
|
14
|
+
end # WebDriver
|
15
|
+
end # Selenium
|
16
|
+
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
module Remote
|
6
|
+
describe Capabilities do
|
7
|
+
|
8
|
+
it "has default capabilities for Android" do
|
9
|
+
caps = Capabilities.android
|
10
|
+
caps.browser_name.should == "android"
|
11
|
+
caps.platform.should == :android
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has default capabilities for Chrome" do
|
15
|
+
caps = Capabilities.chrome
|
16
|
+
caps.browser_name.should == "chrome"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has default capabilities for Firefox" do
|
20
|
+
caps = Capabilities.firefox
|
21
|
+
caps.browser_name.should == "firefox"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has default capabilities for HtmlUnit" do
|
25
|
+
caps = Capabilities.htmlunit
|
26
|
+
caps.browser_name.should == "htmlunit"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has default capabilities for Internet Explorer" do
|
30
|
+
caps = Capabilities.internet_explorer
|
31
|
+
caps.browser_name.should == "internet explorer"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has default capabilities for iPhone" do
|
35
|
+
caps = Capabilities.iphone
|
36
|
+
caps.browser_name.should == "iPhone"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has default capabilities for iPad" do
|
40
|
+
caps = Capabilities.ipad
|
41
|
+
caps.browser_name.should == "iPad"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has default capabilities for Opera" do
|
45
|
+
caps = Capabilities.opera
|
46
|
+
caps.browser_name.should == "opera"
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
it "should default to no proxy" do
|
51
|
+
Capabilities.new.proxy.should be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can set and get standard capabilities" do
|
55
|
+
caps = Capabilities.new
|
56
|
+
|
57
|
+
caps.browser_name = "foo"
|
58
|
+
caps.browser_name.should == "foo"
|
59
|
+
|
60
|
+
caps.native_events = true
|
61
|
+
caps.native_events.should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can set and get arbitrary capabilities" do
|
65
|
+
caps = Capabilities.chrome
|
66
|
+
caps['chrome'] = :foo
|
67
|
+
caps['chrome'].should == :foo
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set the given proxy" do
|
71
|
+
proxy = Proxy.new
|
72
|
+
capabilities = Capabilities.new(:proxy => proxy)
|
73
|
+
|
74
|
+
capabilities.proxy.should == proxy
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should accept a Hash" do
|
78
|
+
capabilities = Capabilities.new(:proxy => {:http => "foo:123"})
|
79
|
+
capabilities.proxy.http.should == "foo:123"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return a hash of the json properties to serialize" do
|
83
|
+
capabilities_hash = Capabilities.new(:proxy => {:http => "some value"}).as_json
|
84
|
+
proxy_hash = capabilities_hash["proxy"]
|
85
|
+
|
86
|
+
capabilities_hash["proxy"].should be_kind_of(Hash)
|
87
|
+
proxy_hash['httpProxy'].should == "some value"
|
88
|
+
proxy_hash['proxyType'].should == "MANUAL"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not contain proxy hash when no proxy settings" do
|
92
|
+
capabilities_hash = Capabilities.new.as_json
|
93
|
+
capabilities_hash.should_not have_key("proxy")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "can merge capabilities" do
|
97
|
+
a, b = Capabilities.chrome, Capabilities.htmlunit
|
98
|
+
a.merge!(b)
|
99
|
+
|
100
|
+
a.browser_name.should == "htmlunit"
|
101
|
+
a.javascript_enabled.should be_false
|
102
|
+
end
|
103
|
+
|
104
|
+
it "can be serialized and deserialized to JSON" do
|
105
|
+
caps = Capabilities.new(:browser_name => "firefox", :custom_capability => true)
|
106
|
+
caps.should == Capabilities.json_create(caps.as_json)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -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,46 @@
|
|
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
|
+
end
|
41
|
+
|
42
|
+
end # Http
|
43
|
+
end # Remote
|
44
|
+
end # WebDriver
|
45
|
+
end # Selenium
|
46
|
+
|
@@ -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) { mock(:Element)}
|
15
|
+
let(:bridge) { mock(: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) { mock 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.should_receive(:new).any_number_of_times.and_return socket
|
21
|
+
states.each { |state|
|
22
|
+
socket.should_receive(:connect_nonblock).
|
23
|
+
and_raise(state ? Errno::EISCONN : Errno::ECONNREFUSED)
|
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
|
+
Time.should_receive(:now).and_return(start, wait, stop)
|
61
|
+
|
62
|
+
poller.should_not be_closed
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -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) { mock(Remote::Bridge, :driver_extensions => []) }
|
9
|
+
let(:listener) { mock("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
|