browserstack-webdriver 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +791 -0
- data/README.md +31 -0
- data/build.desc +334 -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 +132 -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 +248 -0
- data/lib/selenium/webdriver.rb +71 -0
- data/lib/selenium/webdriver/android.rb +9 -0
- data/lib/selenium/webdriver/android/bridge.rb +47 -0
- data/lib/selenium/webdriver/chrome.rb +26 -0
- data/lib/selenium/webdriver/chrome/bridge.rb +120 -0
- data/lib/selenium/webdriver/chrome/profile.rb +90 -0
- data/lib/selenium/webdriver/chrome/service.rb +75 -0
- data/lib/selenium/webdriver/common.rb +44 -0
- data/lib/selenium/webdriver/common/action_builder.rb +352 -0
- data/lib/selenium/webdriver/common/alert.rb +30 -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_browser_connection.rb +17 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +25 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +13 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +22 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +19 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +22 -0
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +45 -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 +293 -0
- data/lib/selenium/webdriver/common/error.rb +207 -0
- data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
- data/lib/selenium/webdriver/common/html5/local_storage.rb +42 -0
- data/lib/selenium/webdriver/common/html5/location.rb +0 -0
- data/lib/selenium/webdriver/common/html5/session_storage.rb +44 -0
- data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +42 -0
- data/lib/selenium/webdriver/common/json_helper.rb +34 -0
- data/lib/selenium/webdriver/common/keyboard.rb +55 -0
- data/lib/selenium/webdriver/common/keys.rb +109 -0
- data/lib/selenium/webdriver/common/log_entry.rb +29 -0
- data/lib/selenium/webdriver/common/logs.rb +23 -0
- data/lib/selenium/webdriver/common/mouse.rb +72 -0
- data/lib/selenium/webdriver/common/navigation.rb +43 -0
- data/lib/selenium/webdriver/common/options.rb +136 -0
- data/lib/selenium/webdriver/common/platform.rb +218 -0
- data/lib/selenium/webdriver/common/port_prober.rb +42 -0
- data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
- data/lib/selenium/webdriver/common/proxy.rb +149 -0
- data/lib/selenium/webdriver/common/search_context.rb +92 -0
- data/lib/selenium/webdriver/common/socket_poller.rb +105 -0
- data/lib/selenium/webdriver/common/target_locator.rb +81 -0
- data/lib/selenium/webdriver/common/timeouts.rb +38 -0
- data/lib/selenium/webdriver/common/touch_action_builder.rb +64 -0
- data/lib/selenium/webdriver/common/touch_screen.rb +105 -0
- data/lib/selenium/webdriver/common/wait.rb +63 -0
- data/lib/selenium/webdriver/common/window.rb +104 -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 +158 -0
- data/lib/selenium/webdriver/firefox/bridge.rb +70 -0
- data/lib/selenium/webdriver/firefox/extension.rb +52 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +106 -0
- data/lib/selenium/webdriver/firefox/profile.rb +263 -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 +68 -0
- data/lib/selenium/webdriver/ie/server.rb +86 -0
- data/lib/selenium/webdriver/iphone.rb +9 -0
- data/lib/selenium/webdriver/iphone/bridge.rb +45 -0
- data/lib/selenium/webdriver/opera.rb +24 -0
- data/lib/selenium/webdriver/opera/bridge.rb +112 -0
- data/lib/selenium/webdriver/opera/service.rb +49 -0
- data/lib/selenium/webdriver/phantomjs.rb +22 -0
- data/lib/selenium/webdriver/phantomjs/bridge.rb +59 -0
- data/lib/selenium/webdriver/phantomjs/service.rb +90 -0
- data/lib/selenium/webdriver/remote.rb +22 -0
- data/lib/selenium/webdriver/remote/bridge.rb +644 -0
- data/lib/selenium/webdriver/remote/capabilities.rb +267 -0
- data/lib/selenium/webdriver/remote/commands.rb +193 -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 +139 -0
- data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
- data/lib/selenium/webdriver/remote/response.rb +97 -0
- data/lib/selenium/webdriver/remote/server_error.rb +17 -0
- data/lib/selenium/webdriver/safari.rb +46 -0
- data/lib/selenium/webdriver/safari/bridge.rb +110 -0
- data/lib/selenium/webdriver/safari/browser.rb +20 -0
- data/lib/selenium/webdriver/safari/extension.rb +120 -0
- data/lib/selenium/webdriver/safari/server.rb +145 -0
- data/lib/selenium/webdriver/support.rb +5 -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/color.rb +110 -0
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
- data/lib/selenium/webdriver/support/select.rb +293 -0
- data/ruby.iml +13 -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 +31 -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/api/webdriver_backed_spec.rb +21 -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 +139 -0
- data/spec/integration/selenium/webdriver/app_cache_spec.rb +47 -0
- data/spec/integration/selenium/webdriver/browser_connection_spec.rb +20 -0
- data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
- data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +63 -0
- data/spec/integration/selenium/webdriver/driver_spec.rb +266 -0
- data/spec/integration/selenium/webdriver/element_spec.rb +191 -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/location_spec.rb +29 -0
- data/spec/integration/selenium/webdriver/mouse_spec.rb +57 -0
- data/spec/integration/selenium/webdriver/navigation_spec.rb +46 -0
- data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
- data/spec/integration/selenium/webdriver/options_spec.rb +77 -0
- data/spec/integration/selenium/webdriver/remote/driver_spec.rb +19 -0
- data/spec/integration/selenium/webdriver/remote/element_spec.rb +26 -0
- data/spec/integration/selenium/webdriver/spec_helper.rb +36 -0
- data/spec/integration/selenium/webdriver/spec_support.rb +12 -0
- data/spec/integration/selenium/webdriver/spec_support/guards.rb +110 -0
- data/spec/integration/selenium/webdriver/spec_support/helpers.rb +51 -0
- data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
- data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +239 -0
- data/spec/integration/selenium/webdriver/sql_database_spec.rb +59 -0
- data/spec/integration/selenium/webdriver/storage_spec.rb +96 -0
- data/spec/integration/selenium/webdriver/target_locator_spec.rb +186 -0
- data/spec/integration/selenium/webdriver/timeout_spec.rb +69 -0
- data/spec/integration/selenium/webdriver/touch_spec.rb +176 -0
- data/spec/integration/selenium/webdriver/window_spec.rb +70 -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 +150 -0
- data/spec/unit/selenium/webdriver/action_builder_spec.rb +97 -0
- data/spec/unit/selenium/webdriver/android/bridge_spec.rb +43 -0
- data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +137 -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 +47 -0
- data/spec/unit/selenium/webdriver/ie/bridge_spec.rb +91 -0
- data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +42 -0
- data/spec/unit/selenium/webdriver/log_entry_spec.rb +11 -0
- data/spec/unit/selenium/webdriver/opera/bridge_spec.rb +44 -0
- data/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb +55 -0
- data/spec/unit/selenium/webdriver/proxy_spec.rb +106 -0
- data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
- data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +115 -0
- data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
- data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +124 -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 +27 -0
- data/spec/unit/selenium/webdriver/support/color_spec.rb +119 -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 +49 -0
- 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
|