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,79 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Selenium::Client::JavascriptExpressionBuilder do
|
4
|
+
def builder(*args)
|
5
|
+
@builder ||= Selenium::Client::JavascriptExpressionBuilder.new(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "can append arbitrary text to builder" do
|
9
|
+
builder.append("hello").append(" world")
|
10
|
+
builder.script.should == "hello world"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the correct #no_pending_ajax_requests script for Prototype" do
|
14
|
+
builder = builder(:prototype)
|
15
|
+
builder.no_pending_ajax_requests.script.should == "selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns the correct #no_pending_ajax_requests script for jQuery" do
|
19
|
+
builder = builder(:jquery)
|
20
|
+
builder.no_pending_ajax_requests.script.should == "selenium.browserbot.getCurrentWindow().jQuery.active == 0;"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the correct #no_pending_effects for Prototype" do
|
24
|
+
builder = builder(:prototype)
|
25
|
+
builder.no_pending_effects.script.should == "selenium.browserbot.getCurrentWindow().Effect.Queue.size() == 0;"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#quote_escaped" do
|
29
|
+
it "returns a locator as is when it has no single quotes" do
|
30
|
+
builder.quote_escaped("the_locator").should == "the_locator"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "escapes single quotes" do
|
34
|
+
builder.quote_escaped("//div[@id='demo-effect-appear']").should == "//div[@id=\\'demo-effect-appear\\']"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "escapes backslashes" do
|
38
|
+
builder.quote_escaped("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/").should == "webratlink=evalregex:/Pastry Lovers \\\\(Organizer\\\\)/"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#text_match" do
|
43
|
+
it "matches on entire string when pattern is a string" do
|
44
|
+
builder.text_match("some text").should == "element.innerHTML == 'some text'"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "performs a regexp match when pattern is a regexp" do
|
48
|
+
builder.text_match(/some text/).should == "null != element.innerHTML.match(/some text/)"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "escapes rexpexp when pattern is a regexp" do
|
52
|
+
builder.text_match(/some.*text/).should == "null != element.innerHTML.match(/some.*text/)"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#find_element" do
|
57
|
+
it "adds a script to find an element" do
|
58
|
+
builder.find_element('a_locator').script.should =~ /element\s+=\s+selenium.browserbot.findElement\('a_locator'\);/m
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should handle embedded evalregex locators" do
|
62
|
+
builder.find_element("webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/").script.should =~ /element\s+=\s+selenium.browserbot.findElement\('webratlink=evalregex:\/Pastry Lovers \\\\\(Organizer\\\\\)\/'\);/m
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#javascript_framework_for" do
|
67
|
+
it "returns JavascriptFrameworks::Prototype when argument is :prototype" do
|
68
|
+
builder.javascript_framework_for(:prototype).should == Selenium::Client::JavascriptFrameworks::Prototype
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns JavascriptFrameworks::JQuery when argument is :jquery" do
|
72
|
+
builder.javascript_framework_for(:jquery).should == Selenium::Client::JavascriptFrameworks::JQuery
|
73
|
+
end
|
74
|
+
|
75
|
+
it "raises a Runtime for unsupported frameworks" do
|
76
|
+
lambda { builder.javascript_framework_for(:unsupported_framework) }.should raise_error(RuntimeError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Selenium::Client::JavascriptFrameworks::JQuery do
|
4
|
+
|
5
|
+
it "returns 'jQuery.active'" do
|
6
|
+
art = Selenium::Client::JavascriptFrameworks::JQuery.ajax_request_tracker
|
7
|
+
art.should == "jQuery.active"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Selenium::Client::JavascriptFrameworks::Prototype do
|
4
|
+
|
5
|
+
it "returns 'Ajax.activeRequestCount'" do
|
6
|
+
art = Selenium::Client::JavascriptFrameworks::Prototype.ajax_request_tracker
|
7
|
+
art.should == "Ajax.activeRequestCount"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Selenium::Client::Protocol do
|
4
|
+
class ProtocolClient
|
5
|
+
include Selenium::Client::Protocol
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:client) { ProtocolClient.new }
|
9
|
+
|
10
|
+
describe "#remote_control_command" do
|
11
|
+
it "returns the content of the HTTP response when the command succeeds" do
|
12
|
+
client.instance_variable_set :@default_timeout_in_seconds, 1
|
13
|
+
client.stub!(:http_request_for).with(:a_verb, :some_args).and_return(:the_request)
|
14
|
+
client.should_receive(:http_post).with(:the_request).and_return(["OK", "OK,the response"])
|
15
|
+
client.remote_control_command(:a_verb, :some_args).should == "the response"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises a SeleniumCommandError when the command fails" do
|
19
|
+
client.instance_variable_set :@default_timeout_in_seconds, 1
|
20
|
+
client.stub!(:http_request_for).with(:a_verb, :some_args).and_return(:the_request)
|
21
|
+
client.should_receive(:http_post).with(:the_request).and_return(["ER", "ERROR,the error message"])
|
22
|
+
lambda { client.remote_control_command(:a_verb, :some_args) }.should raise_error(Selenium::Client::CommandError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "succeeds when given zero args" do
|
26
|
+
client.instance_variable_set :@default_timeout_in_seconds, 1
|
27
|
+
client.should_receive(:http_request_for).with(:a_verb, []).and_return(:the_request)
|
28
|
+
client.stub!(:http_post).with(:the_request).and_return(["OK", "OK,the response"])
|
29
|
+
client.remote_control_command(:a_verb)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#string_command" do
|
34
|
+
it "returns the selenese command response" do
|
35
|
+
client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return("A String")
|
36
|
+
client.string_command(:a_verb, :some_args).should == "A String"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "succeeds when given zero args" do
|
40
|
+
client.should_receive(:remote_control_command).with(:a_verb, [])
|
41
|
+
client.string_command:a_verb
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#get_string" do # private?
|
46
|
+
it "parses the command response as a CSV row" do
|
47
|
+
client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return("One,Two,Three")
|
48
|
+
client.string_array_command(:a_verb, :some_args).should == ["One", "Two", "Three"]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "preserves spaces" do
|
52
|
+
client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return(" One , Two & Three ")
|
53
|
+
client.string_array_command(:a_verb, :some_args).should == [" One ", " Two & Three "]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "ignores commas escaped with a backspace" do
|
57
|
+
client.should_receive(:remote_control_command).with(:a_verb, :some_args).and_return("One,Two\\,Three")
|
58
|
+
client.string_array_command(:a_verb, :some_args).should == ["One", "Two,Three"]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "parse_boolean_value" do
|
63
|
+
it "returns true when string is true" do
|
64
|
+
client.send(:parse_boolean_value, "true").should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns false when string is false" do
|
68
|
+
client.send(:parse_boolean_value, "false").should == false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "parse_boolean_value raise a ProtocolError when string is neither true nor false" do
|
72
|
+
lambda {
|
73
|
+
client.send(:parse_boolean_value, "unexpected")
|
74
|
+
}.should raise_error(Selenium::Client::ProtocolError, "Invalid Selenese boolean value that is neither 'true' nor 'false': got 'unexpected'")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#boolean_command or #boolean_array_command" do
|
79
|
+
it "returns true when string_command returns 'true'" do
|
80
|
+
client.stub!(:string_command).with(:a_verb, :some_args).and_return("true")
|
81
|
+
client.boolean_command(:a_verb, :some_args).should == true
|
82
|
+
end
|
83
|
+
|
84
|
+
it "succeeds when given zero args" do
|
85
|
+
client.should_receive(:string_command).with(:a_verb, []).and_return("true")
|
86
|
+
client.boolean_command(:a_verb)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns false when string_command returns 'false'" do
|
90
|
+
client.stub!(:string_command).with(:a_verb, :some_args).and_return("false")
|
91
|
+
client.boolean_command(:a_verb, :some_args).should == false
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns an array of evaluated boolean values" do
|
95
|
+
client.stub!(:string_array_command).with(:a_verb, :some_args).
|
96
|
+
and_return(["true", "false", "true", "true", "false"])
|
97
|
+
|
98
|
+
client.boolean_array_command(:a_verb, :some_args).should == [true, false, true, true, false]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#http_request_for" do
|
103
|
+
it "returns cmd=verb for a verb" do
|
104
|
+
client.send(:http_request_for, "aCommand", []).should == "cmd=aCommand"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "escapes the command" do
|
108
|
+
client.send(:http_request_for, "a Command & More", []).should == "cmd=a+Command+%26+More"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "adds a session_id parameter when client has a current session id" do
|
112
|
+
client.stub!(:session_id).and_return(24)
|
113
|
+
client.send(:http_request_for, "aCommand", []).should == "cmd=aCommand&sessionId=24"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "sets args as parameters whose key is their index" do
|
117
|
+
client.send(:http_request_for, "aCommand", [24, "foo", true]).should == "cmd=aCommand&1=24&2=foo&3=true"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "escapes arg values" do
|
121
|
+
client.send(:http_request_for, "aCommand", [ "This & That" ]).should == "cmd=aCommand&1=This+%26+That"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Selenium::Client::SeleniumHelper do
|
4
|
+
class SeleniumHelperClass
|
5
|
+
include Selenium::Client::SeleniumHelper
|
6
|
+
attr_accessor :selenium
|
7
|
+
end
|
8
|
+
|
9
|
+
let :object do
|
10
|
+
@object ||= (
|
11
|
+
o = SeleniumHelperClass.new
|
12
|
+
o.selenium = mock("selenium")
|
13
|
+
|
14
|
+
o
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "delegates open to @selenium" do
|
19
|
+
object.selenium.should_receive(:open).with(:the_url).and_return(:the_result)
|
20
|
+
|
21
|
+
object.open(:the_url).should == :the_result
|
22
|
+
end
|
23
|
+
|
24
|
+
it "delegates type to @selenium" do
|
25
|
+
object.selenium.should_receive(:type).with(:the_locator, :the_value) \
|
26
|
+
.and_return(:the_result)
|
27
|
+
|
28
|
+
object.type(:the_locator, :the_value).should == :the_result
|
29
|
+
end
|
30
|
+
|
31
|
+
it "delegates select to @selenium" do
|
32
|
+
object.selenium.should_receive(:type).with(:the_input_locator,
|
33
|
+
:the_option_locator) \
|
34
|
+
.and_return(:the_result)
|
35
|
+
|
36
|
+
object.type(:the_input_locator, :the_option_locator).should == :the_result
|
37
|
+
end
|
38
|
+
|
39
|
+
it "delegates to any no-arg method defined on @selenium" do
|
40
|
+
object.selenium.should_receive(:a_noarg_method).with().and_return(:the_result)
|
41
|
+
|
42
|
+
object.a_noarg_method.should == :the_result
|
43
|
+
end
|
44
|
+
|
45
|
+
it "delegates to any arg method defined on @selenium" do
|
46
|
+
object.selenium.should_receive(:a_method).with(:alpha, :beta)\
|
47
|
+
.and_return(:the_result)
|
48
|
+
|
49
|
+
object.a_method(:alpha, :beta).should == :the_result
|
50
|
+
end
|
51
|
+
|
52
|
+
it "calls default method_missing when a method is not defined on @selenium" do
|
53
|
+
lambda { object.a_method(:alpha, :beta) }.should raise_error(NoMethodError)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'selenium-client'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
# for bamboo
|
5
|
+
require 'ci/reporter/rspec'
|
6
|
+
|
7
|
+
module SeleniumClientSpecHelper
|
8
|
+
def capture_stderr(&blk)
|
9
|
+
io = StringIO.new
|
10
|
+
orig, $stderr = $stderr, io
|
11
|
+
|
12
|
+
begin
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
$stderr = orig
|
16
|
+
end
|
17
|
+
|
18
|
+
io.string
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.include(SeleniumClientSpecHelper)
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path("../../webdriver/spec_helper", __FILE__)
|
2
|
+
require 'selenium/rake/server_task'
|
3
|
+
|
4
|
+
describe Selenium::Rake::ServerTask do
|
5
|
+
let(:mock_server) { mock(Selenium::Server).as_null_object }
|
6
|
+
|
7
|
+
it "raises an error if no jar file is specified" do
|
8
|
+
lambda {
|
9
|
+
Selenium::Rake::ServerTask.new
|
10
|
+
}.should raise_error(Selenium::Rake::MissingJarFileError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "launches the server with default options" do
|
14
|
+
expected_opts = {
|
15
|
+
:port => 4444,
|
16
|
+
:timeout => 30,
|
17
|
+
:background => true,
|
18
|
+
:log => true,
|
19
|
+
}
|
20
|
+
|
21
|
+
Selenium::Server.should_receive(:new).
|
22
|
+
with("selenium-server.jar", expected_opts).
|
23
|
+
and_return(mock_server)
|
24
|
+
|
25
|
+
task = Selenium::Rake::ServerTask.new { |t| t.jar = "selenium-server.jar" }
|
26
|
+
|
27
|
+
task.port.should == 4444
|
28
|
+
task.timeout.should == 30
|
29
|
+
task.background.should be_true
|
30
|
+
task.log.should be_true
|
31
|
+
task.opts.should == []
|
32
|
+
end
|
33
|
+
|
34
|
+
it "lets the user override the default options" do
|
35
|
+
expected_opts = {
|
36
|
+
:port => 5555,
|
37
|
+
:timeout => 120,
|
38
|
+
:background => false,
|
39
|
+
:log => false,
|
40
|
+
}
|
41
|
+
|
42
|
+
Selenium::Server.should_receive(:new).
|
43
|
+
with("selenium-server.jar", expected_opts).
|
44
|
+
and_return(mock_server)
|
45
|
+
|
46
|
+
task = Selenium::Rake::ServerTask.new { |t|
|
47
|
+
t.jar = "selenium-server.jar"
|
48
|
+
t.port = 5555
|
49
|
+
t.timeout = 120
|
50
|
+
t.background = false
|
51
|
+
t.log = false
|
52
|
+
|
53
|
+
t.opts << "-some" << "args"
|
54
|
+
}
|
55
|
+
|
56
|
+
task.port.should == 5555
|
57
|
+
task.timeout.should == 120
|
58
|
+
task.background.should be_false
|
59
|
+
task.log.should be_false
|
60
|
+
task.opts.should == ["-some", "args"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "lets the user specify a version to use which it will automatically download" do
|
64
|
+
required_version = '10.2.0'
|
65
|
+
jar_file = "selenium-server-standalone-#{required_version}.jar"
|
66
|
+
|
67
|
+
Selenium::Server.should_receive(:new).
|
68
|
+
with(jar_file, anything()).
|
69
|
+
and_return(mock_server)
|
70
|
+
|
71
|
+
Selenium::Server.should_receive(:download).
|
72
|
+
with(required_version).
|
73
|
+
and_return(jar_file)
|
74
|
+
|
75
|
+
Selenium::Rake::ServerTask.new { |t| t.version = required_version }
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.expand_path('../webdriver/spec_helper', __FILE__)
|
2
|
+
require 'selenium/server'
|
3
|
+
|
4
|
+
describe Selenium::Server do
|
5
|
+
let(:mock_process) { mock(ChildProcess).as_null_object }
|
6
|
+
let(:mock_poller) { mock("SocketPoller", :connected? => true, :closed? => true)}
|
7
|
+
|
8
|
+
it "raises an error if the jar file does not exist" do
|
9
|
+
lambda {
|
10
|
+
Selenium::Server.new("doesnt-exist.jar")
|
11
|
+
}.should raise_error(Errno::ENOENT)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "uses the given jar file and port" do
|
15
|
+
File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true)
|
16
|
+
|
17
|
+
ChildProcess.should_receive(:build).
|
18
|
+
with("java", "-jar", "selenium-server-test.jar", "-port", "1234").
|
19
|
+
and_return(mock_process)
|
20
|
+
|
21
|
+
server = Selenium::Server.new("selenium-server-test.jar", :port => 1234, :background => true)
|
22
|
+
server.stub!(:socket).and_return(mock_poller)
|
23
|
+
|
24
|
+
server.start
|
25
|
+
end
|
26
|
+
|
27
|
+
it "waits for the server process by default" do
|
28
|
+
File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true)
|
29
|
+
|
30
|
+
ChildProcess.should_receive(:build).
|
31
|
+
with("java", "-jar", "selenium-server-test.jar", "-port", "4444").
|
32
|
+
and_return(mock_process)
|
33
|
+
|
34
|
+
server = Selenium::Server.new("selenium-server-test.jar")
|
35
|
+
server.stub!(:socket).and_return(mock_poller)
|
36
|
+
|
37
|
+
mock_process.should_receive(:wait)
|
38
|
+
server.start
|
39
|
+
end
|
40
|
+
|
41
|
+
it "adds additional args" do
|
42
|
+
File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true)
|
43
|
+
|
44
|
+
ChildProcess.should_receive(:build).
|
45
|
+
with("java", "-jar", "selenium-server-test.jar", "-port", "4444", "foo", "bar").
|
46
|
+
and_return(mock_process)
|
47
|
+
|
48
|
+
server = Selenium::Server.new("selenium-server-test.jar", :background => true)
|
49
|
+
server.stub!(:socket).and_return(mock_poller)
|
50
|
+
|
51
|
+
server << ["foo", "bar"]
|
52
|
+
|
53
|
+
server.start
|
54
|
+
end
|
55
|
+
|
56
|
+
it "downloads the specified version from the selenium site" do
|
57
|
+
required_version = '10.2.0'
|
58
|
+
expected_download_file_name = "selenium-server-standalone-#{required_version}.jar"
|
59
|
+
|
60
|
+
stub_request(:get, "http://selenium.googlecode.com/files/#{expected_download_file_name}").to_return(:body => "this is pretending to be a jar file for testing purposes")
|
61
|
+
|
62
|
+
begin
|
63
|
+
actual_download_file_name = Selenium::Server.download(required_version)
|
64
|
+
actual_download_file_name.should == expected_download_file_name
|
65
|
+
File.should exist(expected_download_file_name)
|
66
|
+
ensure
|
67
|
+
FileUtils.rm_rf expected_download_file_name
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "gets a server instance and downloads the specified version" do
|
72
|
+
required_version = '10.4.0'
|
73
|
+
expected_download_file_name = "selenium-server-standalone-#{required_version}.jar"
|
74
|
+
expected_options = {:port => 5555}
|
75
|
+
fake_server = Object.new
|
76
|
+
|
77
|
+
Selenium::Server.should_receive(:download).with(required_version).and_return(expected_download_file_name)
|
78
|
+
Selenium::Server.should_receive(:new).with(expected_download_file_name, expected_options).and_return(fake_server)
|
79
|
+
server = Selenium::Server.get required_version, expected_options
|
80
|
+
server.should == fake_server
|
81
|
+
end
|
82
|
+
|
83
|
+
it "automatically repairs http_proxy settings that do not start with http://" do
|
84
|
+
ENV['http_proxy'] = 'proxy.com'
|
85
|
+
Selenium::Server.net_http.proxy_address.should == 'proxy.com'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "only downloads a jar if it is not present in the current directory" do
|
89
|
+
required_version = '10.2.0'
|
90
|
+
expected_download_file_name = "selenium-server-standalone-#{required_version}.jar"
|
91
|
+
|
92
|
+
File.should_receive(:exists?).with(expected_download_file_name).and_return true
|
93
|
+
|
94
|
+
Selenium::Server.download required_version
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should know what the latest version available is" do
|
98
|
+
latest_version = '10.2.0'
|
99
|
+
stub_request(:get, "http://code.google.com/p/selenium/downloads/list").to_return(:body => "web page containing jar selenium-server-standalone-#{latest_version}.jar")
|
100
|
+
|
101
|
+
Selenium::Server.latest.should == latest_version
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should download the latest version if that has been specified" do
|
105
|
+
required_version = '10.6.0'
|
106
|
+
expected_download_file_name = "selenium-server-standalone-#{required_version}.jar"
|
107
|
+
|
108
|
+
Selenium::Server.should_receive(:latest).and_return required_version
|
109
|
+
stub_request(:get, "http://selenium.googlecode.com/files/#{expected_download_file_name}").to_return(:body => "this is pretending to be a jar file for testing purposes")
|
110
|
+
|
111
|
+
begin
|
112
|
+
actual_download_file_name = Selenium::Server.download(:latest)
|
113
|
+
actual_download_file_name.should == expected_download_file_name
|
114
|
+
File.should exist(expected_download_file_name)
|
115
|
+
ensure
|
116
|
+
FileUtils.rm_rf expected_download_file_name
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "raises Selenium::Server::Error if the server is not launched within the timeout" do
|
121
|
+
File.should_receive(:exist?).with("selenium-server-test.jar").and_return(true)
|
122
|
+
|
123
|
+
poller = mock('SocketPoller')
|
124
|
+
poller.should_receive(:connected?).and_return(false)
|
125
|
+
|
126
|
+
server = Selenium::Server.new("selenium-server-test.jar", :background => true)
|
127
|
+
server.stub!(:socket).and_return(poller)
|
128
|
+
|
129
|
+
lambda { server.start }.should raise_error(Selenium::Server::Error)
|
130
|
+
end
|
131
|
+
end
|