browserstack-webdriver 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,59 @@
|
|
|
1
|
+
<htmL>
|
|
2
|
+
<head>
|
|
3
|
+
<title>Prototype - Selenium Ruby Client Sample App</title>
|
|
4
|
+
<script type="application/x-javascript" src="/prototype-1.6.0.3.js"></script>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<h1 id="title">Prototype - Selenium Ruby Client Sample App</h1>
|
|
8
|
+
|
|
9
|
+
<div id="element-present-demo">
|
|
10
|
+
<h2>Element / Text Present</h2>
|
|
11
|
+
<input type="button" id="create-element-button" value="Create Mojo" />
|
|
12
|
+
<input type="button" id="delete-element-button" value="Destroy Mojo" />
|
|
13
|
+
|
|
14
|
+
<script type="text/javascript" language="javascript">
|
|
15
|
+
Event.observe(window, 'load', function() {
|
|
16
|
+
|
|
17
|
+
Event.observe('create-element-button', 'click', function (event) {
|
|
18
|
+
$('element-present-demo').insert('<div id="new-element">We All Need ' + 'Some Mojo</div>');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
Event.observe('delete-element-button', 'click', function (event) {
|
|
22
|
+
$('new-element').remove();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
</script>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<div id="regexp-support">
|
|
29
|
+
<div id="dangerous-characters">There are some dangerous characters here: ' / \</div>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<div id="ajax-demo">
|
|
33
|
+
<h2>AJAX Calculator</h2>
|
|
34
|
+
<form id="calculator-form" action="#" method="post" onSubmit="return false;">
|
|
35
|
+
<input id="calculator-expression" name="calculator-expression"/>
|
|
36
|
+
<input type="submit" id="calculator-button" value="Compute" />
|
|
37
|
+
<br/><br/>
|
|
38
|
+
<div>Result: <input id="calculator-result" disabled /></div>
|
|
39
|
+
</form>
|
|
40
|
+
|
|
41
|
+
<script type="text/javascript" language="javascript">
|
|
42
|
+
Event.observe(window, 'load', function() {
|
|
43
|
+
|
|
44
|
+
Event.observe('calculator-button', 'click', function (event) {
|
|
45
|
+
new Ajax.Request('/compute', {
|
|
46
|
+
method: 'post',
|
|
47
|
+
parameters: $('calculator-form').serialize(true),
|
|
48
|
+
onSuccess: function(transport) {
|
|
49
|
+
$('calculator-result').value = transport.responseText;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return false;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
</body>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rack'
|
|
3
|
+
require 'webrick'
|
|
4
|
+
|
|
5
|
+
# TODO: Use Selenium::WebDriver::SpecSupport::RackServer?
|
|
6
|
+
class SampleApp
|
|
7
|
+
|
|
8
|
+
def self.start(host, port)
|
|
9
|
+
Rack::Handler::WEBrick.run(new, :Host => host, :Port => port)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@public = Rack::File.new(File.expand_path("../public", __FILE__))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def call(env)
|
|
17
|
+
req = Rack::Request.new(env)
|
|
18
|
+
|
|
19
|
+
case req.path
|
|
20
|
+
when "/"
|
|
21
|
+
[200, {}, ["Selenium Ruby Client Sample Application"]]
|
|
22
|
+
when "/compute"
|
|
23
|
+
sleep 5
|
|
24
|
+
resp = eval(req.params['calculator-expression']).to_s
|
|
25
|
+
[200, {}, [resp]]
|
|
26
|
+
else
|
|
27
|
+
@public.call(env)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'selenium/client'
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require File.expand_path('../sample-app/sample_app', __FILE__)
|
|
5
|
+
|
|
6
|
+
# for bamboo
|
|
7
|
+
require 'ci/reporter/rspec'
|
|
8
|
+
|
|
9
|
+
class SeleniumClientTestEnvironment
|
|
10
|
+
def initialize
|
|
11
|
+
$stdout.sync = true
|
|
12
|
+
@jar = File.expand_path("../../../../../../build/java/server/test/org/openqa/selenium/server-with-tests-standalone.jar", __FILE__)
|
|
13
|
+
|
|
14
|
+
raise Errno::ENOENT, @jar unless File.exist?(@jar)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def run
|
|
18
|
+
start_server
|
|
19
|
+
start_example_app
|
|
20
|
+
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def stop
|
|
25
|
+
stop_example_app
|
|
26
|
+
stop_server
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def driver
|
|
30
|
+
@driver ||= new_driver_with_session
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def in_separate_driver
|
|
34
|
+
@driver.stop if @driver
|
|
35
|
+
begin
|
|
36
|
+
@driver = new_driver_with_session
|
|
37
|
+
yield
|
|
38
|
+
ensure
|
|
39
|
+
@driver.stop
|
|
40
|
+
@driver = new_driver_with_session
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def server_host
|
|
45
|
+
ENV['SELENIUM_RC_HOST'] || "localhost"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def server_port
|
|
49
|
+
ENV['SELENIUM_RC_PORT'] || 4444
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def app_url
|
|
53
|
+
application_host = ENV['SELENIUM_APPLICATION_HOST'] || "localhost"
|
|
54
|
+
application_port = ENV['SELENIUM_APPLICATION_PORT'] || "4567"
|
|
55
|
+
|
|
56
|
+
"http://#{application_host}:#{application_port}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def new_driver_with_session
|
|
62
|
+
driver = Selenium::Client::Driver.new :host => server_host,
|
|
63
|
+
:port => server_port,
|
|
64
|
+
:browser => (ENV['SELENIUM_BROWSER'] || "*firefox"),
|
|
65
|
+
:timeout_in_seconds => (ENV['SELENIUM_RC_TIMEOUT'] || 20),
|
|
66
|
+
:url => app_url
|
|
67
|
+
|
|
68
|
+
driver.start_new_browser_session
|
|
69
|
+
driver.set_context self.class.name
|
|
70
|
+
|
|
71
|
+
driver
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def start_server
|
|
75
|
+
@server = Selenium::Server.new(@jar, :background => true,
|
|
76
|
+
:timeout => 3*60,
|
|
77
|
+
:port => server_port,
|
|
78
|
+
:log => true)
|
|
79
|
+
|
|
80
|
+
@server << "-singleWindow"
|
|
81
|
+
@server.start
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def stop_server
|
|
85
|
+
@server && @server.stop
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def start_example_app
|
|
89
|
+
Thread.abort_on_exception = true
|
|
90
|
+
@example_app = Thread.new { SampleApp.start("127.0.0.1", 4567) }
|
|
91
|
+
|
|
92
|
+
poller = Selenium::WebDriver::SocketPoller.new("127.0.0.1", 4567, 60)
|
|
93
|
+
unless poller.connected?
|
|
94
|
+
raise "timed out waiting for SampleApp to launch"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def stop_example_app
|
|
99
|
+
@example_app.kill
|
|
100
|
+
end
|
|
101
|
+
end # SeleniumClientTestEnvironment
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
RSpec.configure do |config|
|
|
105
|
+
if ENV['focus']
|
|
106
|
+
config.filter_run :focus => true
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
config.after(:suite) do
|
|
110
|
+
$selenium_client_test_environment && $selenium_client_test_environment.stop
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def selenium_driver
|
|
114
|
+
test_environment.driver
|
|
115
|
+
end
|
|
116
|
+
alias :page :selenium_driver
|
|
117
|
+
|
|
118
|
+
def test_environment
|
|
119
|
+
$selenium_client_test_environment ||= SeleniumClientTestEnvironment.new.run
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def in_separate_driver(&blk)
|
|
123
|
+
test_environment.in_separate_driver(&blk)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def should_timeout
|
|
127
|
+
begin
|
|
128
|
+
yield
|
|
129
|
+
raise "Should have timed out"
|
|
130
|
+
rescue Timeout::Error => e
|
|
131
|
+
# All good
|
|
132
|
+
rescue Selenium::Client::CommandError => e
|
|
133
|
+
raise unless e.message =~ /ed out after/
|
|
134
|
+
# All good
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module Selenium::WebDriver::DriverExtensions
|
|
5
|
+
describe "HasApplicationCache" do
|
|
6
|
+
|
|
7
|
+
compliant_on :browser => nil do
|
|
8
|
+
it "gets the app cache status" do
|
|
9
|
+
driver.application_cache.status.should == :uncached
|
|
10
|
+
|
|
11
|
+
driver.online = false
|
|
12
|
+
driver.navigate.to url_for("html5Page.html")
|
|
13
|
+
|
|
14
|
+
browser.application_cache.status.should == :idle
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "loads from cache when offline" do
|
|
18
|
+
driver.get url_for("html5Page.html")
|
|
19
|
+
driver.get url_for("formPage.html")
|
|
20
|
+
|
|
21
|
+
driver.online = false
|
|
22
|
+
|
|
23
|
+
driver.get url_for("html5Page.html")
|
|
24
|
+
driver.title.should == "HTML5"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "gets the app cache entries" do
|
|
28
|
+
# dependant on spec above?!
|
|
29
|
+
|
|
30
|
+
driver.get url_for("html5Page")
|
|
31
|
+
|
|
32
|
+
entries = driver.application_cache.to_a
|
|
33
|
+
entries.size.should > 2
|
|
34
|
+
|
|
35
|
+
entries.each do |e|
|
|
36
|
+
case e.url
|
|
37
|
+
when /red\.jpg/
|
|
38
|
+
e.type.value.should == :master
|
|
39
|
+
when /yellow\.jpg/
|
|
40
|
+
e.type.value.should == :explicit
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
|
2
|
+
|
|
3
|
+
module Selenium::WebDriver::DriverExtensions
|
|
4
|
+
describe HasBrowserConnection do
|
|
5
|
+
|
|
6
|
+
compliant_on :browser => nil do
|
|
7
|
+
it "can set the browser offline and online" do
|
|
8
|
+
driver.navigate.to url_for("html5Page.html")
|
|
9
|
+
driver.should be_online
|
|
10
|
+
|
|
11
|
+
driver.online = false
|
|
12
|
+
wait.until { not driver.online? }
|
|
13
|
+
|
|
14
|
+
driver.online = true
|
|
15
|
+
wait.until { driver.online? }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Selenium
|
|
2
|
+
module WebDriver
|
|
3
|
+
module Chrome
|
|
4
|
+
|
|
5
|
+
describe Driver do
|
|
6
|
+
it "should accept an array of custom command line arguments" do
|
|
7
|
+
begin
|
|
8
|
+
driver = Selenium::WebDriver.for :chrome, :args => ["--user-agent=foo;bar"]
|
|
9
|
+
driver.navigate.to url_for("click_jacker.html")
|
|
10
|
+
|
|
11
|
+
ua = driver.execute_script "return window.navigator.userAgent"
|
|
12
|
+
ua.should == "foo;bar"
|
|
13
|
+
ensure
|
|
14
|
+
driver.quit if driver
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should raise ArgumentError if :args is not an Array" do
|
|
19
|
+
lambda {
|
|
20
|
+
Selenium::WebDriver.for(:chrome, :args => "--foo")
|
|
21
|
+
}.should raise_error(ArgumentError)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end # Chrome
|
|
26
|
+
end # WebDriver
|
|
27
|
+
end # Selenium
|
|
28
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Selenium
|
|
2
|
+
module WebDriver
|
|
3
|
+
module Chrome
|
|
4
|
+
|
|
5
|
+
describe Profile do
|
|
6
|
+
let(:profile) { Profile.new }
|
|
7
|
+
|
|
8
|
+
# Won't work on ChromeDriver 2.0
|
|
9
|
+
#
|
|
10
|
+
# it "launches Chrome with a custom profile" do
|
|
11
|
+
# profile['autofill.disabled'] = true
|
|
12
|
+
#
|
|
13
|
+
# begin
|
|
14
|
+
# driver = WebDriver.for :chrome, :profile => profile
|
|
15
|
+
# ensure
|
|
16
|
+
# driver.quit if driver
|
|
17
|
+
# end
|
|
18
|
+
# end
|
|
19
|
+
|
|
20
|
+
it "should be serializable to JSON" do
|
|
21
|
+
profile['foo.boolean'] = true
|
|
22
|
+
|
|
23
|
+
new_profile = Profile.from_json(profile.to_json)
|
|
24
|
+
new_profile['foo.boolean'].should be_true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "adds an extension" do
|
|
28
|
+
ext_path = "/some/path.crx"
|
|
29
|
+
|
|
30
|
+
File.should_receive(:file?).with(ext_path).and_return true
|
|
31
|
+
profile.add_extension(ext_path).should == [ext_path]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "reads an extension as binary data" do
|
|
35
|
+
ext_path = "/some/path.crx"
|
|
36
|
+
File.should_receive(:file?).with(ext_path).and_return true
|
|
37
|
+
|
|
38
|
+
profile.add_extension(ext_path)
|
|
39
|
+
|
|
40
|
+
ext_file = double('file')
|
|
41
|
+
File.should_receive(:open).with(ext_path, "rb").and_yield ext_file
|
|
42
|
+
ext_file.should_receive(:read).and_return "test"
|
|
43
|
+
|
|
44
|
+
profile.should_receive(:layout_on_disk).and_return "ignored"
|
|
45
|
+
Zipper.should_receive(:zip).and_return "ignored"
|
|
46
|
+
|
|
47
|
+
profile.as_json().should == {
|
|
48
|
+
'zip' => "ignored",
|
|
49
|
+
'extensions' => [Base64.strict_encode64("test")]
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "raises an error if the extension doesn't exist" do
|
|
54
|
+
lambda {
|
|
55
|
+
profile.add_extension("/not/likely/to/exist.crx")
|
|
56
|
+
}.should raise_error
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end # Chrome
|
|
61
|
+
end # WebDriver
|
|
62
|
+
end # Selenium
|
|
63
|
+
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
|
2
|
+
|
|
3
|
+
describe "Driver" do
|
|
4
|
+
it "should get the page title" do
|
|
5
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
6
|
+
driver.title.should == "XHTML Test Page"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should get the page source" do
|
|
10
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
11
|
+
driver.page_source.should match(%r[<title>XHTML Test Page</title>]i)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
not_compliant_on :browser => :safari do
|
|
16
|
+
it "should refresh the page" do
|
|
17
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
18
|
+
driver.find_element(:link_text, 'Update a div').click
|
|
19
|
+
driver.find_element(:id, 'dynamo').text.should == "Fish and chips!"
|
|
20
|
+
driver.navigate.refresh
|
|
21
|
+
driver.find_element(:id, 'dynamo').text.should == "What's for dinner?"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
not_compliant_on :browser => [:opera, :iphone, :safari] do
|
|
26
|
+
it "should save a screenshot" do
|
|
27
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
28
|
+
path = "screenshot_tmp.png"
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
driver.save_screenshot path
|
|
32
|
+
File.exist?(path).should be_true # sic
|
|
33
|
+
File.size(path).should > 0
|
|
34
|
+
ensure
|
|
35
|
+
File.delete(path) if File.exist?(path)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should return a screenshot in the specified format" do
|
|
40
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
41
|
+
|
|
42
|
+
ss = driver.screenshot_as(:png)
|
|
43
|
+
ss.should be_kind_of(String)
|
|
44
|
+
ss.size.should > 0
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "raises an error when given an unknown format" do
|
|
48
|
+
lambda { driver.screenshot_as(:jpeg) }.should raise_error(WebDriver::Error::UnsupportedOperationError)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "one element" do
|
|
53
|
+
it "should find by id" do
|
|
54
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
55
|
+
element = driver.find_element(:id, "id1")
|
|
56
|
+
element.should be_kind_of(WebDriver::Element)
|
|
57
|
+
element.text.should == "Foo"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should find by field name" do
|
|
61
|
+
driver.navigate.to url_for("formPage.html")
|
|
62
|
+
driver.find_element(:name, "x").attribute('value').should == "name"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should find by class name" do
|
|
66
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
67
|
+
driver.find_element(:class, "header").text.should == "XHTML Might Be The Future"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should find by link text" do
|
|
71
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
72
|
+
driver.find_element(:link, "Foo").text.should == "Foo"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should find by xpath" do
|
|
76
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
77
|
+
driver.find_element(:xpath, "//h1").text.should == "XHTML Might Be The Future"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should find by css selector" do
|
|
81
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
82
|
+
driver.find_element(:css, "div.content").attribute("class").should == "content"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should find by tag name" do
|
|
86
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
87
|
+
driver.find_element(:tag_name, 'div').attribute("class").should == "navigation"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should find child element" do
|
|
91
|
+
driver.navigate.to url_for("nestedElements.html")
|
|
92
|
+
|
|
93
|
+
element = driver.find_element(:name, "form2")
|
|
94
|
+
child = element.find_element(:name, "selectomatic")
|
|
95
|
+
|
|
96
|
+
child.attribute("id").should == "2"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should find child element by tag name" do
|
|
100
|
+
driver.navigate.to url_for("nestedElements.html")
|
|
101
|
+
|
|
102
|
+
element = driver.find_element(:name, "form2")
|
|
103
|
+
child = element.find_element(:tag_name, "select")
|
|
104
|
+
|
|
105
|
+
child.attribute("id").should == "2"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should raise on nonexistant element" do
|
|
109
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
110
|
+
lambda { driver.find_element("nonexistant") }.should raise_error
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should find elements with a hash selector" do
|
|
114
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
115
|
+
driver.find_element(:class => "header").text.should == "XHTML Might Be The Future"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "should find elements with the shortcut syntax" do
|
|
119
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
120
|
+
|
|
121
|
+
driver[:id1].should be_kind_of(WebDriver::Element)
|
|
122
|
+
driver[:xpath => "//h1"].should be_kind_of(WebDriver::Element)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe "many elements" do
|
|
127
|
+
it "should find by class name" do
|
|
128
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
129
|
+
driver.find_elements(:class, "nameC").should have(2).things
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should find by css selector" do
|
|
133
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
134
|
+
driver.find_elements(:css, 'p')
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "should find children by field name" do
|
|
138
|
+
driver.navigate.to url_for("nestedElements.html")
|
|
139
|
+
element = driver.find_element(:name, "form2")
|
|
140
|
+
children = element.find_elements(:name, "selectomatic")
|
|
141
|
+
children.should have(2).items
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe "execute script" do
|
|
146
|
+
it "should return strings" do
|
|
147
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
148
|
+
driver.execute_script("return document.title;").should == "XHTML Test Page"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "should return numbers" do
|
|
152
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
153
|
+
driver.execute_script("return document.title.length;").should == "XHTML Test Page".length
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should return elements" do
|
|
157
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
158
|
+
element = driver.execute_script("return document.getElementById('id1');")
|
|
159
|
+
element.should be_kind_of(WebDriver::Element)
|
|
160
|
+
element.text.should == "Foo"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
not_compliant_on :browser => [:opera, :android] do
|
|
164
|
+
it "should unwrap elements in deep objects" do
|
|
165
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
166
|
+
result = driver.execute_script(<<-SCRIPT)
|
|
167
|
+
var e1 = document.getElementById('id1');
|
|
168
|
+
var body = document.body;
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
elements: {'body' : body, other: [e1] }
|
|
172
|
+
};
|
|
173
|
+
SCRIPT
|
|
174
|
+
|
|
175
|
+
result.should be_kind_of(Hash)
|
|
176
|
+
result['elements']['body'].should be_kind_of(WebDriver::Element)
|
|
177
|
+
result['elements']['other'].first.should be_kind_of(WebDriver::Element)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "should return booleans" do
|
|
182
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
183
|
+
driver.execute_script("return true;").should == true
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "should raise if the script is bad" do
|
|
187
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
188
|
+
lambda { driver.execute_script("return squiggle();") }.should raise_error
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should return arrays" do
|
|
192
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
|
193
|
+
driver.execute_script('return ["zero", "one", "two"];').should == %w[zero one two]
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "should be able to call functions on the page" do
|
|
197
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
198
|
+
driver.execute_script("displayMessage('I like cheese');")
|
|
199
|
+
driver.find_element(:id, "result").text.strip.should == "I like cheese"
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it "should be able to pass string arguments" do
|
|
203
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
204
|
+
driver.execute_script("return arguments[0] == 'fish' ? 'fish' : 'not fish';", "fish").should == "fish"
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it "should be able to pass boolean arguments" do
|
|
208
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
209
|
+
driver.execute_script("return arguments[0] == true;", true).should == true
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "should be able to pass numeric arguments" do
|
|
213
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
214
|
+
driver.execute_script("return arguments[0] == 1 ? 1 : 0;", 1).should == 1
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "should be able to pass null arguments" do
|
|
218
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
219
|
+
driver.execute_script("return arguments[0];", nil).should == nil
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it "should be able to pass array arguments" do
|
|
223
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
224
|
+
driver.execute_script("return arguments[0];", [1, '2', 3]).should == [1, '2', 3]
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it "should be able to pass element arguments" do
|
|
228
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
229
|
+
button = driver.find_element(:id, "plainButton")
|
|
230
|
+
driver.execute_script("arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];", button).should == "plainButton"
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it "should be able to pass in multiple arguments" do
|
|
234
|
+
driver.navigate.to url_for("javascriptPage.html")
|
|
235
|
+
driver.execute_script("return arguments[0] + arguments[1];", "one", "two").should == "onetwo"
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
not_compliant_on :browser => [:opera, :iphone, :android, :phantomjs] do
|
|
240
|
+
describe "execute async script" do
|
|
241
|
+
before {
|
|
242
|
+
driver.manage.timeouts.script_timeout = 0
|
|
243
|
+
driver.navigate.to url_for("ajaxy_page.html")
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
it "should be able to return arrays of primitives from async scripts" do
|
|
247
|
+
result = driver.execute_async_script "arguments[arguments.length - 1]([null, 123, 'abc', true, false]);"
|
|
248
|
+
result.should == [nil, 123, 'abc', true, false]
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it "should be able to pass multiple arguments to async scripts" do
|
|
252
|
+
result = driver.execute_async_script "arguments[arguments.length - 1](arguments[0] + arguments[1]);", 1, 2
|
|
253
|
+
result.should == 3
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
it "times out if the callback is not invoked" do
|
|
257
|
+
lambda {
|
|
258
|
+
# Script is expected to be async and explicitly callback, so this should timeout.
|
|
259
|
+
driver.execute_async_script "return 1 + 2;"
|
|
260
|
+
}.should raise_error(Selenium::WebDriver::Error::ScriptTimeOutError)
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
end
|
|
266
|
+
|