rainux-selenium-webdriver 0.0.17

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.
Files changed (192) hide show
  1. data/COPYING +204 -0
  2. data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
  3. data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
  4. data/chrome/src/extension/background.html +9 -0
  5. data/chrome/src/extension/background.js +995 -0
  6. data/chrome/src/extension/content_script.js +1321 -0
  7. data/chrome/src/extension/icons/busy.png +0 -0
  8. data/chrome/src/extension/icons/free.png +0 -0
  9. data/chrome/src/extension/manifest-nonwin.json +19 -0
  10. data/chrome/src/extension/manifest-win.json +20 -0
  11. data/chrome/src/extension/utils.js +231 -0
  12. data/chrome/src/rb/lib/selenium/webdriver/chrome.rb +8 -0
  13. data/chrome/src/rb/lib/selenium/webdriver/chrome/bridge.rb +358 -0
  14. data/chrome/src/rb/lib/selenium/webdriver/chrome/command_executor.rb +124 -0
  15. data/chrome/src/rb/lib/selenium/webdriver/chrome/launcher.rb +135 -0
  16. data/common/src/js/abstractcommandprocessor.js +134 -0
  17. data/common/src/js/asserts.js +296 -0
  18. data/common/src/js/by.js +149 -0
  19. data/common/src/js/command.js +304 -0
  20. data/common/src/js/context.js +58 -0
  21. data/common/src/js/core/Blank.html +7 -0
  22. data/common/src/js/core/InjectedRemoteRunner.html +8 -0
  23. data/common/src/js/core/RemoteRunner.html +101 -0
  24. data/common/src/js/core/SeleniumLog.html +109 -0
  25. data/common/src/js/core/TestPrompt.html +145 -0
  26. data/common/src/js/core/TestRunner-splash.html +55 -0
  27. data/common/src/js/core/TestRunner.html +165 -0
  28. data/common/src/js/core/icons/all.png +0 -0
  29. data/common/src/js/core/icons/continue.png +0 -0
  30. data/common/src/js/core/icons/continue_disabled.png +0 -0
  31. data/common/src/js/core/icons/pause.png +0 -0
  32. data/common/src/js/core/icons/pause_disabled.png +0 -0
  33. data/common/src/js/core/icons/selected.png +0 -0
  34. data/common/src/js/core/icons/step.png +0 -0
  35. data/common/src/js/core/icons/step_disabled.png +0 -0
  36. data/common/src/js/core/lib/cssQuery/cssQuery-p.js +6 -0
  37. data/common/src/js/core/lib/cssQuery/src/cssQuery-level2.js +142 -0
  38. data/common/src/js/core/lib/cssQuery/src/cssQuery-level3.js +150 -0
  39. data/common/src/js/core/lib/cssQuery/src/cssQuery-standard.js +53 -0
  40. data/common/src/js/core/lib/cssQuery/src/cssQuery.js +356 -0
  41. data/common/src/js/core/lib/prototype.js +2006 -0
  42. data/common/src/js/core/lib/scriptaculous/builder.js +101 -0
  43. data/common/src/js/core/lib/scriptaculous/controls.js +815 -0
  44. data/common/src/js/core/lib/scriptaculous/dragdrop.js +915 -0
  45. data/common/src/js/core/lib/scriptaculous/effects.js +958 -0
  46. data/common/src/js/core/lib/scriptaculous/scriptaculous.js +47 -0
  47. data/common/src/js/core/lib/scriptaculous/slider.js +283 -0
  48. data/common/src/js/core/lib/scriptaculous/unittest.js +383 -0
  49. data/common/src/js/core/lib/snapsie.js +91 -0
  50. data/common/src/js/core/scripts/find_matching_child.js +69 -0
  51. data/common/src/js/core/scripts/htmlutils.js +8716 -0
  52. data/common/src/js/core/scripts/injection.html +72 -0
  53. data/common/src/js/core/scripts/selenium-api.js +3291 -0
  54. data/common/src/js/core/scripts/selenium-browserbot.js +2457 -0
  55. data/common/src/js/core/scripts/selenium-browserdetect.js +153 -0
  56. data/common/src/js/core/scripts/selenium-commandhandlers.js +379 -0
  57. data/common/src/js/core/scripts/selenium-executionloop.js +175 -0
  58. data/common/src/js/core/scripts/selenium-logging.js +148 -0
  59. data/common/src/js/core/scripts/selenium-remoterunner.js +695 -0
  60. data/common/src/js/core/scripts/selenium-testrunner.js +1362 -0
  61. data/common/src/js/core/scripts/selenium-version.js +5 -0
  62. data/common/src/js/core/scripts/ui-doc.html +808 -0
  63. data/common/src/js/core/scripts/ui-element.js +1644 -0
  64. data/common/src/js/core/scripts/ui-map-sample.js +979 -0
  65. data/common/src/js/core/scripts/user-extensions.js +3 -0
  66. data/common/src/js/core/scripts/user-extensions.js.sample +75 -0
  67. data/common/src/js/core/scripts/xmlextras.js +153 -0
  68. data/common/src/js/core/selenium-logo.png +0 -0
  69. data/common/src/js/core/selenium-test.css +43 -0
  70. data/common/src/js/core/selenium.css +316 -0
  71. data/common/src/js/core/xpath/dom.js +566 -0
  72. data/common/src/js/core/xpath/javascript-xpath-0.1.11.js +2816 -0
  73. data/common/src/js/core/xpath/util.js +549 -0
  74. data/common/src/js/core/xpath/xmltoken.js +149 -0
  75. data/common/src/js/core/xpath/xpath.js +2481 -0
  76. data/common/src/js/extension/README +2 -0
  77. data/common/src/js/extension/dommessenger.js +152 -0
  78. data/common/src/js/factory.js +55 -0
  79. data/common/src/js/future.js +141 -0
  80. data/common/src/js/jsunit.js +40 -0
  81. data/common/src/js/jsunit/app/css/jsUnitStyle.css +50 -0
  82. data/common/src/js/jsunit/app/css/readme +10 -0
  83. data/common/src/js/jsunit/app/emptyPage.html +11 -0
  84. data/common/src/js/jsunit/app/jsUnitCore.js +534 -0
  85. data/common/src/js/jsunit/app/jsUnitMockTimeout.js +81 -0
  86. data/common/src/js/jsunit/app/jsUnitTestManager.js +705 -0
  87. data/common/src/js/jsunit/app/jsUnitTestSuite.js +44 -0
  88. data/common/src/js/jsunit/app/jsUnitTracer.js +102 -0
  89. data/common/src/js/jsunit/app/jsUnitVersionCheck.js +59 -0
  90. data/common/src/js/jsunit/app/main-counts-errors.html +12 -0
  91. data/common/src/js/jsunit/app/main-counts-failures.html +13 -0
  92. data/common/src/js/jsunit/app/main-counts-runs.html +13 -0
  93. data/common/src/js/jsunit/app/main-counts.html +21 -0
  94. data/common/src/js/jsunit/app/main-data.html +178 -0
  95. data/common/src/js/jsunit/app/main-errors.html +23 -0
  96. data/common/src/js/jsunit/app/main-frame.html +19 -0
  97. data/common/src/js/jsunit/app/main-loader.html +45 -0
  98. data/common/src/js/jsunit/app/main-progress.html +25 -0
  99. data/common/src/js/jsunit/app/main-results.html +67 -0
  100. data/common/src/js/jsunit/app/main-status.html +13 -0
  101. data/common/src/js/jsunit/app/testContainer.html +16 -0
  102. data/common/src/js/jsunit/app/testContainerController.html +77 -0
  103. data/common/src/js/jsunit/app/xbDebug.js +306 -0
  104. data/common/src/js/jsunit/changelog.txt +60 -0
  105. data/common/src/js/jsunit/css/jsUnitStyle.css +83 -0
  106. data/common/src/js/jsunit/images/green.gif +0 -0
  107. data/common/src/js/jsunit/images/logo_jsunit.gif +0 -0
  108. data/common/src/js/jsunit/images/powerby-transparent.gif +0 -0
  109. data/common/src/js/jsunit/images/red.gif +0 -0
  110. data/common/src/js/jsunit/licenses/JDOM_license.txt +56 -0
  111. data/common/src/js/jsunit/licenses/Jetty_license.html +213 -0
  112. data/common/src/js/jsunit/licenses/MPL-1.1.txt +470 -0
  113. data/common/src/js/jsunit/licenses/gpl-2.txt +340 -0
  114. data/common/src/js/jsunit/licenses/index.html +141 -0
  115. data/common/src/js/jsunit/licenses/lgpl-2.1.txt +504 -0
  116. data/common/src/js/jsunit/licenses/mpl-tri-license-c.txt +35 -0
  117. data/common/src/js/jsunit/licenses/mpl-tri-license-html.txt +35 -0
  118. data/common/src/js/jsunit/readme.txt +19 -0
  119. data/common/src/js/jsunit/testRunner.html +167 -0
  120. data/common/src/js/jsunit/version.txt +1 -0
  121. data/common/src/js/key.js +117 -0
  122. data/common/src/js/localcommandprocessor.js +185 -0
  123. data/common/src/js/testcase.js +217 -0
  124. data/common/src/js/timing.js +89 -0
  125. data/common/src/js/webdriver.js +890 -0
  126. data/common/src/js/webelement.js +485 -0
  127. data/common/src/rb/README +30 -0
  128. data/common/src/rb/lib/selenium-webdriver.rb +1 -0
  129. data/common/src/rb/lib/selenium/webdriver.rb +67 -0
  130. data/common/src/rb/lib/selenium/webdriver/bridge_helper.rb +91 -0
  131. data/common/src/rb/lib/selenium/webdriver/child_process.rb +180 -0
  132. data/common/src/rb/lib/selenium/webdriver/core_ext/dir.rb +41 -0
  133. data/common/src/rb/lib/selenium/webdriver/driver.rb +252 -0
  134. data/common/src/rb/lib/selenium/webdriver/driver_extensions/takes_screenshot.rb +24 -0
  135. data/common/src/rb/lib/selenium/webdriver/element.rb +262 -0
  136. data/common/src/rb/lib/selenium/webdriver/error.rb +67 -0
  137. data/common/src/rb/lib/selenium/webdriver/find.rb +89 -0
  138. data/common/src/rb/lib/selenium/webdriver/keys.rb +84 -0
  139. data/common/src/rb/lib/selenium/webdriver/navigation.rb +27 -0
  140. data/common/src/rb/lib/selenium/webdriver/options.rb +50 -0
  141. data/common/src/rb/lib/selenium/webdriver/platform.rb +86 -0
  142. data/common/src/rb/lib/selenium/webdriver/target_locator.rb +70 -0
  143. data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
  144. data/firefox/prebuilt/linux/Release/libwebdriver-firefox.so +0 -0
  145. data/firefox/prebuilt/linux/Release/x_ignore_nofocus.so +0 -0
  146. data/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so +0 -0
  147. data/firefox/prebuilt/linux64/Release/x_ignore_nofocus.so +0 -0
  148. data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
  149. data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
  150. data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
  151. data/firefox/src/extension/chrome.manifest +3 -0
  152. data/firefox/src/extension/components/badCertListener.js +294 -0
  153. data/firefox/src/extension/components/context.js +37 -0
  154. data/firefox/src/extension/components/driver-component.js +127 -0
  155. data/firefox/src/extension/components/firefoxDriver.js +810 -0
  156. data/firefox/src/extension/components/json2.js +273 -0
  157. data/firefox/src/extension/components/keytest.html +554 -0
  158. data/firefox/src/extension/components/nsCommandProcessor.js +643 -0
  159. data/firefox/src/extension/components/promptService.js +208 -0
  160. data/firefox/src/extension/components/screenshooter.js +81 -0
  161. data/firefox/src/extension/components/socketListener.js +185 -0
  162. data/firefox/src/extension/components/utils.js +1263 -0
  163. data/firefox/src/extension/components/webLoadingListener.js +57 -0
  164. data/firefox/src/extension/components/webdriverserver.js +106 -0
  165. data/firefox/src/extension/components/wrappedElement.js +683 -0
  166. data/firefox/src/extension/content/fxdriver.xul +30 -0
  167. data/firefox/src/extension/content/server.js +95 -0
  168. data/firefox/src/extension/idl/nsICommandProcessor.idl +38 -0
  169. data/firefox/src/extension/idl/nsIResponseHandler.idl +34 -0
  170. data/firefox/src/extension/install.rdf +29 -0
  171. data/firefox/src/rb/lib/selenium/webdriver/firefox.rb +31 -0
  172. data/firefox/src/rb/lib/selenium/webdriver/firefox/binary.rb +107 -0
  173. data/firefox/src/rb/lib/selenium/webdriver/firefox/bridge.rb +484 -0
  174. data/firefox/src/rb/lib/selenium/webdriver/firefox/extension_connection.rb +90 -0
  175. data/firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb +155 -0
  176. data/firefox/src/rb/lib/selenium/webdriver/firefox/profile.rb +233 -0
  177. data/firefox/src/rb/lib/selenium/webdriver/firefox/profiles_ini.rb +59 -0
  178. data/firefox/src/rb/lib/selenium/webdriver/firefox/util.rb +23 -0
  179. data/jobbie/prebuilt/Win32/Release/InternetExplorerDriver.dll +0 -0
  180. data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
  181. data/jobbie/src/rb/lib/selenium/webdriver/ie.rb +14 -0
  182. data/jobbie/src/rb/lib/selenium/webdriver/ie/bridge.rb +565 -0
  183. data/jobbie/src/rb/lib/selenium/webdriver/ie/lib.rb +99 -0
  184. data/jobbie/src/rb/lib/selenium/webdriver/ie/util.rb +147 -0
  185. data/remote/client/src/rb/lib/selenium/webdriver/remote.rb +16 -0
  186. data/remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb +408 -0
  187. data/remote/client/src/rb/lib/selenium/webdriver/remote/capabilities.rb +105 -0
  188. data/remote/client/src/rb/lib/selenium/webdriver/remote/commands.rb +53 -0
  189. data/remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb +71 -0
  190. data/remote/client/src/rb/lib/selenium/webdriver/remote/response.rb +49 -0
  191. data/remote/client/src/rb/lib/selenium/webdriver/remote/server_error.rb +32 -0
  192. metadata +303 -0
