bbc-selenium-webdriver 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/CHANGES +473 -0
  2. data/README +31 -0
  3. data/lib/selenium-client.rb +2 -0
  4. data/lib/selenium-webdriver.rb +1 -0
  5. data/lib/selenium/client.rb +37 -0
  6. data/lib/selenium/client/base.rb +118 -0
  7. data/lib/selenium/client/driver.rb +10 -0
  8. data/lib/selenium/client/errors.rb +9 -0
  9. data/lib/selenium/client/extensions.rb +118 -0
  10. data/lib/selenium/client/idiomatic.rb +488 -0
  11. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  12. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  13. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  14. data/lib/selenium/client/legacy_driver.rb +1720 -0
  15. data/lib/selenium/client/protocol.rb +104 -0
  16. data/lib/selenium/client/selenium_helper.rb +34 -0
  17. data/lib/selenium/rake/server_task.rb +157 -0
  18. data/lib/selenium/server.rb +223 -0
  19. data/lib/selenium/webdriver.rb +64 -0
  20. data/lib/selenium/webdriver/android.rb +9 -0
  21. data/lib/selenium/webdriver/android/bridge.rb +51 -0
  22. data/lib/selenium/webdriver/chrome.rb +26 -0
  23. data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
  24. data/lib/selenium/webdriver/chrome/profile.rb +83 -0
  25. data/lib/selenium/webdriver/chrome/service.rb +74 -0
  26. data/lib/selenium/webdriver/common.rb +30 -0
  27. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  28. data/lib/selenium/webdriver/common/alert.rb +26 -0
  29. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  30. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  31. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  32. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  33. data/lib/selenium/webdriver/common/driver.rb +301 -0
  34. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  35. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  38. data/lib/selenium/webdriver/common/element.rb +262 -0
  39. data/lib/selenium/webdriver/common/error.rb +212 -0
  40. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  41. data/lib/selenium/webdriver/common/keyboard.rb +52 -0
  42. data/lib/selenium/webdriver/common/keys.rb +109 -0
  43. data/lib/selenium/webdriver/common/mouse.rb +65 -0
  44. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  45. data/lib/selenium/webdriver/common/options.rb +128 -0
  46. data/lib/selenium/webdriver/common/platform.rb +166 -0
  47. data/lib/selenium/webdriver/common/port_prober.rb +25 -0
  48. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  49. data/lib/selenium/webdriver/common/proxy.rb +120 -0
  50. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  51. data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
  52. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  53. data/lib/selenium/webdriver/common/timeouts.rb +29 -0
  54. data/lib/selenium/webdriver/common/wait.rb +60 -0
  55. data/lib/selenium/webdriver/common/window.rb +96 -0
  56. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  57. data/lib/selenium/webdriver/firefox.rb +37 -0
  58. data/lib/selenium/webdriver/firefox/binary.rb +161 -0
  59. data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
  60. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  61. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  62. data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
  63. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  64. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  65. data/lib/selenium/webdriver/firefox/profile.rb +315 -0
  66. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  67. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  68. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  69. data/lib/selenium/webdriver/ie.rb +19 -0
  70. data/lib/selenium/webdriver/ie/bridge.rb +60 -0
  71. data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
  72. data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
  73. data/lib/selenium/webdriver/ie/server.rb +64 -0
  74. data/lib/selenium/webdriver/iphone.rb +9 -0
  75. data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
  76. data/lib/selenium/webdriver/opera.rb +24 -0
  77. data/lib/selenium/webdriver/opera/bridge.rb +113 -0
  78. data/lib/selenium/webdriver/opera/service.rb +49 -0
  79. data/lib/selenium/webdriver/remote.rb +21 -0
  80. data/lib/selenium/webdriver/remote/bridge.rb +473 -0
  81. data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
  82. data/lib/selenium/webdriver/remote/commands.rb +181 -0
  83. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  84. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  85. data/lib/selenium/webdriver/remote/http/default.rb +102 -0
  86. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  87. data/lib/selenium/webdriver/remote/response.rb +99 -0
  88. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  89. data/lib/selenium/webdriver/support.rb +4 -0
  90. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  91. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  92. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  93. data/lib/selenium/webdriver/support/select.rb +293 -0
  94. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  95. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  96. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  97. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  98. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  99. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  100. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  101. data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
  102. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  103. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  104. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  105. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  106. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  107. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  108. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  109. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  110. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  111. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  112. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  113. data/spec/integration/selenium/client/spec_helper.rb +125 -0
  114. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  115. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
  116. data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
  117. data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
  118. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  119. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  120. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  121. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  122. data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
  123. data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
  124. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  125. data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
  126. data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
  127. data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
  128. data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
  129. data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
  130. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
  131. data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
  132. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  133. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
  134. data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
  135. data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
  136. data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
  137. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  138. data/spec/unit/selenium/client/base_spec.rb +239 -0
  139. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  140. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  141. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  142. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  143. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  144. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  145. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  146. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  147. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  148. data/spec/unit/selenium/server_spec.rb +131 -0
  149. data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
  150. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
  151. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
  152. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  153. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  154. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  155. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
  156. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
  157. data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
  158. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  159. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
  160. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  161. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
  162. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  163. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  164. data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
  165. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  166. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  167. data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
  168. metadata +215 -0
