rainux-selenium-webdriver 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
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,124 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Chrome
4
+ class CommandExecutor
5
+ HTML_TEMPLATE = "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s"
6
+ JSON_TEMPLATE = "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n%s"
7
+
8
+ def initialize
9
+ @server = TCPServer.new(localhost, 0)
10
+ @queue = Queue.new
11
+
12
+ @accepted_any = false
13
+ @next_socket = nil
14
+ @listening = true
15
+
16
+ Thread.new { start_run_loop }
17
+ end
18
+
19
+ def execute(command)
20
+ until accepted_any?
21
+ Thread.pass
22
+ sleep 0.01
23
+ end
24
+
25
+ json = command.to_json
26
+ data = JSON_TEMPLATE % [json.length, json]
27
+
28
+ @next_socket.write data
29
+ @next_socket.close
30
+
31
+ JSON.parse read_response(@queue.pop)
32
+ end
33
+
34
+ def close
35
+ stop_listening
36
+ close_sockets
37
+ @server.close unless @server.closed?
38
+ rescue IOError
39
+ nil
40
+ end
41
+
42
+ def port
43
+ @server.addr[1]
44
+ end
45
+
46
+ def uri
47
+ "http://localhost:#{port}/chromeCommandExecutor"
48
+ end
49
+
50
+ private
51
+
52
+ def localhost
53
+ Platform.ironruby? ? "localhost" : "0.0.0.0" # yeah, weird..
54
+ end
55
+
56
+ def start_run_loop
57
+ while(@listening) do
58
+ socket = @server.accept
59
+
60
+ if socket.read(1) == "G" # initial GET(s)
61
+ write_holding_page_to socket
62
+ else
63
+ if accepted_any?
64
+ @queue << socket
65
+ else
66
+ read_response(socket)
67
+ @accepted_any = true
68
+ end
69
+ end
70
+ end
71
+ rescue IOError, Errno::EBADF
72
+ raise unless @server.closed?
73
+ end
74
+
75
+ def read_response(socket)
76
+ result = ''
77
+ seen_double_crlf = false
78
+
79
+ while line = next_line(socket)
80
+ seen_double_crlf = true if line.empty?
81
+ result << "#{line}\n" if seen_double_crlf
82
+ end
83
+
84
+ @next_socket = socket
85
+
86
+ result.strip!
87
+ end
88
+
89
+ def accepted_any?
90
+ @accepted_any
91
+ end
92
+
93
+ def close_sockets
94
+ @queue.pop.close until @queue.empty?
95
+ @next_socket.close if @next_socket
96
+ end
97
+
98
+ def stop_listening
99
+ @listening = false
100
+ end
101
+
102
+ def next_line(socket)
103
+ return if socket.closed?
104
+ input = socket.gets
105
+
106
+ raise Error::WebDriverError, "unexpected EOF from Chrome" if input.nil?
107
+
108
+ line = input.chomp
109
+ return if line == "EOResponse"
110
+
111
+ line
112
+ end
113
+
114
+ def write_holding_page_to(socket)
115
+ msg = %[<html><head><script type='text/javascript'>if (window.location.search == '') { setTimeout("window.location = window.location.href + '?reloaded'", 5000); }</script></head><body><p>ChromeDriver server started and connected. Please leave this tab open.</p></body></html>]
116
+
117
+ socket.write HTML_TEMPLATE % [msg.length, msg]
118
+ socket.close
119
+ end
120
+
121
+ end # CommandExecutor
122
+ end # Chrome
123
+ end # WebDriver
124
+ end # Selenium
@@ -0,0 +1,135 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Chrome
4
+ class Launcher
5
+ include FileUtils
6
+
7
+ attr_reader :pid
8
+
9
+ def self.launcher
10
+ launcher = case Platform.os
11
+ when :windows
12
+ WindowsLauncher.new
13
+ when :macosx
14
+ MacOSXLauncher.new
15
+ when :unix, :linux
16
+ UnixLauncher.new
17
+ else
18
+ raise "unknown OS: #{Platform.os}"
19
+ end
20
+
21
+ launcher
22
+ end
23
+
24
+ def launch(server_url)
25
+ create_extension
26
+ create_profile
27
+ launch_chrome server_url
28
+
29
+ pid
30
+ end
31
+
32
+ def kill
33
+ @process.kill
34
+ end
35
+
36
+ private
37
+
38
+ def create_extension
39
+ # TODO: find a better way to do this
40
+ rm_rf tmp_extension_dir
41
+ mkdir_p File.dirname(tmp_extension_dir), :mode => 0700
42
+ cp_r ext_path, tmp_extension_dir
43
+
44
+ if Platform.win?
45
+ cp linked_lib_path, tmp_extension_dir
46
+ mv "#{tmp_extension_dir}/manifest-win.json", "#{tmp_extension_dir}/manifest.json"
47
+ else
48
+ mv "#{tmp_extension_dir}/manifest-nonwin.json", "#{tmp_extension_dir}/manifest.json"
49
+ end
50
+ end
51
+
52
+ def create_profile
53
+ touch "#{tmp_profile_dir}/First Run"
54
+ touch "#{tmp_profile_dir}/First Run Dev"
55
+ end
56
+
57
+ def launch_chrome(server_url)
58
+ check_binary_exists
59
+ @process = ChildProcess.new Platform.wrap_in_quotes_if_necessary(binary_path),
60
+ "--load-extension=#{Platform.wrap_in_quotes_if_necessary tmp_extension_dir}",
61
+ "--user-data-dir=#{Platform.wrap_in_quotes_if_necessary tmp_profile_dir}",
62
+ "--activate-on-launch",
63
+ "--disable-hang-monitor",
64
+ "--disable-popup-blocking",
65
+ "--disable-prompt-on-repost",
66
+ server_url
67
+ @process.start
68
+ end
69
+
70
+ def check_binary_exists
71
+ unless File.file?(binary_path)
72
+ raise Error::WebDriverError, "Could not find Chrome binary. Make sure Chrome is installed (OS: #{Platform.os})"
73
+ end
74
+ end
75
+
76
+ def ext_path
77
+ @ext_path ||= "#{WebDriver.root}/chrome/src/extension"
78
+ end
79
+
80
+ def tmp_extension_dir
81
+ @tmp_extension_dir ||= begin
82
+ dir = Dir.mktmpdir("webdriver-chrome-extension")
83
+ Platform.make_writable(dir)
84
+
85
+ dir
86
+ end
87
+ end
88
+
89
+ def tmp_profile_dir
90
+ @tmp_profile_dir ||= begin
91
+ dir = Dir.mktmpdir("webdriver-chrome-profile")
92
+ Platform.make_writable(dir)
93
+
94
+ dir
95
+ end
96
+ end
97
+
98
+ class WindowsLauncher < Launcher
99
+ def linked_lib_path
100
+ # TODO: x64
101
+ @linked_lib_path ||= "#{WebDriver.root}/chrome/prebuilt/Win32/Release/npchromedriver.dll"
102
+ end
103
+
104
+ def binary_path
105
+ @binary_path ||= begin
106
+ possible_paths = [
107
+ "#{ENV['USERPROFILE']}\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe",
108
+ "#{ENV['USERPROFILE']}\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe",
109
+ "#{Platform.home}\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe",
110
+ "#{Platform.home}\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe",
111
+ ]
112
+
113
+ possible_paths.find { |f| File.exist?(f) } || possible_paths.first
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ class UnixLauncher < Launcher
120
+ def binary_path
121
+ @binary_path ||= "/usr/bin/google-chrome"
122
+ end
123
+
124
+ end
125
+
126
+ class MacOSXLauncher < UnixLauncher
127
+ def binary_path
128
+ @binary_path ||= "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
129
+ end
130
+ end
131
+
132
+ end # Launcher
133
+ end # Chrome
134
+ end # WebDriver
135
+ end # Selenium
@@ -0,0 +1,134 @@
1
+ /** @license
2
+ Copyright 2007-2009 WebDriver committers
3
+ Copyright 2007-2009 Google Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ /**
19
+ * @fileoverview Base class for all WebDriver command processors.
20
+ * @author jmleyba@gmail.com (Jason Leyba)
21
+ */
22
+
23
+ goog.provide('webdriver.AbstractCommandProcessor');
24
+
25
+ goog.require('goog.Disposable');
26
+ goog.require('goog.array');
27
+ goog.require('goog.object');
28
+ goog.require('webdriver.CommandName');
29
+ goog.require('webdriver.Future');
30
+ goog.require('webdriver.Response');
31
+ goog.require('webdriver.WebElement');
32
+ goog.require('webdriver.timing');
33
+
34
+
35
+ /**
36
+ * Base class for all WebDriver command processors.
37
+ * @constructor
38
+ * @extends {goog.Disposable}
39
+ */
40
+ webdriver.AbstractCommandProcessor = function() {
41
+ goog.Disposable.call(this);
42
+ };
43
+ goog.inherits(webdriver.AbstractCommandProcessor, goog.Disposable);
44
+
45
+
46
+ /**
47
+ * Updates a {@code webdriver.Command} instance so that any parameters that
48
+ * are {@code webdriver.Future} values are converted to their asynchronously set
49
+ * values.
50
+ * @param {webdriver.Command} command The command object to modify.
51
+ * @throws If an attempt is made to fetch the value of a
52
+ * {@code webdriver.Future} that hasn't been computed yet.
53
+ * @private
54
+ */
55
+ webdriver.AbstractCommandProcessor.resolveFutureParams_ = function(
56
+ command) {
57
+ function getValue(obj) {
58
+ if (obj instanceof webdriver.Future) {
59
+ return obj.getValue();
60
+ } else if (goog.isFunction(obj) ||
61
+ obj instanceof webdriver.WebElement) {
62
+ return obj;
63
+ } else if (goog.isObject(obj)) {
64
+ goog.object.forEach(obj, function(value, key) {
65
+ if (value instanceof webdriver.Future) {
66
+ obj[key] = value.getValue();
67
+ }
68
+ });
69
+ }
70
+ return obj;
71
+ }
72
+
73
+ command.parameters = goog.array.map(command.parameters, function(param) {
74
+ if (goog.isArray(param)) {
75
+ return goog.array.map(param, getValue);
76
+ } else {
77
+ return getValue(param);
78
+ }
79
+ });
80
+ };
81
+
82
+
83
+ /**
84
+ * Executes a command.
85
+ * @param {webdriver.Command} command The command to execute.
86
+ */
87
+ webdriver.AbstractCommandProcessor.prototype.execute = function(command) {
88
+ var driver = command.getDriver();
89
+ webdriver.AbstractCommandProcessor.resolveFutureParams_(command);
90
+ var parameters = command.getParameters();
91
+ switch (command.getName()) {
92
+ case webdriver.CommandName.SLEEP:
93
+ var ms = parameters[0];
94
+ webdriver.timing.setTimeout(function() {
95
+ command.setResponse(new webdriver.Response(
96
+ false, driver.getContext(), ms));
97
+ }, ms);
98
+ break;
99
+
100
+ case webdriver.CommandName.WAIT:
101
+ case webdriver.CommandName.FUNCTION:
102
+ try {
103
+ var fn = parameters[0];
104
+ var selfObj = parameters[1];
105
+ var args = parameters[2];
106
+ var result = fn.apply(selfObj, args);
107
+ command.setResponse(new webdriver.Response(
108
+ false, driver.getContext(), result));
109
+ } catch (ex) {
110
+ command.setResponse(new webdriver.Response(
111
+ true, driver.getContext(), null, ex));
112
+ }
113
+ break;
114
+
115
+ default:
116
+ try {
117
+ this.dispatchDriverCommand(command);
118
+ } catch (ex) {
119
+ command.setResponse(new webdriver.Response(
120
+ true, driver.getContext(), null, ex));
121
+ }
122
+ break;
123
+ }
124
+ };
125
+
126
+
127
+ /**
128
+ * Sends a command to be executed by a browser driver. This method must be
129
+ * implemented by each subclass.
130
+ * @param {webdriver.Command} command The command to execute.
131
+ * @protected
132
+ */
133
+ webdriver.AbstractCommandProcessor.prototype.dispatchDriverCommand =
134
+ goog.abstractMethod;
@@ -0,0 +1,296 @@
1
+ /** @license
2
+ Copyright 2007-2009 WebDriver committers
3
+ Copyright 2007-2009 Google Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ /**
19
+ * @fileoverview Assertion functions for use in webdriver test cases.
20
+ * @author jmleyba@gmail.com (Jason Leyba)
21
+ */
22
+
23
+ goog.provide('webdriver.asserts');
24
+
25
+ goog.require('goog.math.Coordinate');
26
+ goog.require('goog.string');
27
+ goog.require('webdriver.Future');
28
+
29
+
30
+ /**
31
+ * @param {webdriver.Future|Object} obj The object to get the value form.
32
+ * @return {*} The value of the given object.
33
+ */
34
+ webdriver.asserts.getValue_ = function(obj) {
35
+ return obj instanceof webdriver.Future ? obj.getValue() : obj;
36
+ };
37
+
38
+
39
+ /**
40
+ * Returns a string with the following format: "<$value> ($type)" where $value
41
+ * is the String representation of the {@code obj} and $type is its type.
42
+ * @param {*} obj The object to build a string for.
43
+ * @return {string} A string describing the given object.
44
+ */
45
+ webdriver.asserts.objToString = function(obj) {
46
+ var value = webdriver.asserts.getValue_(obj);
47
+ var valueStr = goog.isDef(value) ? String(value) : 'undefined';
48
+ return '<' + valueStr + '> (' + goog.typeOf(value) + ')';
49
+ };
50
+
51
+
52
+ /**
53
+ * A class for determining if a value matches a defined criteria.
54
+ * @param {function} matchFn A function that takes a single argument and whether
55
+ * that argument matches the criteria defined by this Matcher.
56
+ * @param {function} describeFn A function that returns a string describing the
57
+ * criteria for this matcher. The string returned by this function should
58
+ * finish this sentence: "Expected to..."
59
+ * @constructor
60
+ */
61
+ webdriver.asserts.Matcher = function(matchFn, describeFn) {
62
+ this.matches = matchFn;
63
+ this.describe = describeFn;
64
+ };
65
+
66
+
67
+ /**
68
+ * Factory method for a {@code webdriver.asserts.Matcher} that does a
69
+ * {@code ===} comparison between the expected and actual values.
70
+ * @param {*} expected The expected value.
71
+ * @return {webdriver.asserts.Matcher} An equality matcher.
72
+ */
73
+ webdriver.asserts.Matcher.equals = function(expected) {
74
+ return new webdriver.asserts.Matcher(
75
+ function (actual) {
76
+ return webdriver.asserts.getValue_(expected) ===
77
+ webdriver.asserts.getValue_(actual);
78
+ },
79
+ function () {
80
+ return 'equal ' + webdriver.asserts.objToString(expected);
81
+ });
82
+ };
83
+ goog.exportSymbol('equals', webdriver.asserts.Matcher.equals);
84
+ goog.exportSymbol('is', webdriver.asserts.Matcher.equals);
85
+
86
+
87
+ /**
88
+ * Creates a {@code webdriver.asserts.Matcher} that tests if the actual
89
+ * value contains the expected value.
90
+ * @param {string} expected The string expected to be in the actual value.
91
+ * @return {webdriver.asserts.Matcher} A new matcher.
92
+ */
93
+ webdriver.asserts.Matcher.contains = function(expected) {
94
+ return new webdriver.asserts.Matcher(
95
+ function (actual) {
96
+ var ev = webdriver.asserts.getValue_(expected);
97
+ var av = webdriver.asserts.getValue_(actual);
98
+ return goog.string.contains(av, ev);
99
+ },
100
+ function () {
101
+ return 'contain ' + webdriver.asserts.objToString(expected);
102
+ });
103
+ };
104
+ goog.exportSymbol('contains', webdriver.asserts.Matcher.contains);
105
+
106
+
107
+ /**
108
+ * Creates a {@code webdriver.asserts.Matcher} that tests if the actual value
109
+ * matches the given regular expression.
110
+ * @param {RegEx} regex The expected regular expression.
111
+ * @return {webdriver.asserts.Matcher} A new matcher.
112
+ */
113
+ webdriver.asserts.Matcher.matchesRegex = function(regex) {
114
+ if (!(regex instanceof RegExp)) {
115
+ throw new Error('IllegalArgument; must be a RegExp, but was: ' + regex +
116
+ '(' + goog.typeOf(regex) + ')');
117
+ }
118
+ return new webdriver.asserts.Matcher(
119
+ function (actual) {
120
+ var av = webdriver.asserts.getValue_(actual);
121
+ return av.match(regex) != null;
122
+ },
123
+ function () {
124
+ return 'match regex ' + regex;
125
+ });
126
+ };
127
+ goog.exportSymbol('matchesRegex', webdriver.asserts.Matcher.matchesRegex);
128
+
129
+
130
+ /**
131
+ * Creates a {@code webdriver.asserts.Matcher} that tests if the actual value
132
+ * starts with the given string.
133
+ * @param {string} expected The expected beginning of the tested string.
134
+ * @return {webdriver.asserts.Matcher} A new matcher.
135
+ */
136
+ webdriver.asserts.Matcher.startsWith = function(expected) {
137
+ return new webdriver.asserts.Matcher(
138
+ function (actual) {
139
+ var ev = webdriver.asserts.getValue_(expected);
140
+ var av = webdriver.asserts.getValue_(actual);
141
+ return goog.string.startsWith(av, ev);
142
+ },
143
+ function () {
144
+ return 'start with ' + webdriver.asserts.objToString(expected);
145
+ });
146
+ };
147
+ goog.exportSymbol('startsWith', webdriver.asserts.Matcher.startsWith);
148
+
149
+
150
+ /**
151
+ * Creates a {@code webdriver.asserts.Matcher} that tests if the actual value is
152
+ * the same location as the expected value.
153
+ * @param {goog.math.Coordinate} expected The expected location, or a future
154
+ * whose pending result is the expected location.
155
+ * @return {webdriver.asserts.Matcher} A new matcher.
156
+ */
157
+ webdriver.asserts.Matcher.isTheSameLocationAs = function(expected) {
158
+ return new webdriver.asserts.Matcher(
159
+ function (actual) {
160
+ var ev = webdriver.asserts.getValue_(expected);
161
+ var av = webdriver.asserts.getValue_(actual);
162
+ return goog.math.Coordinate.equals(ev, av);
163
+ },
164
+ function () {
165
+ return 'equal ' + webdriver.asserts.objToString(expected);
166
+ });
167
+ };
168
+ goog.exportSymbol('isTheSameLocationAs',
169
+ webdriver.asserts.Matcher.isTheSameLocationAs);
170
+
171
+
172
+ /**
173
+ * Verifies that that given value matches the provided {@code Matcher}. This
174
+ * method has two signatures based on the number of arguments:
175
+ * Two arguments:
176
+ * assertThat(actualValue, matcher)
177
+ * Three arguments:
178
+ * assertThat(failureMessage, actualValue, matcher)
179
+ * @param {string} failureMessage The message to include in the resulting error
180
+ * if actualValue does not match matcher.
181
+ * @param {webdriver.Future|Object} The actual value to verify.
182
+ * @param {webdriver.asserts.Matcher} matcher The object to match the actual
183
+ * value against. If not an instanceof {@code webdriver.Matcher}, will
184
+ * default to the matcher returned by the {@code webdriver.equals} factory
185
+ * function.
186
+ */
187
+ webdriver.asserts.assertThat = function(a, b, opt_c) {
188
+ var args = goog.array.slice(arguments, 0);
189
+ var message = args.length > 2 ? (args[0] + '\n') : '';
190
+ var future = args.length > 2 ? args[1] : args[0];
191
+
192
+ var matcher = args.length > 2 ? args[2] : args[1];
193
+ if (!(matcher instanceof webdriver.asserts.Matcher)) {
194
+ matcher = webdriver.asserts.Matcher.equals(matcher);
195
+ }
196
+
197
+ var doAssertion = function() {
198
+ if (!matcher.matches(future)) {
199
+ throw new Error(message +
200
+ 'Expected to ' + matcher.describe() +
201
+ '\n but was ' + webdriver.asserts.objToString(future));
202
+ }
203
+ };
204
+
205
+ if (future instanceof webdriver.Future) {
206
+ // Schedule a function with the Future's controlling driver so the value
207
+ // is verified after it has been set.
208
+ future.getDriver().callFunction(doAssertion);
209
+ } else {
210
+ doAssertion();
211
+ }
212
+ };
213
+ goog.exportSymbol('assertThat', webdriver.asserts.assertThat);
214
+
215
+
216
+ // ----------------------------------------------------------------------------
217
+ // Define some common xUnit paradigm assertion functions, but do not override
218
+ // any pre-existing function (e.g. if the jsapi is being used with the jsunit
219
+ // library.
220
+ // ----------------------------------------------------------------------------
221
+
222
+ goog.global.fail = goog.global.fail || function(opt_msg) {
223
+ var msg = 'Call to fail()';
224
+ if (opt_msg) {
225
+ msg += ': ' + opt_msg;
226
+ }
227
+ throw new Error(msg);
228
+ };
229
+
230
+
231
+ goog.global.assertEquals = goog.global.assertEquals || function(a, b, opt_c) {
232
+ var args = goog.array.slice(arguments, 0);
233
+ var msg = args.length > 2 ? args[0] : '';
234
+ var expected = args.length > 2 ? args[1] : args[0];
235
+ var actual = args.length > 2 ? args[2] : args[1];
236
+ if (expected !== actual) {
237
+ webdriver.asserts.assertThat(msg, actual, equals(expected));
238
+ }
239
+ };
240
+
241
+
242
+ goog.global.assertTrue = goog.global.assertTrue || function(a, opt_b) {
243
+ var args = goog.array.slice(arguments, 0);
244
+ if (args.length > 1) {
245
+ goog.global.assertEquals(args[0], true, args[1]);
246
+ } else {
247
+ goog.global.assertEquals(true, args[0]);
248
+ }
249
+ };
250
+
251
+
252
+ goog.global.assertFalse = goog.global.assertFalse || function(a, opt_b) {
253
+ var args = goog.array.slice(arguments, 0);
254
+ if (args.length > 1) {
255
+ goog.global.assertEquals(args[0], false, args[1]);
256
+ } else {
257
+ goog.global.assertEquals(false, args[0]);
258
+ }
259
+ };
260
+
261
+
262
+ /**
263
+ * Utility function for inverting a value. If the input is a...
264
+ * <ul>
265
+ * <li>{@code webdriver.asserts.Matcher}, returns a new Matcher that inverts
266
+ * the result of the input</li>
267
+ * <li>{@code webdriver.Future}, returns a new Future whose result will be the
268
+ * inverse of hte input</li>
269
+ * <li>any other type of object, it will be converted to a boolean and
270
+ * inverted</li>
271
+ * </ul>
272
+ * @param {*) input The value to invert.
273
+ * @return {webdriver.asserts.Matcher|webdriver.Future|boolean} The inverted
274
+ * value according to the rules defined above.
275
+ */
276
+ webdriver.not = function(input) {
277
+ if (input instanceof webdriver.Future) {
278
+ var invertedFuture = new webdriver.Future(input.getDriver());
279
+ goog.events.listen(input, goog.events.EventType.CHANGE,
280
+ function() {
281
+ invertedFuture.setValue(!!!input.getValue());
282
+ });
283
+ return invertedFuture;
284
+ } else if (input instanceof webdriver.asserts.Matcher) {
285
+ return new webdriver.asserts.Matcher(
286
+ function (actual) {
287
+ return !input.matches(actual);
288
+ },
289
+ function () {
290
+ return 'not ' + input.describe();
291
+ });
292
+ } else {
293
+ return !!!value;
294
+ }
295
+ };
296
+ goog.exportSymbol('not', webdriver.not);