@@ -0,0 +1,30 @@
1
+ = selenium-webdriver
2
+
3
+ This gem provides Ruby bindings for WebDriver and has been tested to work on MRI (1.8.6 through 1.9), JRuby and Rubinius.
4
+
5
+ = INSTALL
6
+
7
+ gem install selenium-webdriver
8
+
9
+ = LINKS
10
+
11
+ * http://gemcutter.org/gems/selenium-webdriver
12
+ * http://selenium.googlecode.com/svn/trunk/docs/api/rb/index.html
13
+ * http://code.google.com/p/selenium/wiki/RubyBindings
14
+ * http://code.google.com/p/selenium/issues/list
15
+
16
+ = LICENSE
17
+
18
+ Copyright 2009 WebDriver committers
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
@@ -0,0 +1 @@
1
+ require "selenium/webdriver"
@@ -0,0 +1,67 @@
1
+ require "tmpdir"
2
+ require "fileutils"
3
+
4
+ def have_yajl?
5
+ require "yajl/json_gem"
6
+ true
7
+ rescue LoadError
8
+ false
9
+ end
10
+
11
+ def have_json?
12
+ require "json"
13
+ true
14
+ rescue LoadError
15
+ false
16
+ end
17
+
18
+ unless have_yajl? || have_json?
19
+ raise LoadError, <<-END
20
+
21
+ You need to require rubygems or install one of these gems:
22
+
23
+ yajl-ruby (best on MRI)
24
+ json
25
+ json-jruby (native JRuby)
26
+ json_pure (any platform)
27
+
28
+ END
29
+ end
30
+
31
+
32
+ require "selenium/webdriver/core_ext/dir"
33
+ require "selenium/webdriver/error"
34
+ require "selenium/webdriver/platform"
35
+ require "selenium/webdriver/child_process"
36
+ require "selenium/webdriver/target_locator"
37
+ require "selenium/webdriver/navigation"
38
+ require "selenium/webdriver/options"
39
+ require "selenium/webdriver/find"
40
+ require "selenium/webdriver/driver_extensions/takes_screenshot"
41
+ require "selenium/webdriver/keys"
42
+ require "selenium/webdriver/bridge_helper"
43
+ require "selenium/webdriver/driver"
44
+ require "selenium/webdriver/element"
45
+
46
+ module Selenium
47
+ module WebDriver
48
+ Point = Struct.new(:x, :y)
49
+ Dimension = Struct.new(:width, :heigth)
50
+
51
+ autoload :IE, 'selenium/webdriver/ie'
52
+ autoload :Remote, 'selenium/webdriver/remote'
53
+ autoload :Chrome, 'selenium/webdriver/chrome'
54
+ autoload :Firefox, 'selenium/webdriver/firefox'
55
+
56
+ def self.root
57
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", ".."))
58
+ end
59
+
60
+ def self.for(*args)
61
+ WebDriver::Driver.for(*args)
62
+ end
63
+
64
+ end # WebDriver
65
+ end # Selenium
66
+
67
+ Thread.abort_on_exception = true
@@ -0,0 +1,91 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # Shared across bridges
6
+ #
7
+
8
+ module BridgeHelper
9
+
10
+ def wrap_script_argument(arg)
11
+ case arg
12
+ when Integer, Float
13
+ { :type => "NUMBER", :value => arg }
14
+ when TrueClass, FalseClass, NilClass
15
+ { :type => "BOOLEAN", :value => !!arg }
16
+ when Element
17
+ { :type => "ELEMENT", :value => arg.ref }
18
+ when String
19
+ { :type => "STRING", :value => arg.to_s }
20
+ when Array # Enumerable?
21
+ arg.map { |e| wrap_script_argument(e) }
22
+ else
23
+ raise TypeError, "Parameter is not of recognized type: #{arg.inspect}:#{arg.class}"
24
+ end
25
+ end
26
+
27
+ def unwrap_script_argument(arg)
28
+ if arg.kind_of?(Array)
29
+ arg.map { |e| unwrap_script_argument(e) }
30
+ else
31
+ case arg["type"]
32
+ when "NULL"
33
+ nil
34
+ when "ELEMENT"
35
+ Element.new self, element_id_from(arg["value"])
36
+ when "POINT"
37
+ Point.new arg['x'], arg['y']
38
+ when "DIMENSION"
39
+ Dimension.new arg['width'], arg['height']
40
+ when "COOKIE"
41
+ {:name => arg['name'], :value => arg['value']}
42
+ else
43
+ arg["value"]
44
+ end
45
+ end
46
+ end
47
+
48
+ def element_id_from(id)
49
+ str = id.kind_of?(Array) ? id.first : id
50
+ after = str.split("/").last
51
+
52
+ after
53
+ end
54
+
55
+ def parse_cookie_string(str)
56
+ result = {
57
+ 'name' => '',
58
+ 'value' => '',
59
+ 'domain' => '',
60
+ 'path' => '',
61
+ 'expires' => '',
62
+ 'secure' => false
63
+ }
64
+
65
+ str.split(";").each do |attribute|
66
+ if attribute.include? "="
67
+ key, value = attribute.strip.split("=", 2)
68
+ if result['name'].empty?
69
+ result['name'] = key
70
+ result['value'] = value
71
+ elsif key == 'domain' && value.strip =~ /^\.(.+)/
72
+ result['domain'] = $1
73
+ elsif key && value
74
+ result[key] = value
75
+ end
76
+ elsif attribute == "secure"
77
+ result['secure'] = true
78
+ end
79
+
80
+ unless [nil, "", "0"].include?(result['expires'])
81
+ # firefox stores expiry as number of seconds
82
+ result['expires'] = Time.at(result['expires'].to_i)
83
+ end
84
+ end
85
+
86
+ result
87
+ end
88
+
89
+ end # BridgeHelper
90
+ end # WebDriver
91
+ end # Selenium
@@ -0,0 +1,180 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # Cross platform child process launcher
6
+ #
7
+
8
+ class ChildProcess
9
+ attr_reader :pid
10
+
11
+ def initialize(*args)
12
+ @args = args
13
+
14
+ if Platform.jruby?
15
+ extend JRubyProcess
16
+ elsif Platform.ironruby?
17
+ extend IronRubyProcess
18
+ elsif Platform.os == :windows
19
+ extend WindowsProcess
20
+ end
21
+ end
22
+
23
+ def ugly_death?
24
+ code = exit_value()
25
+ # if exit_val is nil, the process is still alive
26
+ code && code != 0
27
+ end
28
+
29
+ def exit_value
30
+ pid, status = Process.waitpid2(@pid, Process::WNOHANG)
31
+ status.exitstatus if pid
32
+ end
33
+
34
+ def start
35
+ @pid = fork do
36
+ unless $DEBUG
37
+ [STDOUT, STDERR].each { |io| io.reopen("/dev/null") }
38
+ end
39
+
40
+ exec(*@args)
41
+ end
42
+
43
+ self
44
+ end
45
+
46
+ def wait
47
+ assert_started
48
+ Process.waitpid2 @pid
49
+ rescue Errno::ECHILD
50
+ nil
51
+ end
52
+
53
+ def kill
54
+ assert_started
55
+ Process.kill('TERM', @pid)
56
+ end
57
+
58
+ def kill!
59
+ assert_started
60
+ Process.kill('KILL', @pid)
61
+ end
62
+
63
+ def assert_started
64
+ raise Error::WebDriverError, "process not started" unless @pid
65
+ end
66
+
67
+ module WindowsProcess
68
+ def start
69
+ require "win32/process" # adds a dependency on windows - perhaps we could just use FFI instead?
70
+ @pid = Process.create(
71
+ :app_name => @args.join(" "),
72
+ :inherit => false # don't inherit open file handles
73
+ ).process_id
74
+
75
+ self
76
+ end
77
+
78
+ def kill
79
+ kill!
80
+ end
81
+ end
82
+
83
+ module JRubyProcess
84
+ def start
85
+ pb = java.lang.ProcessBuilder.new(@args)
86
+
87
+ env = pb.environment
88
+ ENV.each { |k,v| env.put(k, v) }
89
+
90
+ @process = pb.start
91
+
92
+ # Firefox 3.6 on Snow Leopard has a lot output on stderr, which makes
93
+ # the launch act funny if we don't do something to the streams
94
+
95
+ @process.getErrorStream.close
96
+ @process.getInputStream.close
97
+
98
+ # Closing the streams solves that problem, but on other platforms we might
99
+ # need to actually read them.
100
+
101
+ # Thread.new do
102
+ # input, error = 0, 0
103
+ # loop do
104
+ # error = @process.getErrorStream.read if error != -1
105
+ # input = @process.getInputStream.read if input != -1
106
+ # break if error == -1 && input == -1
107
+ # end
108
+ # end
109
+
110
+ self
111
+ end
112
+
113
+ def kill
114
+ assert_started
115
+ @process.destroy
116
+ end
117
+ alias_method :kill!, :kill
118
+
119
+ def wait
120
+ assert_started
121
+ @process.waitFor
122
+ [nil, @process.exitValue] # no robust way to get pid here
123
+ end
124
+
125
+ def exit_value
126
+ assert_started
127
+ @process.exitValue
128
+ rescue java.lang.IllegalThreadStateException
129
+ nil
130
+ end
131
+
132
+ def assert_started
133
+ raise Error::WebDriverError, "process not started" unless @process
134
+ end
135
+ end
136
+
137
+ module IronRubyProcess
138
+ def start
139
+ args = @args.dup
140
+
141
+ @process = System::Diagnostics::Process.new
142
+ @process.StartInfo.UseShellExecute = true
143
+ @process.StartInfo.FileName = args.shift
144
+ @process.StartInfo.Arguments = args.join ' '
145
+ @process.start
146
+
147
+ self
148
+ end
149
+
150
+ def kill
151
+ assert_started
152
+ @process.Kill
153
+ end
154
+
155
+ def wait
156
+ assert_started
157
+ @process.WaitForExit
158
+ [pid, exit_value]
159
+ end
160
+
161
+ def pid
162
+ assert_started
163
+ @process.Id
164
+ end
165
+
166
+ def exit_value
167
+ assert_started
168
+ return unless @process.HasExited
169
+
170
+ @process.ExitCode
171
+ end
172
+
173
+ def assert_started
174
+ raise Error::WebDriverError, "process not started" unless @process
175
+ end
176
+ end
177
+
178
+ end # ChildProcess
179
+ end # WebDriver
180
+ end # Selenium
@@ -0,0 +1,41 @@
1
+ class Dir
2
+ def self.mktmpdir(prefix_suffix=nil, tmpdir=nil)
3
+ case prefix_suffix
4
+ when nil
5
+ prefix = "d"
6
+ suffix = ""
7
+ when String
8
+ prefix = prefix_suffix
9
+ suffix = ""
10
+ when Array
11
+ prefix = prefix_suffix[0]
12
+ suffix = prefix_suffix[1]
13
+ else
14
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
15
+ end
16
+ tmpdir ||= Dir.tmpdir
17
+ t = Time.now.strftime("%Y%m%d")
18
+ n = nil
19
+ begin
20
+ path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
21
+ path << "-#{n}" if n
22
+ path << suffix
23
+ Dir.mkdir(path, 0700)
24
+ rescue Errno::EEXIST
25
+ n ||= 0
26
+ n += 1
27
+ retry
28
+ end
29
+
30
+ if block_given?
31
+ begin
32
+ yield path
33
+ ensure
34
+ FileUtils.remove_entry_secure path
35
+ end
36
+ else
37
+ path
38
+ end
39
+ end unless respond_to? :mktmpdir # > 1.8.7
40
+ end
41
+
@@ -0,0 +1,252 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # The main class through which you control the browser.
6
+ #
7
+ # @see Find
8
+ # @see Navigation
9
+ # @see TargetLocator
10
+ # @see Options
11
+ #
12
+
13
+ class Driver
14
+ include Find
15
+
16
+ attr_reader :bridge
17
+
18
+ class << self
19
+
20
+ #
21
+ # Create a new Driver instance with the correct bridge for the given browser
22
+ #
23
+ # @param browser [Symbol]
24
+ # the driver type to use
25
+ # @param *rest
26
+ # arguments passed to the Bridge.new
27
+ #
28
+ # @return [Driver]
29
+ #
30
+
31
+ def for(browser, *args)
32
+ bridge = case browser
33
+ when :ie, :internet_explorer
34
+ WebDriver::IE::Bridge.new(*args)
35
+ when :remote
36
+ WebDriver::Remote::Bridge.new(*args)
37
+ when :chrome
38
+ WebDriver::Chrome::Bridge.new(*args)
39
+ when :firefox, :ff
40
+ WebDriver::Firefox::Bridge.new(*args)
41
+ else
42
+ raise ArgumentError, "unknown driver: #{browser.inspect}"
43
+ end
44
+
45
+ driver = new(bridge)
46
+
47
+ unless bridge.driver_extensions.empty?
48
+ driver.extend(*bridge.driver_extensions)
49
+ end
50
+
51
+ driver
52
+ end
53
+ end
54
+
55
+ #
56
+ # A new Driver instance
57
+ #
58
+ # @api private
59
+ #
60
+
61
+ def initialize(bridge)
62
+ @bridge = bridge
63
+ end
64
+
65
+ def inspect
66
+ '#<%s:0x%x browser=%s>' % [self.class, hash*2, bridge.browser.inspect]
67
+ end
68
+
69
+ #
70
+ # @return [Navigation]
71
+ # @see Navigation
72
+ #
73
+
74
+ def navigate
75
+ @navigate ||= WebDriver::Navigation.new(self)
76
+ end
77
+
78
+ #
79
+ # @return [TargetLocator]
80
+ # @see TargetLocator
81
+ #
82
+
83
+ def switch_to
84
+ @switch_to ||= WebDriver::TargetLocator.new(self)
85
+ end
86
+
87
+ #
88
+ # @return [Options]
89
+ # @see Options
90
+ #
91
+
92
+ def manage
93
+ @manage ||= WebDriver::Options.new(self)
94
+ end
95
+
96
+ #
97
+ # Opens the specified URL in the browser.
98
+ #
99
+
100
+ def get(url)
101
+ navigate.to(url)
102
+ end
103
+
104
+ #
105
+ # Get the URL of the current page
106
+ #
107
+ # @return [String]
108
+ #
109
+
110
+ def current_url
111
+ bridge.getCurrentUrl
112
+ end
113
+
114
+ #
115
+ # Get the title of the current page
116
+ #
117
+ # @return [String]
118
+ #
119
+
120
+ def title
121
+ bridge.getTitle
122
+ end
123
+
124
+ #
125
+ # Get the source of the current page
126
+ #
127
+ # @return [String]
128
+ #
129
+
130
+ def page_source
131
+ bridge.getPageSource
132
+ end
133
+
134
+ #
135
+ # Get the visibility of the browser. Not applicable for all browsers.
136
+ #
137
+ # @return [Boolean]
138
+ #
139
+
140
+ def visible?
141
+ bridge.getBrowserVisible
142
+ end
143
+
144
+ #
145
+ # Set the visibility of the browser. Not applicable for all browsers.
146
+ #
147
+ # @param [Boolean]
148
+ #
149
+
150
+ def visible=(bool)
151
+ bridge.setBrowserVisible bool
152
+ end
153
+
154
+ #
155
+ # Quit the browser
156
+ #
157
+
158
+ def quit
159
+ bridge.quit
160
+ end
161
+
162
+ #
163
+ # Close the current window, or the browser if no windows are left.
164
+ #
165
+
166
+ def close
167
+ bridge.close
168
+ end
169
+
170
+ #
171
+ # Get the window handles of open browser windows.
172
+ #
173
+ # @return [Array]
174
+ # @see TargetLocator#window
175
+ #
176
+
177
+ def window_handles
178
+ bridge.getWindowHandles
179
+ end
180
+
181
+ #
182
+ # Get the current window handle
183
+ #
184
+ # @return [String]
185
+ #
186
+
187
+ def window_handle
188
+ bridge.getCurrentWindowHandle
189
+ end
190
+
191
+ #
192
+ # Execute the given JavaScript
193
+ #
194
+ # @param [String] script
195
+ # JavaScript source to execute
196
+ # @param [WebDriver::Element,Integer, Float, Boolean, NilClass, String, Array] *args
197
+ # Arguments will be available in the given script as the 'arguments' array.
198
+ #
199
+ # @return [WebDriver::Element,Integer,Float,Boolean,NilClass,String,Array]
200
+ # The value returned from the script.
201
+ #
202
+
203
+ def execute_script(script, *args)
204
+ bridge.executeScript(script, *args)
205
+ end
206
+
207
+ #-------------------------------- sugar --------------------------------
208
+
209
+ #
210
+ # driver.first(:id, 'foo')
211
+ #
212
+
213
+ alias_method :first, :find_element
214
+
215
+ #
216
+ # driver.all(:class, 'bar') #=> [#<WebDriver::Element:0x1011c3b88, ...]
217
+ #
218
+
219
+ alias_method :all, :find_elements
220
+
221
+ #
222
+ # driver.script('function() { ... };')
223
+ #
224
+
225
+ alias_method :script, :execute_script
226
+
227
+ # Get the first element matching the given id.
228
+ #
229
+ # @param [String] id
230
+ # @return [WebDriver::Element]
231
+ #
232
+ # driver['someElementId'] #=> #<WebDriver::Element:0x1011c3b88>
233
+ #
234
+
235
+ def [](id)
236
+ find_element :id, id
237
+ end
238
+
239
+
240
+ #
241
+ # for Find
242
+ #
243
+ # @api private
244
+ #
245
+
246
+ def ref
247
+ nil
248
+ end
249
+
250
+ end # Driver
251
+ end # WebDriver
252
+ end # Selenium