@@ -0,0 +1,44 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "Navigation" do
4
+ let(:wait) { Selenium::WebDriver::Wait.new }
5
+
6
+ it "should navigate back and forward" do
7
+ form_title = "We Leave From Here"
8
+ result_title = "We Arrive Here"
9
+ form_url = url_for "formPage.html"
10
+ result_url = url_for "resultPage.html"
11
+
12
+ driver.navigate.to form_url
13
+ driver.title.should == form_title
14
+
15
+ driver.find_element(:id, 'imageButton').submit
16
+ wait.until { driver.title != form_title }
17
+
18
+ driver.current_url.should include(result_url)
19
+ driver.title.should == result_title
20
+
21
+ driver.navigate.back
22
+
23
+ driver.current_url.should include(form_url)
24
+ driver.title.should == form_title
25
+
26
+ driver.navigate.forward
27
+ driver.current_url.should include(result_url)
28
+ driver.title.should == result_title
29
+ end
30
+
31
+ it "should refresh the page" do
32
+ changed_title = "Changed"
33
+
34
+ driver.navigate.to url_for("javascriptPage.html")
35
+ driver.find_element(:link_text, "Change the page title!").click
36
+ driver.title.should == changed_title
37
+
38
+ driver.navigate.refresh
39
+ wait.until { driver.title != changed_title }
40
+
41
+ driver.title.should == "Testing Javascript"
42
+ end
43
+ end
44
+
@@ -0,0 +1,47 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Opera
4
+
5
+ describe Driver do
6
+
7
+ before(:all) { GlobalTestEnv.quit_driver rescue nil }
8
+
9
+ it 'raises ArgumentError if sent an unknown capability as an argument' do
10
+ lambda {
11
+ Selenium::WebDriver.for :opera, :foo => 'bar'
12
+ }.should raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'accepts an array of custom command-line arguments' do
16
+ begin
17
+ driver = Selenium::WebDriver.for :opera, :arguments => ['-geometry 800x600']
18
+ ensure
19
+ driver.quit if driver
20
+ end
21
+ end
22
+
23
+ it 'raises ArgumentError if :arguments is not an Array' do
24
+ lambda {
25
+ Selenium::WebDriver.for :opera, :arguments => '-foo'
26
+ }.should raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'accepts a valid logging level' do
30
+ begin
31
+ driver = Selenium::WebDriver.for :opera, :logging_level => :config
32
+ # TODO(andreastt): Validate output to console
33
+ ensure
34
+ driver.quit if driver
35
+ end
36
+ end
37
+
38
+ it 'raises ArgumentError if :logging_level uses an invalid logging level' do
39
+ lambda {
40
+ Selenium::WebDriver.for :opera, :logging_level => :hoobaflooba
41
+ }.should raise_error(ArgumentError)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "Options" do
4
+ describe "cookie management" do
5
+ it "should get all" do
6
+ driver.navigate.to url_for("xhtmlTest.html")
7
+ driver.manage.add_cookie :name => "foo", :value => "bar"
8
+
9
+ cookies = driver.manage.all_cookies
10
+
11
+ cookies.should have(1).things
12
+ cookies.first[:name].should == "foo"
13
+ cookies.first[:value].should == "bar"
14
+ end
15
+
16
+ it "should delete one" do
17
+ driver.navigate.to url_for("xhtmlTest.html")
18
+
19
+ driver.manage.add_cookie :name => "foo", :value => "bar"
20
+ driver.manage.delete_cookie("foo")
21
+ end
22
+
23
+ it "should delete all" do
24
+ driver.navigate.to url_for("xhtmlTest.html")
25
+
26
+ driver.manage.add_cookie :name => "foo", :value => "bar"
27
+ driver.manage.delete_all_cookies
28
+ driver.manage.all_cookies.should be_empty
29
+ end
30
+
31
+ not_compliant_on :browser => [:ie, :android, :iphone] do
32
+ it "should use DateTime for expires" do
33
+ driver.navigate.to url_for("xhtmlTest.html")
34
+
35
+ expected = DateTime.new(2039)
36
+ driver.manage.add_cookie :name => "foo",
37
+ :value => "bar",
38
+ :expires => expected
39
+
40
+ actual = driver.manage.cookie_named("foo")[:expires]
41
+ actual.should be_kind_of(DateTime)
42
+ actual.should == expected
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+
@@ -0,0 +1,24 @@
1
+ module Selenium
2
+ module WebDriver
3
+ describe Element do
4
+ before do
5
+ driver.file_detector = lambda { |str| __FILE__ }
6
+ end
7
+
8
+ after do
9
+ driver.file_detector = nil
10
+ end
11
+
12
+ it "uses the file detector" do
13
+ driver.navigate.to url_for("upload.html")
14
+
15
+ driver.find_element(:id => "upload").send_keys("random string")
16
+ driver.find_element(:id => "go").submit
17
+
18
+ driver.switch_to.frame("upload_target")
19
+ body = driver.find_element(:xpath => "//body")
20
+ body.text.should include("uses the set file detector")
21
+ end
22
+ end
23
+ end # WebDriver
24
+ end # Selenium
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'time'
3
+ require 'rspec'
4
+ require 'ci/reporter/rspec'
5
+
6
+ require 'selenium-webdriver'
7
+ require 'selenium/webdriver/spec_support'
8
+
9
+ include Selenium
10
+
11
+ if WebDriver::Platform.jruby?
12
+ require 'java'
13
+
14
+ [
15
+ Dir['build/**/*.jar'],
16
+ Dir['third_party/java/{jetty,servlet-api}/*.jar']
17
+ ].flatten.each { |jar| require jar }
18
+
19
+
20
+ GlobalTestEnv = WebDriver::SpecSupport::JRubyTestEnvironment.new
21
+ else
22
+ GlobalTestEnv = WebDriver::SpecSupport::TestEnvironment.new
23
+ end
24
+
25
+ class Object
26
+ include WebDriver::SpecSupport::Guards
27
+ end
28
+
29
+ RSpec.configure do |c|
30
+ c.include(WebDriver::SpecSupport::Helpers)
31
+ c.before(:suite) do
32
+ if GlobalTestEnv.driver == :remote
33
+ GlobalTestEnv.remote_server.start
34
+ end
35
+ end
36
+
37
+ c.after(:suite) do
38
+ GlobalTestEnv.quit_driver
39
+ end
40
+ end
41
+
42
+ WebDriver::Platform.exit_hook { GlobalTestEnv.quit }
43
+
44
+ $stdout.sync = true
@@ -0,0 +1,13 @@
1
+ require 'selenium/server'
2
+ require 'selenium/webdriver/spec_support/test_environment'
3
+ require 'selenium/webdriver/spec_support/jruby_test_environment'
4
+ require 'selenium/webdriver/spec_support/guards'
5
+ require 'selenium/webdriver/spec_support/helpers'
6
+
7
+ module Selenium
8
+ module WebDriver
9
+ module SpecSupport
10
+ autoload :RackServer, 'selenium/webdriver/spec_support/rack_server'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,86 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module SpecSupport
4
+ module Guards
5
+
6
+ class << self
7
+ def guards
8
+ @guards ||= Hash.new { |hash, key| hash[key] = [] }
9
+ end
10
+
11
+ def record(guard_name, options, data)
12
+ options.each do |opts|
13
+ opts = current_env.merge(opts)
14
+ key = opts.values_at(:browser, :driver, :platform, :native).join('.')
15
+ guards[key] << [guard_name, data]
16
+ end
17
+ end
18
+
19
+ def report
20
+ key = [
21
+ GlobalTestEnv.browser,
22
+ GlobalTestEnv.driver,
23
+ Platform.os,
24
+ GlobalTestEnv.native_events?
25
+ ].join(".")
26
+
27
+ gs = guards[key]
28
+
29
+ print "\n\nSpec guards for this implementation: "
30
+
31
+ if gs.empty?
32
+ puts "none."
33
+ else
34
+ puts
35
+ gs.each do |guard_name, data|
36
+ puts "\t#{guard_name.to_s.ljust(20)}: #{data.inspect}"
37
+ end
38
+ end
39
+ end
40
+
41
+ def current_env
42
+ {
43
+ :browser => GlobalTestEnv.browser,
44
+ :driver => GlobalTestEnv.driver,
45
+ :platform => Platform.os,
46
+ :native => GlobalTestEnv.native_events?
47
+ }
48
+ end
49
+
50
+ #
51
+ # not_compliant_on :browser => [:firefox, :chrome]
52
+ # - guard this spec for both firefox and chrome
53
+ #
54
+ # not_compliant_on {:browser => :chrome, :platform => :macosx}, {:browser => :opera}
55
+ # - guard this spec for Chrome on OSX and Opera on any OS
56
+
57
+ def env_matches?(opts)
58
+ opts.any? { |env|
59
+ env.all? { |key, value|
60
+ if value.kind_of?(Array)
61
+ value.include? current_env[key]
62
+ else
63
+ value == current_env[key]
64
+ end
65
+ }
66
+ }
67
+ end
68
+ end
69
+
70
+ def not_compliant_on(*opts, &blk)
71
+ Guards.record(:not_compliant, opts, :file => caller.first)
72
+ yield unless Guards.env_matches?(opts)
73
+ end
74
+
75
+ def compliant_on(*opts, &blk)
76
+ Guards.record(:compliant_on, opts, :file => caller.first)
77
+ yield if Guards.env_matches?(opts)
78
+ end
79
+
80
+ alias_method :not_compliant_when, :not_compliant_on
81
+ alias_method :compliant_when, :compliant_on
82
+
83
+ end # Guards
84
+ end # SpecSupport
85
+ end # WebDriver
86
+ end # Selenium
@@ -0,0 +1,46 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module SpecSupport
4
+ module Helpers
5
+
6
+ def driver
7
+ GlobalTestEnv.driver_instance
8
+ end
9
+
10
+ def reset_driver!
11
+ GlobalTestEnv.reset_driver!
12
+ end
13
+
14
+ def url_for(filename)
15
+ GlobalTestEnv.url_for filename
16
+ end
17
+
18
+ def fix_windows_path(path)
19
+ return path unless WebDriver::Platform.os == :windows
20
+
21
+ if GlobalTestEnv.browser == :ie
22
+ path = path[%r[file://(.*)], 1]
23
+ path.gsub!("/", '\\')
24
+
25
+ "file://#{path}"
26
+ else
27
+ path.sub(%r[file:/{0,2}], "file:///")
28
+ end
29
+ end
30
+
31
+ def long_wait
32
+ @long_wait ||= Wait.new(:timeout => 30)
33
+ end
34
+
35
+ def short_wait
36
+ @short_wait ||= Wait.new(:timeout => 3)
37
+ end
38
+
39
+ def wait(timeout = 10)
40
+ Wait.new(:timeout => timeout)
41
+ end
42
+
43
+ end # Helpers
44
+ end # SpecSupport
45
+ end # WebDriver
46
+ end # Selenium
@@ -0,0 +1,29 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module SpecSupport
4
+ class JRubyTestEnvironment < TestEnvironment
5
+
6
+ def app_server
7
+ @app_server ||= in_process_test_environment.appServer
8
+ end
9
+
10
+ def url_for(filename)
11
+ app_server.whereIs filename
12
+ end
13
+
14
+ def quit
15
+ super
16
+ @in_process_test_environment.stop
17
+ @in_process_test_environment = nil
18
+ end
19
+
20
+ private
21
+
22
+ def in_process_test_environment
23
+ @in_process_test_environment ||= org.openqa.selenium.environment.InProcessTestEnvironment.new
24
+ end
25
+
26
+ end # JRubyTestEnvironmnet
27
+ end # SpecSupport
28
+ end # WebDriver
29
+ end # Selenium
@@ -0,0 +1,123 @@
1
+ require 'rack'
2
+ require 'socket'
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module SpecSupport
7
+ class RackServer
8
+
9
+ START_TIMEOUT = 30
10
+
11
+ def initialize(path, port = nil)
12
+ @path = path
13
+ @app = TestApp.new(path)
14
+
15
+ @host = "127.0.0.1"
16
+ @port = Integer(port || PortProber.above(8180))
17
+ end
18
+
19
+ def start
20
+ if Platform.jruby?
21
+ start_threaded
22
+ elsif Platform.windows?
23
+ start_windows
24
+ else
25
+ start_forked
26
+ end
27
+
28
+ unless SocketPoller.new(@host, @port, START_TIMEOUT).connected?
29
+ raise "rack server not launched in #{START_TIMEOUT} seconds"
30
+ end
31
+ end
32
+
33
+ def run
34
+ handler.run @app, :Host => @host, :Port => @port
35
+ end
36
+
37
+ def where_is(file)
38
+ "http://#{@host}:#{@port}/#{file}"
39
+ end
40
+
41
+ def stop
42
+ if defined?(@thread) && @thread
43
+ @thread.kill
44
+ elsif defined?(@pid) && @pid
45
+ Process.kill('KILL', @pid)
46
+ Process.waitpid(@pid)
47
+ elsif defined?(@process) && @process
48
+ @process.stop
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def handler
55
+ # can't use Platform here since it's being run as a file on Windows + IE.
56
+ if RUBY_PLATFORM =~ /mswin|msys|mingw32/
57
+ handlers = %w[mongrel webrick]
58
+ else
59
+ handlers = %w[thin mongrel webrick]
60
+ end
61
+
62
+ handler = handlers.find { |h| load_handler h }
63
+ constant = handler == 'webrick' ? "WEBrick" : handler.capitalize
64
+ Rack::Handler.const_get constant
65
+ end
66
+
67
+ def load_handler(handler)
68
+ require handler
69
+ true
70
+ rescue LoadError
71
+ false
72
+ end
73
+
74
+ def start_forked
75
+ @pid = fork { run }
76
+ end
77
+
78
+ def start_threaded
79
+ Thread.abort_on_exception = true
80
+ @thread = Thread.new { run }
81
+ sleep 0.5
82
+ end
83
+
84
+ def start_windows
85
+ if %w[ie internet_explorer].include? ENV['WD_SPEC_DRIVER']
86
+ # For IE, the combination of Windows + FFI + MRI seems to cause a
87
+ # deadlock with the get() call and the server thread.
88
+ # Workaround by running this file in a subprocess.
89
+ @process = ChildProcess.build("ruby", "-r", "rubygems", __FILE__, @path, @port).start
90
+ else
91
+ start_threaded
92
+ end
93
+ end
94
+
95
+ class TestApp
96
+ def initialize(file_root)
97
+ @static = Rack::File.new(file_root)
98
+ end
99
+
100
+ def call(env)
101
+ case env['REQUEST_PATH']
102
+ when "/common/upload"
103
+ req = Rack::Request.new(env)
104
+
105
+ status = 200
106
+ header = {"Content-Type" => "text/html"}
107
+ body = req['upload'][:tempfile].read
108
+
109
+ [status, header, [body]]
110
+ else
111
+ @static.call env
112
+ end
113
+ end
114
+ end
115
+
116
+ end # RackServer
117
+ end # SpecSupport
118
+ end # WebDriver
119
+ end # Selenium
120
+
121
+ if __FILE__ == $0
122
+ Selenium::WebDriver::SpecSupport::RackServer.new(ARGV[0], ARGV[1]).run
123
+ end