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,199 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
module SpecSupport
|
4
|
+
class TestEnvironment
|
5
|
+
|
6
|
+
attr_accessor :unguarded
|
7
|
+
attr_reader :driver
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
puts "creating test env :: #{ruby_description}"
|
11
|
+
|
12
|
+
@create_driver_error = nil
|
13
|
+
@create_driver_error_count = 0
|
14
|
+
|
15
|
+
# TODO: get rid of ENV
|
16
|
+
@driver = (ENV['WD_SPEC_DRIVER'] || raise("must set WD_SPEC_DRIVER")).to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def browser
|
20
|
+
if driver == :remote
|
21
|
+
# TODO: get rid of ENV
|
22
|
+
(ENV['WD_REMOTE_BROWSER'] || :firefox).to_sym
|
23
|
+
else
|
24
|
+
driver
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def driver_instance
|
29
|
+
@driver_instance ||= new_driver_instance
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset_driver!
|
33
|
+
quit_driver
|
34
|
+
@driver_instance = new_driver_instance
|
35
|
+
end
|
36
|
+
|
37
|
+
def quit_driver
|
38
|
+
@driver_instance.quit if @driver_instance
|
39
|
+
end
|
40
|
+
|
41
|
+
def new_driver_instance
|
42
|
+
check_for_previous_error
|
43
|
+
create_driver
|
44
|
+
end
|
45
|
+
|
46
|
+
def app_server
|
47
|
+
@app_server ||= (
|
48
|
+
path = File.join(root_folder, "common/src/web")
|
49
|
+
s = RackServer.new(path)
|
50
|
+
s.start
|
51
|
+
|
52
|
+
s
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def remote_server
|
57
|
+
@remote_server ||= (
|
58
|
+
Selenium::Server.new(remote_server_jar,
|
59
|
+
:port => PortProber.random,
|
60
|
+
:log => !!$DEBUG,
|
61
|
+
:background => true,
|
62
|
+
:timeout => 60
|
63
|
+
)
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def remote_server_jar
|
68
|
+
@remote_server_jar ||= File.join(root_folder, "build/java/server/test/org/openqa/selenium/server-with-tests-standalone.jar")
|
69
|
+
end
|
70
|
+
|
71
|
+
def quit
|
72
|
+
app_server.stop
|
73
|
+
|
74
|
+
if defined?(@remote_server)
|
75
|
+
@remote_server.stop
|
76
|
+
end
|
77
|
+
|
78
|
+
@driver_instance = @app_server = @remote_server = nil
|
79
|
+
ensure
|
80
|
+
Guards.report
|
81
|
+
end
|
82
|
+
|
83
|
+
def unguarded?
|
84
|
+
@unguarded ||= false
|
85
|
+
end
|
86
|
+
|
87
|
+
def native_events?
|
88
|
+
@native_events ||= !!ENV['native']
|
89
|
+
end
|
90
|
+
|
91
|
+
def url_for(filename)
|
92
|
+
url = app_server.where_is filename
|
93
|
+
url.sub!("127.0.0.1", "10.0.2.2") if browser == :android
|
94
|
+
|
95
|
+
url
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def ruby_description
|
101
|
+
defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby-#{RUBY_VERSION}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def root_folder
|
105
|
+
@root_folder ||= File.expand_path("../../../../../../../", __FILE__)
|
106
|
+
end
|
107
|
+
|
108
|
+
def create_driver
|
109
|
+
instance = case driver
|
110
|
+
when :remote
|
111
|
+
create_remote_driver
|
112
|
+
when :opera
|
113
|
+
create_opera_driver
|
114
|
+
when :firefox
|
115
|
+
create_firefox_driver
|
116
|
+
when :chrome
|
117
|
+
create_chrome_driver
|
118
|
+
else
|
119
|
+
WebDriver::Driver.for driver
|
120
|
+
end
|
121
|
+
|
122
|
+
@create_driver_error_count -= 1 unless @create_driver_error_count == 0
|
123
|
+
instance
|
124
|
+
rescue => ex
|
125
|
+
@create_driver_error = ex
|
126
|
+
@create_driver_error_count += 1
|
127
|
+
raise ex
|
128
|
+
end
|
129
|
+
|
130
|
+
def remote_capabilities
|
131
|
+
caps = WebDriver::Remote::Capabilities.send(ENV['WD_REMOTE_BROWSER'] || 'firefox')
|
132
|
+
|
133
|
+
caps.javascript_enabled = true
|
134
|
+
caps.css_selectors_enabled = true
|
135
|
+
|
136
|
+
caps
|
137
|
+
end
|
138
|
+
|
139
|
+
MAX_ERRORS = 4
|
140
|
+
|
141
|
+
class DriverInstantiationError < StandardError
|
142
|
+
end
|
143
|
+
|
144
|
+
def check_for_previous_error
|
145
|
+
return unless @create_driver_error && @create_driver_error_count >= MAX_ERRORS
|
146
|
+
|
147
|
+
msg = "previous #{@create_driver_error_count} instantiations of driver #{driver.inspect} failed, not trying again"
|
148
|
+
msg << " (#{@create_driver_error.message})"
|
149
|
+
|
150
|
+
raise DriverInstantiationError, msg, @create_driver_error.backtrace
|
151
|
+
end
|
152
|
+
|
153
|
+
def create_remote_driver
|
154
|
+
WebDriver::Driver.for(:remote,
|
155
|
+
:desired_capabilities => remote_capabilities,
|
156
|
+
:url => remote_server.webdriver_url,
|
157
|
+
:http_client => keep_alive_client || http_client
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
def create_opera_driver
|
162
|
+
ENV['SELENIUM_SERVER_JAR'] = remote_server_jar
|
163
|
+
WebDriver::Driver.for :opera, :logging_level => ENV['log'] ? :config : :severe
|
164
|
+
end
|
165
|
+
|
166
|
+
def create_firefox_driver
|
167
|
+
if native_events?
|
168
|
+
profile = WebDriver::Firefox::Profile.new
|
169
|
+
profile.native_events = true
|
170
|
+
|
171
|
+
WebDriver::Driver.for :firefox, :profile => profile
|
172
|
+
else
|
173
|
+
WebDriver::Driver.for :firefox
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def create_chrome_driver
|
178
|
+
WebDriver::Driver.for :chrome,
|
179
|
+
:native_events => native_events?
|
180
|
+
# :http_client => keep_alive_client || http_client
|
181
|
+
end
|
182
|
+
|
183
|
+
def keep_alive_client
|
184
|
+
require 'selenium/webdriver/remote/http/persistent'
|
185
|
+
STDERR.puts "INFO: using net-http-persistent"
|
186
|
+
|
187
|
+
Selenium::WebDriver::Remote::Http::Persistent.new
|
188
|
+
rescue LoadError
|
189
|
+
# net-http-persistent not available
|
190
|
+
end
|
191
|
+
|
192
|
+
def http_client
|
193
|
+
Selenium::WebDriver::Remote::Http::Default.new
|
194
|
+
end
|
195
|
+
|
196
|
+
end # TestEnvironment
|
197
|
+
end # SpecSupport
|
198
|
+
end # WebDriver
|
199
|
+
end # Selenium
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Selenium::WebDriver::TargetLocator" do
|
4
|
+
let(:wait) { Selenium::WebDriver::Wait.new }
|
5
|
+
|
6
|
+
it "should find the active element" do
|
7
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
8
|
+
driver.switch_to.active_element.should be_an_instance_of(WebDriver::Element)
|
9
|
+
end
|
10
|
+
|
11
|
+
not_compliant_on :browser => :iphone do
|
12
|
+
it "should switch to a frame" do
|
13
|
+
driver.navigate.to url_for("iframes.html")
|
14
|
+
driver.switch_to.frame("iframe1")
|
15
|
+
|
16
|
+
# TODO: expectations?
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should switch to a frame by Element" do
|
20
|
+
driver.navigate.to url_for("iframes.html")
|
21
|
+
|
22
|
+
iframe = driver.find_element(:tag_name => "iframe")
|
23
|
+
driver.switch_to.frame(iframe)
|
24
|
+
|
25
|
+
# TODO: expectations?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
not_compliant_on :browser => [:ie, :iphone] do
|
30
|
+
it "should switch to a window and back when given a block" do
|
31
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
32
|
+
|
33
|
+
driver.find_element(:link, "Open new window").click
|
34
|
+
driver.title.should == "XHTML Test Page"
|
35
|
+
|
36
|
+
driver.switch_to.window("result") do
|
37
|
+
wait.until { driver.title == "We Arrive Here" }
|
38
|
+
end
|
39
|
+
|
40
|
+
wait.until { driver.title == "XHTML Test Page" }
|
41
|
+
|
42
|
+
reset_driver!
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should handle exceptions inside the block" do
|
46
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
47
|
+
|
48
|
+
driver.find_element(:link, "Open new window").click
|
49
|
+
driver.title.should == "XHTML Test Page"
|
50
|
+
|
51
|
+
lambda {
|
52
|
+
driver.switch_to.window("result") { raise "foo" }
|
53
|
+
}.should raise_error(RuntimeError, "foo")
|
54
|
+
|
55
|
+
driver.title.should == "XHTML Test Page"
|
56
|
+
|
57
|
+
reset_driver!
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should switch to a window" do
|
61
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
62
|
+
|
63
|
+
driver.find_element(:link, "Open new window").click
|
64
|
+
wait.until { driver.title == "XHTML Test Page" }
|
65
|
+
|
66
|
+
driver.switch_to.window("result")
|
67
|
+
wait.until { driver.title == "We Arrive Here" }
|
68
|
+
|
69
|
+
reset_driver!
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should use the original window if the block closes the popup" do
|
73
|
+
driver.navigate.to url_for("xhtmlTest.html")
|
74
|
+
|
75
|
+
driver.find_element(:link, "Open new window").click
|
76
|
+
driver.title.should == "XHTML Test Page"
|
77
|
+
|
78
|
+
driver.switch_to.window("result") do
|
79
|
+
wait.until { driver.title == "We Arrive Here" }
|
80
|
+
driver.close
|
81
|
+
end
|
82
|
+
|
83
|
+
driver.current_url.should include("xhtmlTest.html")
|
84
|
+
driver.title.should == "XHTML Test Page"
|
85
|
+
reset_driver!
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
not_compliant_on :browser => [:android, :iphone] do
|
90
|
+
it "should switch to default content" do
|
91
|
+
driver.navigate.to url_for("iframes.html")
|
92
|
+
|
93
|
+
driver.switch_to.frame 0
|
94
|
+
driver.switch_to.default_content
|
95
|
+
|
96
|
+
driver.find_element(:id => "iframe_page_heading")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "alerts" do
|
101
|
+
not_compliant_on :browser => [:opera, :iphone] do
|
102
|
+
it "allows the user to accept an alert" do
|
103
|
+
driver.navigate.to url_for("alerts.html")
|
104
|
+
driver.find_element(:id => "alert").click
|
105
|
+
|
106
|
+
driver.switch_to.alert.accept
|
107
|
+
|
108
|
+
driver.title.should == "Testing Alerts"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
not_compliant_on({:browser => :chrome, :platform => :macosx}, # http://code.google.com/p/chromium/issues/detail?id=90519
|
113
|
+
{:browser => :opera},
|
114
|
+
{:browser => :iphone}) do
|
115
|
+
it "allows the user to dismiss an alert" do
|
116
|
+
driver.navigate.to url_for("alerts.html")
|
117
|
+
driver.find_element(:id => "alert").click
|
118
|
+
|
119
|
+
driver.switch_to.alert.dismiss
|
120
|
+
|
121
|
+
driver.title.should == "Testing Alerts"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
not_compliant_on :browser => [:opera, :iphone] do
|
126
|
+
it "allows the user to set the value of a prompt" do
|
127
|
+
driver.navigate.to url_for("alerts.html")
|
128
|
+
driver.find_element(:id => "prompt").click
|
129
|
+
|
130
|
+
alert = driver.switch_to.alert
|
131
|
+
alert.send_keys "cheese"
|
132
|
+
alert.accept
|
133
|
+
|
134
|
+
text = driver.find_element(:id => "text").text
|
135
|
+
text.should == "cheese"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "allows the user to get the text of an alert" do
|
139
|
+
driver.navigate.to url_for("alerts.html")
|
140
|
+
driver.find_element(:id => "alert").click
|
141
|
+
|
142
|
+
alert = driver.switch_to.alert
|
143
|
+
text = alert.text
|
144
|
+
alert.accept
|
145
|
+
|
146
|
+
text.should == "cheese"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
not_compliant_on :browser => [:chrome, :ie, :opera, :iphone] do
|
151
|
+
it "raises NoAlertOpenError if no alert is present" do
|
152
|
+
lambda { driver.switch_to.alert }.should raise_error(
|
153
|
+
Selenium::WebDriver::Error::NoAlertOpenError, /alert/i)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
compliant_on :browser => nil do
|
158
|
+
it "raises an UnhandledAlertError if an alert has not been dealt with" do
|
159
|
+
driver.navigate.to url_for("alerts.html")
|
160
|
+
driver.find_element(:id => "alert").click
|
161
|
+
|
162
|
+
lambda { driver.title }.should raise_error(Selenium::WebDriver::Error::UnhandledAlertError)
|
163
|
+
|
164
|
+
driver.title.should == "Testing Alerts"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Timeouts" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
driver.manage.timeouts.implicit_wait = 0
|
7
|
+
driver.navigate.to url_for("dynamic.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
after { driver.manage.timeouts.implicit_wait = 0 }
|
11
|
+
|
12
|
+
it "should implicitly wait for a single element" do
|
13
|
+
driver.manage.timeouts.implicit_wait = 3
|
14
|
+
|
15
|
+
driver.find_element(:id => 'adder').click
|
16
|
+
driver.find_element(:id => 'box0')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should still fail to find an element with implicit waits enabled" do
|
20
|
+
driver.manage.timeouts.implicit_wait = 0.5
|
21
|
+
lambda { driver.find_element(:id => "box0") }.should raise_error(WebDriver::Error::NoSuchElementError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return after first attempt to find one after disabling implicit waits" do
|
25
|
+
driver.manage.timeouts.implicit_wait = 3
|
26
|
+
driver.manage.timeouts.implicit_wait = 0
|
27
|
+
|
28
|
+
lambda { driver.find_element(:id => "box0") }.should raise_error(WebDriver::Error::NoSuchElementError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should implicitly wait until at least one element is found when searching for many" do
|
32
|
+
add = driver.find_element(:id => "adder")
|
33
|
+
|
34
|
+
driver.manage.timeouts.implicit_wait = 2
|
35
|
+
add.click
|
36
|
+
add.click
|
37
|
+
|
38
|
+
driver.find_elements(:class_name => "redbox").should_not be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should still fail to find elements when implicit waits are enabled" do
|
42
|
+
driver.manage.timeouts.implicit_wait = 0.5
|
43
|
+
driver.find_elements(:class_name => "redbox").should be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return after first attempt to find many after disabling implicit waits" do
|
47
|
+
add = driver.find_element(:id => "adder")
|
48
|
+
|
49
|
+
driver.manage.timeouts.implicit_wait = 3
|
50
|
+
driver.manage.timeouts.implicit_wait = 0
|
51
|
+
add.click
|
52
|
+
|
53
|
+
driver.find_elements(:class_name => "redbox").should be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
describe Window do
|
6
|
+
let(:window) { driver.manage.window }
|
7
|
+
|
8
|
+
compliant_on :browser => :firefox do
|
9
|
+
it "gets the size of the current window" do
|
10
|
+
size = window.size
|
11
|
+
|
12
|
+
size.should be_kind_of(Dimension)
|
13
|
+
|
14
|
+
size.width.should > 0
|
15
|
+
size.height.should > 0
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets the size of the current window" do
|
19
|
+
size = window.size
|
20
|
+
|
21
|
+
target_width = size.width - 20
|
22
|
+
target_height = size.height - 20
|
23
|
+
|
24
|
+
window.size = Dimension.new(target_width, target_height)
|
25
|
+
|
26
|
+
new_size = window.size
|
27
|
+
new_size.width.should == target_width
|
28
|
+
new_size.height.should == target_height
|
29
|
+
end
|
30
|
+
|
31
|
+
it "gets the position of the current window" do
|
32
|
+
pos = driver.manage.window.position
|
33
|
+
|
34
|
+
pos.should be_kind_of(Point)
|
35
|
+
|
36
|
+
pos.x.should >= 0
|
37
|
+
pos.y.should >= 0
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets the position of the current window" do
|
41
|
+
pos = window.position
|
42
|
+
|
43
|
+
target_x = pos.x + 10
|
44
|
+
target_y = pos.y + 10
|
45
|
+
|
46
|
+
window.position = Point.new(target_x, target_y)
|
47
|
+
|
48
|
+
new_pos = window.position
|
49
|
+
new_pos.x.should == target_x
|
50
|
+
new_pos.y.should == target_y
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|