selenium-webdriver 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/{common/src/rb/CHANGES → CHANGES} +13 -0
  2. data/{common/src/rb/README → README} +1 -1
  3. data/{common/src/rb/lib → lib}/selenium-webdriver.rb +0 -0
  4. data/{common/src/rb/lib → lib}/selenium/webdriver.rb +2 -1
  5. data/{common/src/rb/lib → lib}/selenium/webdriver/bridge_helper.rb +0 -0
  6. data/{common/src/rb/lib → lib}/selenium/webdriver/child_process.rb +0 -0
  7. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome.rb +0 -0
  8. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/bridge.rb +2 -2
  9. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/command_executor.rb +0 -0
  10. data/lib/selenium/webdriver/chrome/extension.zip +0 -0
  11. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/launcher.rb +26 -20
  12. data/{common/src/rb/lib → lib}/selenium/webdriver/core_ext/dir.rb +0 -0
  13. data/{common/src/rb/lib → lib}/selenium/webdriver/core_ext/string.rb +0 -0
  14. data/{common/src/rb/lib → lib}/selenium/webdriver/driver.rb +0 -0
  15. data/{common/src/rb/lib → lib}/selenium/webdriver/driver_extensions/takes_screenshot.rb +0 -0
  16. data/{common/src/rb/lib → lib}/selenium/webdriver/element.rb +0 -0
  17. data/{common/src/rb/lib → lib}/selenium/webdriver/error.rb +0 -0
  18. data/{common/src/rb/lib → lib}/selenium/webdriver/file_reaper.rb +2 -1
  19. data/{common/src/rb/lib → lib}/selenium/webdriver/find.rb +0 -0
  20. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox.rb +2 -1
  21. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/binary.rb +32 -6
  22. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/bridge.rb +0 -0
  23. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  24. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/launcher.rb +0 -0
  25. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  26. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  27. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/profile.rb +37 -72
  28. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/profiles_ini.rb +0 -0
  29. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/util.rb +0 -0
  30. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie.rb +2 -2
  31. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/bridge.rb +7 -2
  32. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/lib.rb +0 -0
  33. data/{jobbie/prebuilt/Win32/Release → lib/selenium/webdriver/ie/native/win32}/InternetExplorerDriver.dll +0 -0
  34. data/lib/selenium/webdriver/ie/native/x64/InternetExplorerDriver.dll +0 -0
  35. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/util.rb +0 -0
  36. data/{common/src/rb/lib → lib}/selenium/webdriver/keys.rb +0 -0
  37. data/{common/src/rb/lib → lib}/selenium/webdriver/navigation.rb +0 -0
  38. data/{common/src/rb/lib → lib}/selenium/webdriver/options.rb +0 -0
  39. data/{common/src/rb/lib → lib}/selenium/webdriver/platform.rb +5 -1
  40. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote.rb +0 -0
  41. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/bridge.rb +0 -0
  42. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/capabilities.rb +0 -0
  43. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/commands.rb +0 -0
  44. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/common.rb +0 -0
  45. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/curb.rb +0 -0
  46. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/default.rb +5 -1
  47. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/response.rb +0 -0
  48. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/server_error.rb +0 -0
  49. data/{common/src/rb/lib → lib}/selenium/webdriver/target_locator.rb +0 -0
  50. data/{common/src/rb/lib → lib}/selenium/webdriver/timeouts.rb +0 -0
  51. data/lib/selenium/webdriver/zip_helper.rb +30 -0
  52. metadata +73 -214
  53. data/COPYING +0 -204
  54. data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
  55. data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
  56. data/chrome/src/extension/background.html +0 -9
  57. data/chrome/src/extension/background.js +0 -1029
  58. data/chrome/src/extension/content_script.js +0 -1488
  59. data/chrome/src/extension/icons/busy.png +0 -0
  60. data/chrome/src/extension/icons/free.png +0 -0
  61. data/chrome/src/extension/manifest-nonwin.json +0 -19
  62. data/chrome/src/extension/manifest-win.json +0 -20
  63. data/chrome/src/extension/utils.js +0 -231
  64. data/common/src/js/abstractcommandprocessor.js +0 -132
  65. data/common/src/js/asserts.js +0 -296
  66. data/common/src/js/by.js +0 -149
  67. data/common/src/js/command.js +0 -380
  68. data/common/src/js/core/Blank.html +0 -7
  69. data/common/src/js/core/InjectedRemoteRunner.html +0 -8
  70. data/common/src/js/core/RemoteRunner.html +0 -101
  71. data/common/src/js/core/SeleniumLog.html +0 -109
  72. data/common/src/js/core/TestPrompt.html +0 -145
  73. data/common/src/js/core/TestRunner-splash.html +0 -55
  74. data/common/src/js/core/TestRunner.html +0 -165
  75. data/common/src/js/core/icons/all.png +0 -0
  76. data/common/src/js/core/icons/continue.png +0 -0
  77. data/common/src/js/core/icons/continue_disabled.png +0 -0
  78. data/common/src/js/core/icons/pause.png +0 -0
  79. data/common/src/js/core/icons/pause_disabled.png +0 -0
  80. data/common/src/js/core/icons/selected.png +0 -0
  81. data/common/src/js/core/icons/step.png +0 -0
  82. data/common/src/js/core/icons/step_disabled.png +0 -0
  83. data/common/src/js/core/lib/cssQuery/cssQuery-p.js +0 -6
  84. data/common/src/js/core/lib/cssQuery/src/cssQuery-level2.js +0 -142
  85. data/common/src/js/core/lib/cssQuery/src/cssQuery-level3.js +0 -150
  86. data/common/src/js/core/lib/cssQuery/src/cssQuery-standard.js +0 -53
  87. data/common/src/js/core/lib/cssQuery/src/cssQuery.js +0 -356
  88. data/common/src/js/core/lib/prototype.js +0 -2006
  89. data/common/src/js/core/lib/scriptaculous/builder.js +0 -101
  90. data/common/src/js/core/lib/scriptaculous/controls.js +0 -815
  91. data/common/src/js/core/lib/scriptaculous/dragdrop.js +0 -915
  92. data/common/src/js/core/lib/scriptaculous/effects.js +0 -958
  93. data/common/src/js/core/lib/scriptaculous/scriptaculous.js +0 -47
  94. data/common/src/js/core/lib/scriptaculous/slider.js +0 -283
  95. data/common/src/js/core/lib/scriptaculous/unittest.js +0 -383
  96. data/common/src/js/core/lib/snapsie.js +0 -91
  97. data/common/src/js/core/scripts/find_matching_child.js +0 -69
  98. data/common/src/js/core/scripts/htmlutils.js +0 -8716
  99. data/common/src/js/core/scripts/injection.html +0 -72
  100. data/common/src/js/core/scripts/selenium-api.js +0 -3291
  101. data/common/src/js/core/scripts/selenium-browserbot.js +0 -2457
  102. data/common/src/js/core/scripts/selenium-browserdetect.js +0 -153
  103. data/common/src/js/core/scripts/selenium-commandhandlers.js +0 -379
  104. data/common/src/js/core/scripts/selenium-executionloop.js +0 -175
  105. data/common/src/js/core/scripts/selenium-logging.js +0 -148
  106. data/common/src/js/core/scripts/selenium-remoterunner.js +0 -695
  107. data/common/src/js/core/scripts/selenium-testrunner.js +0 -1362
  108. data/common/src/js/core/scripts/selenium-version.js +0 -5
  109. data/common/src/js/core/scripts/ui-doc.html +0 -808
  110. data/common/src/js/core/scripts/ui-element.js +0 -1644
  111. data/common/src/js/core/scripts/ui-map-sample.js +0 -979
  112. data/common/src/js/core/scripts/user-extensions.js +0 -3
  113. data/common/src/js/core/scripts/user-extensions.js.sample +0 -75
  114. data/common/src/js/core/scripts/xmlextras.js +0 -153
  115. data/common/src/js/core/selenium-logo.png +0 -0
  116. data/common/src/js/core/selenium-test.css +0 -43
  117. data/common/src/js/core/selenium.css +0 -316
  118. data/common/src/js/core/xpath/dom.js +0 -566
  119. data/common/src/js/core/xpath/javascript-xpath-0.1.11.js +0 -2816
  120. data/common/src/js/core/xpath/util.js +0 -549
  121. data/common/src/js/core/xpath/xmltoken.js +0 -149
  122. data/common/src/js/core/xpath/xpath.js +0 -2481
  123. data/common/src/js/extension/README +0 -2
  124. data/common/src/js/extension/dommessenger.js +0 -152
  125. data/common/src/js/factory.js +0 -55
  126. data/common/src/js/future.js +0 -141
  127. data/common/src/js/jsunit.js +0 -40
  128. data/common/src/js/jsunit/app/css/jsUnitStyle.css +0 -50
  129. data/common/src/js/jsunit/app/css/readme +0 -10
  130. data/common/src/js/jsunit/app/emptyPage.html +0 -11
  131. data/common/src/js/jsunit/app/jsUnitCore.js +0 -534
  132. data/common/src/js/jsunit/app/jsUnitMockTimeout.js +0 -81
  133. data/common/src/js/jsunit/app/jsUnitTestManager.js +0 -705
  134. data/common/src/js/jsunit/app/jsUnitTestSuite.js +0 -44
  135. data/common/src/js/jsunit/app/jsUnitTracer.js +0 -102
  136. data/common/src/js/jsunit/app/jsUnitVersionCheck.js +0 -59
  137. data/common/src/js/jsunit/app/main-counts-errors.html +0 -12
  138. data/common/src/js/jsunit/app/main-counts-failures.html +0 -13
  139. data/common/src/js/jsunit/app/main-counts-runs.html +0 -13
  140. data/common/src/js/jsunit/app/main-counts.html +0 -21
  141. data/common/src/js/jsunit/app/main-data.html +0 -178
  142. data/common/src/js/jsunit/app/main-errors.html +0 -23
  143. data/common/src/js/jsunit/app/main-frame.html +0 -19
  144. data/common/src/js/jsunit/app/main-loader.html +0 -45
  145. data/common/src/js/jsunit/app/main-progress.html +0 -25
  146. data/common/src/js/jsunit/app/main-results.html +0 -67
  147. data/common/src/js/jsunit/app/main-status.html +0 -13
  148. data/common/src/js/jsunit/app/testContainer.html +0 -16
  149. data/common/src/js/jsunit/app/testContainerController.html +0 -77
  150. data/common/src/js/jsunit/app/xbDebug.js +0 -306
  151. data/common/src/js/jsunit/changelog.txt +0 -60
  152. data/common/src/js/jsunit/css/jsUnitStyle.css +0 -83
  153. data/common/src/js/jsunit/images/green.gif +0 -0
  154. data/common/src/js/jsunit/images/logo_jsunit.gif +0 -0
  155. data/common/src/js/jsunit/images/powerby-transparent.gif +0 -0
  156. data/common/src/js/jsunit/images/red.gif +0 -0
  157. data/common/src/js/jsunit/licenses/JDOM_license.txt +0 -56
  158. data/common/src/js/jsunit/licenses/Jetty_license.html +0 -213
  159. data/common/src/js/jsunit/licenses/MPL-1.1.txt +0 -470
  160. data/common/src/js/jsunit/licenses/gpl-2.txt +0 -340
  161. data/common/src/js/jsunit/licenses/index.html +0 -141
  162. data/common/src/js/jsunit/licenses/lgpl-2.1.txt +0 -504
  163. data/common/src/js/jsunit/licenses/mpl-tri-license-c.txt +0 -35
  164. data/common/src/js/jsunit/licenses/mpl-tri-license-html.txt +0 -35
  165. data/common/src/js/jsunit/readme.txt +0 -19
  166. data/common/src/js/jsunit/testRunner.html +0 -167
  167. data/common/src/js/jsunit/version.txt +0 -1
  168. data/common/src/js/key.js +0 -117
  169. data/common/src/js/localcommandprocessor.js +0 -171
  170. data/common/src/js/testcase.js +0 -219
  171. data/common/src/js/timing.js +0 -89
  172. data/common/src/js/webdriver.js +0 -860
  173. data/common/src/js/webelement.js +0 -483
  174. data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
  175. data/firefox/prebuilt/amd64/libnoblur64.so +0 -0
  176. data/firefox/prebuilt/i386/libnoblur.so +0 -0
  177. data/firefox/prebuilt/linux/Release/libwebdriver-firefox.so +0 -0
  178. data/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so +0 -0
  179. data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
  180. data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
  181. data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
  182. data/firefox/src/extension/chrome.manifest +0 -3
  183. data/firefox/src/extension/components/badCertListener.js +0 -295
  184. data/firefox/src/extension/components/dispatcher.js +0 -495
  185. data/firefox/src/extension/components/driver-component.js +0 -130
  186. data/firefox/src/extension/components/errorcode.js +0 -70
  187. data/firefox/src/extension/components/firefoxDriver.js +0 -831
  188. data/firefox/src/extension/components/json2.js +0 -273
  189. data/firefox/src/extension/components/keytest.html +0 -554
  190. data/firefox/src/extension/components/nsCommandProcessor.js +0 -684
  191. data/firefox/src/extension/components/promptService.js +0 -208
  192. data/firefox/src/extension/components/request.js +0 -219
  193. data/firefox/src/extension/components/response.js +0 -276
  194. data/firefox/src/extension/components/screenshooter.js +0 -81
  195. data/firefox/src/extension/components/session.js +0 -314
  196. data/firefox/src/extension/components/sessionstore.js +0 -226
  197. data/firefox/src/extension/components/socketListener.js +0 -435
  198. data/firefox/src/extension/components/utils.js +0 -1335
  199. data/firefox/src/extension/components/webLoadingListener.js +0 -57
  200. data/firefox/src/extension/components/webdriverserver.js +0 -110
  201. data/firefox/src/extension/components/wrappedElement.js +0 -706
  202. data/firefox/src/extension/content/fxdriver.xul +0 -30
  203. data/firefox/src/extension/content/server.js +0 -95
  204. data/firefox/src/extension/idl/nsICommandProcessor.idl +0 -38
  205. data/firefox/src/extension/idl/nsIResponseHandler.idl +0 -34
  206. data/firefox/src/extension/install.rdf +0 -29
  207. data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
@@ -1,2457 +0,0 @@
1
- /*
2
- * Copyright 2004 ThoughtWorks, Inc
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- /*
19
- * This script provides the Javascript API to drive the test application contained within
20
- * a Browser Window.
21
- * TODO:
22
- * Add support for more events (keyboard and mouse)
23
- * Allow to switch "user-entry" mode from mouse-based to keyboard-based, firing different
24
- * events in different modes.
25
- */
26
-
27
- // The window to which the commands will be sent. For example, to click on a
28
- // popup window, first select that window, and then do a normal click command.
29
- var BrowserBot = function(topLevelApplicationWindow) {
30
- this.topWindow = topLevelApplicationWindow;
31
- this.topFrame = this.topWindow;
32
- this.baseUrl=window.location.href;
33
-
34
- // the buttonWindow is the Selenium window
35
- // it contains the Run/Pause buttons... this should *not* be the AUT window
36
- this.buttonWindow = window;
37
- this.currentWindow = this.topWindow;
38
- this.currentWindowName = null;
39
- this.allowNativeXpath = true;
40
- this.xpathEvaluator = new XPathEvaluator('ajaxslt'); // change to "javascript-xpath" for the newer, faster engine
41
-
42
- // We need to know this in advance, in case the frame closes unexpectedly
43
- this.isSubFrameSelected = false;
44
-
45
- this.altKeyDown = false;
46
- this.controlKeyDown = false;
47
- this.shiftKeyDown = false;
48
- this.metaKeyDown = false;
49
-
50
- this.modalDialogTest = null;
51
- this.recordedAlerts = new Array();
52
- this.recordedConfirmations = new Array();
53
- this.recordedPrompts = new Array();
54
- this.openedWindows = {};
55
- this.nextConfirmResult = true;
56
- this.nextPromptResult = '';
57
- this.newPageLoaded = false;
58
- this.pageLoadError = null;
59
-
60
- this.ignoreResponseCode = false;
61
- this.xhr = null;
62
- this.abortXhr = false;
63
- this.isXhrSent = false;
64
- this.isXhrDone = false;
65
- this.xhrOpenLocation = null;
66
- this.xhrResponseCode = null;
67
- this.xhrStatusText = null;
68
-
69
- this.shouldHighlightLocatedElement = false;
70
-
71
- this.uniqueId = "seleniumMarker" + new Date().getTime();
72
- this.pollingForLoad = new Object();
73
- this.permDeniedCount = new Object();
74
- this.windowPollers = new Array();
75
- // DGF for backwards compatibility
76
- this.browserbot = this;
77
-
78
- var self = this;
79
-
80
- objectExtend(this, PageBot.prototype);
81
- this._registerAllLocatorFunctions();
82
-
83
- this.recordPageLoad = function(elementOrWindow) {
84
- LOG.debug("Page load detected");
85
- try {
86
- if (elementOrWindow.location && elementOrWindow.location.href) {
87
- LOG.debug("Page load location=" + elementOrWindow.location.href);
88
- } else if (elementOrWindow.contentWindow && elementOrWindow.contentWindow.location && elementOrWindow.contentWindow.location.href) {
89
- LOG.debug("Page load location=" + elementOrWindow.contentWindow.location.href);
90
- } else {
91
- LOG.debug("Page load location unknown, current window location=" + this.getCurrentWindow(true).location);
92
- }
93
- } catch (e) {
94
- LOG.error("Caught an exception attempting to log location; this should get noticed soon!");
95
- LOG.exception(e);
96
- self.pageLoadError = e;
97
- return;
98
- }
99
- self.newPageLoaded = true;
100
- };
101
-
102
- this.isNewPageLoaded = function() {
103
- var e;
104
-
105
- if (this.pageLoadError) {
106
- LOG.error("isNewPageLoaded found an old pageLoadError");
107
- e = this.pageLoadError;
108
- this.pageLoadError = null;
109
- throw e;
110
- }
111
-
112
- if (self.ignoreResponseCode) {
113
- return self.newPageLoaded;
114
- } else {
115
- if (self.isXhrSent && self.isXhrDone) {
116
- if (!((self.xhrResponseCode >= 200 && self.xhrResponseCode <= 399) || self.xhrResponseCode == 0)) {
117
- // TODO: for IE status like: 12002, 12007, ... provide corresponding statusText messages also.
118
- LOG.error("XHR failed with message " + self.xhrStatusText);
119
- e = "XHR ERROR: URL = " + self.xhrOpenLocation + " Response_Code = " + self.xhrResponseCode + " Error_Message = " + self.xhrStatusText;
120
- self.abortXhr = false;
121
- self.isXhrSent = false;
122
- self.isXhrDone = false;
123
- self.xhrResponseCode = null;
124
- self.xhrStatusText = null;
125
- throw new SeleniumError(e);
126
- }
127
- }
128
- return self.newPageLoaded && (self.isXhrSent ? (self.abortXhr || self.isXhrDone) : true);
129
- }
130
- };
131
-
132
- this.setAllowNativeXPath = function(allow) {
133
- this.xpathEvaluator.setAllowNativeXPath(allow);
134
- };
135
-
136
- this.setIgnoreAttributesWithoutValue = function(ignore) {
137
- this.xpathEvaluator.setIgnoreAttributesWithoutValue(ignore);
138
- };
139
-
140
- this.setXPathEngine = function(engineName) {
141
- this.xpathEvaluator.setCurrentEngine(engineName);
142
- };
143
-
144
- this.getXPathEngine = function() {
145
- return this.xpathEvaluator.getCurrentEngine();
146
- };
147
- };
148
-
149
- // DGF PageBot exists for backwards compatibility with old user-extensions
150
- var PageBot = function(){};
151
-
152
- BrowserBot.createForWindow = function(window, proxyInjectionMode) {
153
- var browserbot;
154
- LOG.debug('createForWindow');
155
- LOG.debug("browserName: " + browserVersion.name);
156
- LOG.debug("userAgent: " + navigator.userAgent);
157
- if (browserVersion.isIE) {
158
- browserbot = new IEBrowserBot(window);
159
- }
160
- else if (browserVersion.isKonqueror) {
161
- browserbot = new KonquerorBrowserBot(window);
162
- }
163
- else if (browserVersion.isOpera) {
164
- browserbot = new OperaBrowserBot(window);
165
- }
166
- else if (browserVersion.isSafari) {
167
- browserbot = new SafariBrowserBot(window);
168
- }
169
- else {
170
- // Use mozilla by default
171
- browserbot = new MozillaBrowserBot(window);
172
- }
173
- // getCurrentWindow has the side effect of modifying it to handle page loads etc
174
- browserbot.proxyInjectionMode = proxyInjectionMode;
175
- browserbot.getCurrentWindow(); // for modifyWindow side effect. This is not a transparent style
176
- return browserbot;
177
- };
178
-
179
- // todo: rename? This doesn't actually "do" anything.
180
- BrowserBot.prototype.doModalDialogTest = function(test) {
181
- this.modalDialogTest = test;
182
- };
183
-
184
- BrowserBot.prototype.cancelNextConfirmation = function(result) {
185
- this.nextConfirmResult = result;
186
- };
187
-
188
- BrowserBot.prototype.setNextPromptResult = function(result) {
189
- this.nextPromptResult = result;
190
- };
191
-
192
- BrowserBot.prototype.hasAlerts = function() {
193
- return (this.recordedAlerts.length > 0);
194
- };
195
-
196
- BrowserBot.prototype.relayBotToRC = function(s) {
197
- // DGF need to do this funny trick to see if we're in PI mode, because
198
- // "this" might be the window, rather than the browserbot (e.g. during window.alert)
199
- var piMode = this.proxyInjectionMode;
200
- if (!piMode) {
201
- if (typeof(selenium) != "undefined") {
202
- piMode = selenium.browserbot && selenium.browserbot.proxyInjectionMode;
203
- }
204
- }
205
- if (piMode) {
206
- this.relayToRC("selenium." + s);
207
- }
208
- };
209
-
210
- BrowserBot.prototype.relayToRC = function(name) {
211
- var object = eval(name);
212
- var s = 'state:' + serializeObject(name, object) + "\n";
213
- sendToRC(s,"state=true");
214
- };
215
-
216
- BrowserBot.prototype.resetPopups = function() {
217
- this.recordedAlerts = [];
218
- this.recordedConfirmations = [];
219
- this.recordedPrompts = [];
220
- };
221
-
222
- BrowserBot.prototype.getNextAlert = function() {
223
- var t = this.recordedAlerts.shift();
224
- if (t) {
225
- t = t.replace(/\n/g, " "); // because Selenese loses \n's when retrieving text from HTML table
226
- }
227
- this.relayBotToRC("browserbot.recordedAlerts");
228
- return t;
229
- };
230
-
231
- BrowserBot.prototype.hasConfirmations = function() {
232
- return (this.recordedConfirmations.length > 0);
233
- };
234
-
235
- BrowserBot.prototype.getNextConfirmation = function() {
236
- var t = this.recordedConfirmations.shift();
237
- this.relayBotToRC("browserbot.recordedConfirmations");
238
- return t;
239
- };
240
-
241
- BrowserBot.prototype.hasPrompts = function() {
242
- return (this.recordedPrompts.length > 0);
243
- };
244
-
245
- BrowserBot.prototype.getNextPrompt = function() {
246
- var t = this.recordedPrompts.shift();
247
- this.relayBotToRC("browserbot.recordedPrompts");
248
- return t;
249
- };
250
-
251
- /* Fire a mouse event in a browser-compatible manner */
252
-
253
- BrowserBot.prototype.triggerMouseEvent = function(element, eventType, canBubble, clientX, clientY, button) {
254
- clientX = clientX ? clientX : 0;
255
- clientY = clientY ? clientY : 0;
256
-
257
- LOG.debug("triggerMouseEvent assumes setting screenX and screenY to 0 is ok");
258
- var screenX = 0;
259
- var screenY = 0;
260
-
261
- canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
262
- var evt;
263
- if (element.fireEvent && element.ownerDocument && element.ownerDocument.createEventObject) { //IE
264
- evt = createEventObject(element, this.controlKeyDown, this.altKeyDown, this.shiftKeyDown, this.metaKeyDown);
265
- evt.detail = 0;
266
- evt.button = button ? button : 1; // default will be the left mouse click ( http://www.javascriptkit.com/jsref/event.shtml )
267
- evt.relatedTarget = null;
268
- if (!screenX && !screenY && !clientX && !clientY && !this.controlKeyDown && !this.altKeyDown && !this.shiftKeyDown && !this.metaKeyDown) {
269
- element.fireEvent('on' + eventType);
270
- }
271
- else {
272
- evt.screenX = screenX;
273
- evt.screenY = screenY;
274
- evt.clientX = clientX;
275
- evt.clientY = clientY;
276
-
277
- // when we go this route, window.event is never set to contain the event we have just created.
278
- // ideally we could just slide it in as follows in the try-block below, but this normally
279
- // doesn't work. This is why I try to avoid this code path, which is only required if we need to
280
- // set attributes on the event (e.g., clientX).
281
- try {
282
- window.event = evt;
283
- }
284
- catch(e) {
285
- // getting an "Object does not support this action or property" error. Save the event away
286
- // for future reference.
287
- // TODO: is there a way to update window.event?
288
-
289
- // work around for http://jira.openqa.org/browse/SEL-280 -- make the event available somewhere:
290
- selenium.browserbot.getCurrentWindow().selenium_event = evt;
291
- }
292
- element.fireEvent('on' + eventType, evt);
293
- }
294
- }
295
- else {
296
- evt = document.createEvent('MouseEvents');
297
- if (evt.initMouseEvent)
298
- {
299
- // see http://developer.mozilla.org/en/docs/DOM:event.button and
300
- // http://developer.mozilla.org/en/docs/DOM:event.initMouseEvent for button ternary logic logic
301
- //Safari
302
- evt.initMouseEvent(eventType, canBubble, true, document.defaultView, 1, screenX, screenY, clientX, clientY,
303
- this.controlKeyDown, this.altKeyDown, this.shiftKeyDown, this.metaKeyDown, button ? button : 0, null);
304
- }
305
- else {
306
- LOG.warn("element doesn't have initMouseEvent; firing an event which should -- but doesn't -- have other mouse-event related attributes here, as well as controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown");
307
- evt.initEvent(eventType, canBubble, true);
308
-
309
- evt.shiftKey = this.shiftKeyDown;
310
- evt.metaKey = this.metaKeyDown;
311
- evt.altKey = this.altKeyDown;
312
- evt.ctrlKey = this.controlKeyDown;
313
- if(button)
314
- {
315
- evt.button = button;
316
- }
317
- }
318
- element.dispatchEvent(evt);
319
- }
320
- };
321
-
322
- BrowserBot.prototype._windowClosed = function(win) {
323
- var c = win.closed;
324
- if (c == null) return true;
325
- return c;
326
- };
327
-
328
- BrowserBot.prototype._modifyWindow = function(win) {
329
- // In proxyInjectionMode, have to suppress LOG calls in _modifyWindow to avoid an infinite loop
330
- if (this._windowClosed(win)) {
331
- if (!this.proxyInjectionMode) {
332
- LOG.error("modifyWindow: Window was closed!");
333
- }
334
- return null;
335
- }
336
- if (!this.proxyInjectionMode) {
337
- LOG.debug('modifyWindow ' + this.uniqueId + ":" + win[this.uniqueId]);
338
- }
339
- if (!win[this.uniqueId]) {
340
- win[this.uniqueId] = 1;
341
- this.modifyWindowToRecordPopUpDialogs(win, this);
342
- }
343
- // In proxyInjection mode, we have our own mechanism for detecting page loads
344
- if (!this.proxyInjectionMode) {
345
- this.modifySeparateTestWindowToDetectPageLoads(win);
346
- }
347
- if (win.frames && win.frames.length && win.frames.length > 0) {
348
- for (var i = 0; i < win.frames.length; i++) {
349
- try {
350
- this._modifyWindow(win.frames[i]);
351
- } catch (e) {} // we're just trying to be opportunistic; don't worry if this doesn't work out
352
- }
353
- }
354
- return win;
355
- };
356
-
357
- BrowserBot.prototype.selectWindow = function(target) {
358
- if (!target || target == "null") {
359
- this._selectTopWindow();
360
- return;
361
- }
362
- var result = target.match(/^([a-zA-Z]+)=(.*)/);
363
- if (!result) {
364
- this._selectWindowByWindowId(target);
365
- return;
366
- }
367
- locatorType = result[1];
368
- locatorValue = result[2];
369
- if (locatorType == "title") {
370
- this._selectWindowByTitle(locatorValue);
371
- }
372
- // TODO separate name and var into separate functions
373
- else if (locatorType == "name") {
374
- this._selectWindowByName(locatorValue);
375
- } else if (locatorType == "var") {
376
- this._selectWindowByName(locatorValue);
377
- } else {
378
- throw new SeleniumError("Window locator not recognized: " + locatorType);
379
- }
380
- };
381
-
382
- BrowserBot.prototype.selectPopUp = function(windowId) {
383
- if (! windowId || windowId == 'null') {
384
- this._selectFirstNonTopWindow();
385
- }
386
- else {
387
- this._selectWindowByWindowId(windowId);
388
- }
389
- };
390
-
391
- BrowserBot.prototype._selectTopWindow = function() {
392
- this.currentWindowName = null;
393
- this.currentWindow = this.topWindow;
394
- this.topFrame = this.topWindow;
395
- this.isSubFrameSelected = false;
396
- };
397
-
398
- BrowserBot.prototype._selectWindowByWindowId = function(windowId) {
399
- try {
400
- this._selectWindowByName(windowId);
401
- }
402
- catch (e) {
403
- this._selectWindowByTitle(windowId);
404
- }
405
- };
406
-
407
- BrowserBot.prototype._selectWindowByName = function(target) {
408
- this.currentWindow = this.getWindowByName(target, false);
409
- this.topFrame = this.currentWindow;
410
- this.currentWindowName = target;
411
- this.isSubFrameSelected = false;
412
- };
413
-
414
- BrowserBot.prototype._selectWindowByTitle = function(target) {
415
- var windowName = this.getWindowNameByTitle(target);
416
- if (!windowName) {
417
- this._selectTopWindow();
418
- } else {
419
- this._selectWindowByName(windowName);
420
- }
421
- };
422
-
423
- BrowserBot.prototype._selectFirstNonTopWindow = function() {
424
- var names = this.getNonTopWindowNames();
425
- if (names.length) {
426
- this._selectWindowByName(names[0]);
427
- }
428
- };
429
-
430
- BrowserBot.prototype.selectFrame = function(target) {
431
- var frame;
432
-
433
- if (target.indexOf("index=") == 0) {
434
- target = target.substr(6);
435
- frame = this.getCurrentWindow().frames[target];
436
- if (frame == null) {
437
- throw new SeleniumError("Not found: frames["+target+"]");
438
- }
439
- if (!frame.document) {
440
- throw new SeleniumError("frames["+target+"] is not a frame");
441
- }
442
- this.currentWindow = frame;
443
- this.isSubFrameSelected = true;
444
- }
445
- else if (target == "relative=up" || target == "relative=parent") {
446
- this.currentWindow = this.getCurrentWindow().parent;
447
- this.isSubFrameSelected = (this._getFrameElement(this.currentWindow) != null);
448
- } else if (target == "relative=top") {
449
- this.currentWindow = this.topFrame;
450
- this.isSubFrameSelected = false;
451
- } else {
452
- frame = this.findElement(target);
453
- if (frame == null) {
454
- throw new SeleniumError("Not found: " + target);
455
- }
456
- // now, did they give us a frame or a frame ELEMENT?
457
- var match = false;
458
- if (frame.contentWindow) {
459
- // this must be a frame element
460
- if (browserVersion.isHTA) {
461
- // stupid HTA bug; can't get in the front door
462
- target = frame.contentWindow.name;
463
- } else {
464
- this.currentWindow = frame.contentWindow;
465
- this.isSubFrameSelected = true;
466
- match = true;
467
- }
468
- } else if (frame.document && frame.location) {
469
- // must be an actual window frame
470
- this.currentWindow = frame;
471
- this.isSubFrameSelected = true;
472
- match = true;
473
- }
474
-
475
- if (!match) {
476
- // neither, let's loop through the frame names
477
- var win = this.getCurrentWindow();
478
-
479
- if (win && win.frames && win.frames.length) {
480
- for (var i = 0; i < win.frames.length; i++) {
481
- if (win.frames[i].name == target) {
482
- this.currentWindow = win.frames[i];
483
- this.isSubFrameSelected = true;
484
- match = true;
485
- break;
486
- }
487
- }
488
- }
489
- if (!match) {
490
- throw new SeleniumError("Not a frame: " + target);
491
- }
492
- }
493
- }
494
- // modifies the window
495
- this.getCurrentWindow();
496
- };
497
-
498
- BrowserBot.prototype.doesThisFrameMatchFrameExpression = function(currentFrameString, target) {
499
- var isDom = false;
500
- if (target.indexOf("dom=") == 0) {
501
- target = target.substr(4);
502
- isDom = true;
503
- } else if (target.indexOf("index=") == 0) {
504
- target = "frames[" + target.substr(6) + "]";
505
- isDom = true;
506
- }
507
- var t;
508
- try {
509
- eval("t=" + currentFrameString + "." + target);
510
- } catch (e) {
511
- }
512
- var autWindow = this.browserbot.getCurrentWindow();
513
- if (t != null) {
514
- try {
515
- if (t.window == autWindow) {
516
- return true;
517
- }
518
- if (t.window.uniqueId == autWindow.uniqueId) {
519
- return true;
520
- }
521
- return false;
522
- } catch (permDenied) {
523
- // DGF if the windows are incomparable, they're probably not the same...
524
- }
525
- }
526
- if (isDom) {
527
- return false;
528
- }
529
- var currentFrame;
530
- eval("currentFrame=" + currentFrameString);
531
- if (target == "relative=up") {
532
- if (currentFrame.window.parent == autWindow) {
533
- return true;
534
- }
535
- return false;
536
- }
537
- if (target == "relative=top") {
538
- if (currentFrame.window.top == autWindow) {
539
- return true;
540
- }
541
- return false;
542
- }
543
- if (currentFrame.window == autWindow.parent) {
544
- if (autWindow.name == target) {
545
- return true;
546
- }
547
- try {
548
- var element = this.findElement(target, currentFrame.window);
549
- if (element.contentWindow == autWindow) {
550
- return true;
551
- }
552
- } catch (e) {}
553
- }
554
- return false;
555
- };
556
-
557
- BrowserBot.prototype.abortXhrRequest = function() {
558
- if (this.ignoreResponseCode) {
559
- LOG.debug("XHR response code being ignored. Nothing to abort.");
560
- } else {
561
- if (this.abortXhr == false && this.isXhrSent && !this.isXhrDone) {
562
- LOG.info("abortXhrRequest(): aborting request");
563
- this.abortXhr = true;
564
- this.xhr.abort();
565
- }
566
- }
567
- };
568
-
569
- BrowserBot.prototype.onXhrStateChange = function(method) {
570
- LOG.info("onXhrStateChange(): xhr.readyState = " + this.xhr.readyState + " method = " + method + " time = " + new Date().getTime());
571
- if (this.xhr.readyState == 4) {
572
-
573
- // check if the request got aborted.
574
- if (this.abortXhr == true) {
575
- this.xhrResponseCode = 0;
576
- this.xhrStatusText = "Request Aborted";
577
- this.isXhrDone = true;
578
- return;
579
- }
580
-
581
- try {
582
- if (method == "HEAD" && (this.xhr.status == 501 || this.xhr.status == 405)) {
583
- LOG.info("onXhrStateChange(): HEAD ajax returned 501 or 405, retrying with GET");
584
- // handle 501 response code from servers that do not support 'HEAD' method.
585
- // send GET ajax request with range 0-1.
586
- this.xhr = XmlHttp.create();
587
- this.xhr.onreadystatechange = this.onXhrStateChange.bind(this, "GET");
588
- this.xhr.open("GET", this.xhrOpenLocation, true);
589
- this.xhr.setRequestHeader("Range", "bytes:0-1");
590
- this.xhr.send("");
591
- this.isXhrSent = true;
592
- return;
593
- }
594
- this.xhrResponseCode = this.xhr.status;
595
- this.xhrStatusText = this.xhr.statusText;
596
- } catch (ex) {
597
- LOG.info("encountered exception while reading xhrResponseCode." + ex.message);
598
- this.xhrResponseCode = -1;
599
- this.xhrStatusText = "Request Error";
600
- }
601
-
602
- this.isXhrDone = true;
603
- }
604
- };
605
-
606
- BrowserBot.prototype.checkedOpen = function(target) {
607
- var url = absolutify(target, this.baseUrl);
608
- LOG.debug("checkedOpen(): url = " + url);
609
- this.isXhrDone = false;
610
- this.abortXhr = false;
611
- this.xhrResponseCode = null;
612
- this.xhrOpenLocation = url;
613
- try {
614
- this.xhr = XmlHttp.create();
615
- } catch (ex) {
616
- LOG.error("Your browser doesnt support Xml Http Request");
617
- return;
618
- }
619
- this.xhr.onreadystatechange = this.onXhrStateChange.bind(this, "HEAD");
620
- this.xhr.open("HEAD", url, true);
621
- this.xhr.send("");
622
- this.isXhrSent = true;
623
- };
624
-
625
- BrowserBot.prototype.openLocation = function(target) {
626
- // We're moving to a new page - clear the current one
627
- var win = this.getCurrentWindow();
628
- LOG.debug("openLocation newPageLoaded = false");
629
- this.newPageLoaded = false;
630
- if (!this.ignoreResponseCode) {
631
- this.checkedOpen(target);
632
- }
633
- this.setOpenLocation(win, target);
634
- };
635
-
636
- BrowserBot.prototype.openWindow = function(url, windowID) {
637
- if (url != "") {
638
- url = absolutify(url, this.baseUrl);
639
- }
640
- if (browserVersion.isHTA) {
641
- // in HTA mode, calling .open on the window interprets the url relative to that window
642
- // we need to absolute-ize the URL to make it consistent
643
- var child = this.getCurrentWindow().open(url, windowID);
644
- selenium.browserbot.openedWindows[windowID] = child;
645
- } else {
646
- this.getCurrentWindow().open(url, windowID);
647
- }
648
- };
649
-
650
- BrowserBot.prototype.setIFrameLocation = function(iframe, location) {
651
- iframe.src = location;
652
- };
653
-
654
- BrowserBot.prototype.setOpenLocation = function(win, loc) {
655
- loc = absolutify(loc, this.baseUrl);
656
- if (browserVersion.isHTA) {
657
- var oldHref = win.location.href;
658
- win.location.href = loc;
659
- var marker = null;
660
- try {
661
- marker = this.isPollingForLoad(win);
662
- if (marker && win.location[marker]) {
663
- win.location[marker] = false;
664
- }
665
- } catch (e) {} // DGF don't know why, but this often fails
666
- } else {
667
- win.location.href = loc;
668
- }
669
- };
670
-
671
- BrowserBot.prototype.getCurrentPage = function() {
672
- return this;
673
- };
674
-
675
- BrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
676
- var self = this;
677
-
678
- windowToModify.seleniumAlert = windowToModify.alert;
679
-
680
- windowToModify.alert = function(alert) {
681
- browserBot.recordedAlerts.push(alert);
682
- self.relayBotToRC.call(self, "browserbot.recordedAlerts");
683
- };
684
-
685
- windowToModify.confirm = function(message) {
686
- browserBot.recordedConfirmations.push(message);
687
- var result = browserBot.nextConfirmResult;
688
- browserBot.nextConfirmResult = true;
689
- self.relayBotToRC.call(self, "browserbot.recordedConfirmations");
690
- return result;
691
- };
692
-
693
- windowToModify.prompt = function(message) {
694
- browserBot.recordedPrompts.push(message);
695
- var result = !browserBot.nextConfirmResult ? null : browserBot.nextPromptResult;
696
- browserBot.nextConfirmResult = true;
697
- browserBot.nextPromptResult = '';
698
- self.relayBotToRC.call(self, "browserbot.recordedPrompts");
699
- return result;
700
- };
701
-
702
- // Keep a reference to all popup windows by name
703
- // note that in IE the "windowName" argument must be a valid javascript identifier, it seems.
704
- var originalOpen = windowToModify.open;
705
- var originalOpenReference;
706
- if (browserVersion.isHTA) {
707
- originalOpenReference = 'selenium_originalOpen' + new Date().getTime();
708
- windowToModify[originalOpenReference] = windowToModify.open;
709
- }
710
-
711
- var isHTA = browserVersion.isHTA;
712
-
713
- var newOpen = function(url, windowName, windowFeatures, replaceFlag) {
714
- var myOriginalOpen = originalOpen;
715
- if (isHTA) {
716
- myOriginalOpen = this[originalOpenReference];
717
- }
718
- if (windowName == "" || windowName == "_blank") {
719
- windowName = "selenium_blank" + Math.round(100000 * Math.random());
720
- LOG.warn("Opening window '_blank', which is not a real window name. Randomizing target to be: " + windowName);
721
- }
722
- var openedWindow = myOriginalOpen(url, windowName, windowFeatures, replaceFlag);
723
- LOG.debug("window.open call intercepted; window ID (which you can use with selectWindow()) is \"" + windowName + "\"");
724
- if (windowName!=null) {
725
- openedWindow["seleniumWindowName"] = windowName;
726
- }
727
- selenium.browserbot.openedWindows[windowName] = openedWindow;
728
- return openedWindow;
729
- };
730
-
731
- if (browserVersion.isHTA) {
732
- originalOpenReference = 'selenium_originalOpen' + new Date().getTime();
733
- newOpenReference = 'selenium_newOpen' + new Date().getTime();
734
- var setOriginalRef = "this['" + originalOpenReference + "'] = this.open;";
735
-
736
- if (windowToModify.eval) {
737
- windowToModify.eval(setOriginalRef);
738
- windowToModify.open = newOpen;
739
- } else {
740
- // DGF why can't I eval here? Seems like I'm querying the window at a bad time, maybe?
741
- setOriginalRef += "this.open = this['" + newOpenReference + "'];";
742
- windowToModify[newOpenReference] = newOpen;
743
- windowToModify.setTimeout(setOriginalRef, 0);
744
- }
745
- } else {
746
- windowToModify.open = newOpen;
747
- }
748
- };
749
-
750
- /**
751
- * Call the supplied function when a the current page unloads and a new one loads.
752
- * This is done by polling continuously until the document changes and is fully loaded.
753
- */
754
- BrowserBot.prototype.modifySeparateTestWindowToDetectPageLoads = function(windowObject) {
755
- // Since the unload event doesn't fire in Safari 1.3, we start polling immediately
756
- if (!windowObject) {
757
- LOG.warn("modifySeparateTestWindowToDetectPageLoads: no windowObject!");
758
- return;
759
- }
760
- if (this._windowClosed(windowObject)) {
761
- LOG.info("modifySeparateTestWindowToDetectPageLoads: windowObject was closed");
762
- return;
763
- }
764
- var oldMarker = this.isPollingForLoad(windowObject);
765
- if (oldMarker) {
766
- LOG.debug("modifySeparateTestWindowToDetectPageLoads: already polling this window: " + oldMarker);
767
- return;
768
- }
769
-
770
- var marker = 'selenium' + new Date().getTime();
771
- LOG.debug("Starting pollForLoad (" + marker + "): " + windowObject.location);
772
- this.pollingForLoad[marker] = true;
773
- // if this is a frame, add a load listener, otherwise, attach a poller
774
- var frameElement = this._getFrameElement(windowObject);
775
- // DGF HTA mode can't attach load listeners to subframes (yuk!)
776
- var htaSubFrame = this._isHTASubFrame(windowObject);
777
- if (frameElement && !htaSubFrame) {
778
- LOG.debug("modifySeparateTestWindowToDetectPageLoads: this window is a frame; attaching a load listener");
779
- addLoadListener(frameElement, this.recordPageLoad);
780
- frameElement[marker] = true;
781
- frameElement["frame"+this.uniqueId] = marker;
782
- LOG.debug("dgf this.uniqueId="+this.uniqueId);
783
- LOG.debug("dgf marker="+marker);
784
- LOG.debug("dgf frameElement['frame'+this.uniqueId]="+frameElement['frame'+this.uniqueId]);
785
- frameElement[this.uniqueId] = marker;
786
- LOG.debug("dgf frameElement[this.uniqueId]="+frameElement[this.uniqueId]);
787
- } else {
788
- windowObject.location[marker] = true;
789
- windowObject[this.uniqueId] = marker;
790
- this.pollForLoad(this.recordPageLoad, windowObject, windowObject.document, windowObject.location, windowObject.location.href, marker);
791
- }
792
- };
793
-
794
- BrowserBot.prototype._isHTASubFrame = function(win) {
795
- if (!browserVersion.isHTA) return false;
796
- // DGF this is wrong! what if "win" isn't the selected window?
797
- return this.isSubFrameSelected;
798
- };
799
-
800
- BrowserBot.prototype._getFrameElement = function(win) {
801
- var frameElement = null;
802
- var caught;
803
- try {
804
- frameElement = win.frameElement;
805
- } catch (e) {
806
- caught = true;
807
- }
808
- if (caught) {
809
- // on IE, checking frameElement in a pop-up results in a "No such interface supported" exception
810
- // but it might have a frame element anyway!
811
- var parentContainsIdenticallyNamedFrame = false;
812
- try {
813
- parentContainsIdenticallyNamedFrame = win.parent.frames[win.name];
814
- } catch (e) {} // this may fail if access is denied to the parent; in that case, assume it's not a pop-up
815
-
816
- if (parentContainsIdenticallyNamedFrame) {
817
- // it can't be a coincidence that the parent has a frame with the same name as myself!
818
- var result;
819
- try {
820
- result = parentContainsIdenticallyNamedFrame.frameElement;
821
- if (result) {
822
- return result;
823
- }
824
- } catch (e) {} // it was worth a try! _getFrameElementsByName is often slow
825
- result = this._getFrameElementByName(win.name, win.parent.document, win);
826
- return result;
827
- }
828
- }
829
- LOG.debug("_getFrameElement: frameElement="+frameElement);
830
- if (frameElement) {
831
- LOG.debug("frameElement.name="+frameElement.name);
832
- }
833
- return frameElement;
834
- };
835
-
836
- BrowserBot.prototype._getFrameElementByName = function(name, doc, win) {
837
- var frames;
838
- var frame;
839
- var i;
840
- frames = doc.getElementsByTagName("iframe");
841
- for (i = 0; i < frames.length; i++) {
842
- frame = frames[i];
843
- if (frame.name === name) {
844
- return frame;
845
- }
846
- }
847
- frames = doc.getElementsByTagName("frame");
848
- for (i = 0; i < frames.length; i++) {
849
- frame = frames[i];
850
- if (frame.name === name) {
851
- return frame;
852
- }
853
- }
854
- // DGF weird; we only call this function when we know the doc contains the frame
855
- LOG.warn("_getFrameElementByName couldn't find a frame or iframe; checking every element for the name " + name);
856
- return BrowserBot.prototype.locateElementByName(win.name, win.parent.document);
857
- };
858
-
859
-
860
- /**
861
- * Set up a polling timer that will keep checking the readyState of the document until it's complete.
862
- * Since we might call this before the original page is unloaded, we first check to see that the current location
863
- * or href is different from the original one.
864
- */
865
- BrowserBot.prototype.pollForLoad = function(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker) {
866
- LOG.debug("pollForLoad original (" + marker + "): " + originalHref);
867
- try {
868
- if (this._windowClosed(windowObject)) {
869
- LOG.debug("pollForLoad WINDOW CLOSED (" + marker + ")");
870
- delete this.pollingForLoad[marker];
871
- return;
872
- }
873
-
874
- var isSamePage = this._isSamePage(windowObject, originalDocument, originalLocation, originalHref, marker);
875
- var rs = this.getReadyState(windowObject, windowObject.document);
876
-
877
- if (!isSamePage && rs == 'complete') {
878
- var currentHref = windowObject.location.href;
879
- LOG.debug("pollForLoad FINISHED (" + marker + "): " + rs + " (" + currentHref + ")");
880
- delete this.pollingForLoad[marker];
881
- this._modifyWindow(windowObject);
882
- var newMarker = this.isPollingForLoad(windowObject);
883
- if (!newMarker) {
884
- LOG.debug("modifyWindow didn't start new poller: " + newMarker);
885
- this.modifySeparateTestWindowToDetectPageLoads(windowObject);
886
- }
887
- newMarker = this.isPollingForLoad(windowObject);
888
- var currentlySelectedWindow;
889
- var currentlySelectedWindowMarker;
890
- currentlySelectedWindow =this.getCurrentWindow(true);
891
- currentlySelectedWindowMarker = currentlySelectedWindow[this.uniqueId];
892
-
893
- LOG.debug("pollForLoad (" + marker + ") restarting " + newMarker);
894
- if (/(TestRunner-splash|Blank)\.html\?start=true$/.test(currentHref)) {
895
- LOG.debug("pollForLoad Oh, it's just the starting page. Never mind!");
896
- } else if (currentlySelectedWindowMarker == newMarker) {
897
- loadFunction(currentlySelectedWindow);
898
- } else {
899
- LOG.debug("pollForLoad page load detected in non-current window; ignoring (currentlySelected="+currentlySelectedWindowMarker+", detection in "+newMarker+")");
900
- }
901
- return;
902
- }
903
- LOG.debug("pollForLoad continue (" + marker + "): " + currentHref);
904
- this.reschedulePoller(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
905
- } catch (e) {
906
- LOG.debug("Exception during pollForLoad; this should get noticed soon (" + e.message + ")!");
907
- //DGF this is supposed to get logged later; log it at debug just in case
908
- //LOG.exception(e);
909
- this.pageLoadError = e;
910
- }
911
- };
912
-
913
- BrowserBot.prototype._isSamePage = function(windowObject, originalDocument, originalLocation, originalHref, marker) {
914
- var currentDocument = windowObject.document;
915
- var currentLocation = windowObject.location;
916
- var currentHref = currentLocation.href;
917
-
918
- var sameDoc = this._isSameDocument(originalDocument, currentDocument);
919
-
920
- var sameLoc = (originalLocation === currentLocation);
921
-
922
- // hash marks don't meant the page has loaded, so we need to strip them off if they exist...
923
- var currentHash = currentHref.indexOf('#');
924
- if (currentHash > 0) {
925
- currentHref = currentHref.substring(0, currentHash);
926
- }
927
- var originalHash = originalHref.indexOf('#');
928
- if (originalHash > 0) {
929
- originalHref = originalHref.substring(0, originalHash);
930
- }
931
- LOG.debug("_isSamePage: currentHref: " + currentHref);
932
- LOG.debug("_isSamePage: originalHref: " + originalHref);
933
-
934
- var sameHref = (originalHref === currentHref);
935
- var markedLoc = currentLocation[marker];
936
-
937
- if (browserVersion.isKonqueror || browserVersion.isSafari) {
938
- // the mark disappears too early on these browsers
939
- markedLoc = true;
940
- }
941
-
942
- // since this is some _very_ important logic, especially for PI and multiWindow mode, we should log all these out
943
- LOG.debug("_isSamePage: sameDoc: " + sameDoc);
944
- LOG.debug("_isSamePage: sameLoc: " + sameLoc);
945
- LOG.debug("_isSamePage: sameHref: " + sameHref);
946
- LOG.debug("_isSamePage: markedLoc: " + markedLoc);
947
-
948
- return sameDoc && sameLoc && sameHref && markedLoc;
949
- };
950
-
951
- BrowserBot.prototype._isSameDocument = function(originalDocument, currentDocument) {
952
- return originalDocument === currentDocument;
953
- };
954
-
955
-
956
- BrowserBot.prototype.getReadyState = function(windowObject, currentDocument) {
957
- var rs = currentDocument.readyState;
958
- if (rs == null) {
959
- if ((this.buttonWindow!=null && this.buttonWindow.document.readyState == null) // not proxy injection mode (and therefore buttonWindow isn't null)
960
- || (top.document.readyState == null)) { // proxy injection mode (and therefore everything's in the top window, but buttonWindow doesn't exist)
961
- // uh oh! we're probably on Firefox with no readyState extension installed!
962
- // We'll have to just take a guess as to when the document is loaded; this guess
963
- // will never be perfect. :-(
964
- if (typeof currentDocument.getElementsByTagName != 'undefined'
965
- && typeof currentDocument.getElementById != 'undefined'
966
- && ( currentDocument.getElementsByTagName('body')[0] != null
967
- || currentDocument.body != null )) {
968
- if (windowObject.frameElement && windowObject.location.href == "about:blank" && windowObject.frameElement.src != "about:blank") {
969
- LOG.info("getReadyState not loaded, frame location was about:blank, but frame src = " + windowObject.frameElement.src);
970
- return null;
971
- }
972
- LOG.debug("getReadyState = windowObject.frames.length = " + windowObject.frames.length);
973
- for (var i = 0; i < windowObject.frames.length; i++) {
974
- LOG.debug("i = " + i);
975
- if (this.getReadyState(windowObject.frames[i], windowObject.frames[i].document) != 'complete') {
976
- LOG.debug("getReadyState aha! the nested frame " + windowObject.frames[i].name + " wasn't ready!");
977
- return null;
978
- }
979
- }
980
-
981
- rs = 'complete';
982
- } else {
983
- LOG.debug("pollForLoad readyState was null and DOM appeared to not be ready yet");
984
- }
985
- }
986
- }
987
- else if (rs == "loading" && browserVersion.isIE) {
988
- LOG.debug("pageUnloading = true!!!!");
989
- this.pageUnloading = true;
990
- }
991
- LOG.debug("getReadyState returning " + rs);
992
- return rs;
993
- };
994
-
995
- /** This function isn't used normally, but was the way we used to schedule pollers:
996
- asynchronously executed autonomous units. This is deprecated, but remains here
997
- for future reference.
998
- */
999
- BrowserBot.prototype.XXXreschedulePoller = function(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker) {
1000
- var self = this;
1001
- window.setTimeout(function() {
1002
- self.pollForLoad(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
1003
- }, 500);
1004
- };
1005
-
1006
- /** This function isn't used normally, but is useful for debugging asynchronous pollers
1007
- * To enable it, rename it to "reschedulePoller", so it will override the
1008
- * existing reschedulePoller function
1009
- */
1010
- BrowserBot.prototype.XXXreschedulePoller = function(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker) {
1011
- var doc = this.buttonWindow.document;
1012
- var button = doc.createElement("button");
1013
- var buttonName = doc.createTextNode(marker + " - " + windowObject.name);
1014
- button.appendChild(buttonName);
1015
- var tools = doc.getElementById("tools");
1016
- var self = this;
1017
- button.onclick = function() {
1018
- tools.removeChild(button);
1019
- self.pollForLoad(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
1020
- };
1021
- tools.appendChild(button);
1022
- window.setTimeout(button.onclick, 500);
1023
- };
1024
-
1025
- BrowserBot.prototype.reschedulePoller = function(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker) {
1026
- var self = this;
1027
- var pollerFunction = function() {
1028
- self.pollForLoad(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
1029
- };
1030
- this.windowPollers.push(pollerFunction);
1031
- };
1032
-
1033
- BrowserBot.prototype.runScheduledPollers = function() {
1034
- LOG.debug("runScheduledPollers");
1035
- var oldPollers = this.windowPollers;
1036
- this.windowPollers = new Array();
1037
- for (var i = 0; i < oldPollers.length; i++) {
1038
- oldPollers[i].call();
1039
- }
1040
- LOG.debug("runScheduledPollers DONE");
1041
- };
1042
-
1043
- BrowserBot.prototype.isPollingForLoad = function(win) {
1044
- var marker;
1045
- var frameElement = this._getFrameElement(win);
1046
- var htaSubFrame = this._isHTASubFrame(win);
1047
- if (frameElement && !htaSubFrame) {
1048
- marker = frameElement["frame"+this.uniqueId];
1049
- } else {
1050
- marker = win[this.uniqueId];
1051
- }
1052
- if (!marker) {
1053
- LOG.debug("isPollingForLoad false, missing uniqueId " + this.uniqueId + ": " + marker);
1054
- return false;
1055
- }
1056
- if (!this.pollingForLoad[marker]) {
1057
- LOG.debug("isPollingForLoad false, this.pollingForLoad[" + marker + "]: " + this.pollingForLoad[marker]);
1058
- return false;
1059
- }
1060
- return marker;
1061
- };
1062
-
1063
- BrowserBot.prototype.getWindowByName = function(windowName, doNotModify) {
1064
- LOG.debug("getWindowByName(" + windowName + ")");
1065
- // First look in the map of opened windows
1066
- var targetWindow = this.openedWindows[windowName];
1067
- if (!targetWindow) {
1068
- targetWindow = this.topWindow[windowName];
1069
- }
1070
- if (!targetWindow && windowName == "_blank") {
1071
- for (var winName in this.openedWindows) {
1072
- // _blank can match selenium_blank*, if it looks like it's OK (valid href, not closed)
1073
- if (/^selenium_blank/.test(winName)) {
1074
- targetWindow = this.openedWindows[winName];
1075
- var ok;
1076
- try {
1077
- if (!this._windowClosed(targetWindow)) {
1078
- ok = targetWindow.location.href;
1079
- }
1080
- } catch (e) {}
1081
- if (ok) break;
1082
- }
1083
- }
1084
- }
1085
- if (!targetWindow) {
1086
- throw new SeleniumError("Window does not exist. If this looks like a Selenium bug, make sure to read http://seleniumhq.org/docs/04_selenese_commands.html#alerts-popups-and-multiple-windows for potential workarounds.");
1087
- }
1088
- if (browserVersion.isHTA) {
1089
- try {
1090
- targetWindow.location.href;
1091
- } catch (e) {
1092
- targetWindow = window.open("", targetWindow.name);
1093
- this.openedWindows[targetWindow.name] = targetWindow;
1094
- }
1095
- }
1096
- if (!doNotModify) {
1097
- this._modifyWindow(targetWindow);
1098
- }
1099
- return targetWindow;
1100
- };
1101
-
1102
- /**
1103
- * Find a window name from the window title.
1104
- */
1105
- BrowserBot.prototype.getWindowNameByTitle = function(windowTitle) {
1106
- LOG.debug("getWindowNameByTitle(" + windowTitle + ")");
1107
-
1108
- // First look in the map of opened windows and iterate them
1109
- for (var windowName in this.openedWindows) {
1110
- var targetWindow = this.openedWindows[windowName];
1111
-
1112
- // If the target window's title is our title
1113
- try {
1114
- // TODO implement Pattern Matching here
1115
- if (!this._windowClosed(targetWindow) &&
1116
- targetWindow.document.title == windowTitle) {
1117
- return windowName;
1118
- }
1119
- } catch (e) {
1120
- // You'll often get Permission Denied errors here in IE
1121
- // eh, if we can't read this window's title,
1122
- // it's probably not available to us right now anyway
1123
- }
1124
- }
1125
-
1126
- try {
1127
- if (this.topWindow.document.title == windowTitle) {
1128
- return "";
1129
- }
1130
- } catch (e) {} // IE Perm denied
1131
-
1132
- throw new SeleniumError("Could not find window with title " + windowTitle);
1133
- };
1134
-
1135
- BrowserBot.prototype.getNonTopWindowNames = function() {
1136
- var nonTopWindowNames = [];
1137
-
1138
- for (var windowName in this.openedWindows) {
1139
- var win = this.openedWindows[windowName];
1140
- if (! this._windowClosed(win) && win != this.topWindow) {
1141
- nonTopWindowNames.push(windowName);
1142
- }
1143
- }
1144
-
1145
- return nonTopWindowNames;
1146
- };
1147
-
1148
- BrowserBot.prototype.getCurrentWindow = function(doNotModify) {
1149
- if (this.proxyInjectionMode) {
1150
- return window;
1151
- }
1152
- var testWindow = this.currentWindow;
1153
- if (!doNotModify) {
1154
- this._modifyWindow(testWindow);
1155
- LOG.debug("getCurrentWindow newPageLoaded = false");
1156
- this.newPageLoaded = false;
1157
- }
1158
- testWindow = this._handleClosedSubFrame(testWindow, doNotModify);
1159
- return testWindow;
1160
- };
1161
-
1162
- /**
1163
- * Offer a method the end-user can reliably use to retrieve the current window.
1164
- * This should work even for windows with an XPCNativeWrapper. Returns the
1165
- * current window object.
1166
- */
1167
- BrowserBot.prototype.getUserWindow = function() {
1168
- var userWindow = this.getCurrentWindow(true);
1169
-
1170
- if (userWindow.wrappedJSObject) {
1171
- userWindow = userWindow.wrappedJSObject;
1172
- }
1173
-
1174
- return userWindow;
1175
- };
1176
-
1177
- BrowserBot.prototype._handleClosedSubFrame = function(testWindow, doNotModify) {
1178
- if (this.proxyInjectionMode) {
1179
- return testWindow;
1180
- }
1181
-
1182
- if (this.isSubFrameSelected) {
1183
- var missing = true;
1184
- if (testWindow.parent && testWindow.parent.frames && testWindow.parent.frames.length) {
1185
- for (var i = 0; i < testWindow.parent.frames.length; i++) {
1186
- if (testWindow.parent.frames[i] == testWindow) {
1187
- missing = false;
1188
- break;
1189
- }
1190
- }
1191
- }
1192
- if (missing) {
1193
- LOG.warn("Current subframe appears to have closed; selecting top frame");
1194
- this.selectFrame("relative=top");
1195
- return this.getCurrentWindow(doNotModify);
1196
- }
1197
- } else if (this._windowClosed(testWindow)) {
1198
- var closedError = new SeleniumError("Current window or frame is closed!");
1199
- closedError.windowClosed = true;
1200
- throw closedError;
1201
- }
1202
- return testWindow;
1203
- };
1204
-
1205
- BrowserBot.prototype.highlight = function (element, force) {
1206
- if (force || this.shouldHighlightLocatedElement) {
1207
- try {
1208
- highlight(element);
1209
- } catch (e) {} // DGF element highlighting is low-priority and possibly dangerous
1210
- }
1211
- return element;
1212
- };
1213
-
1214
- BrowserBot.prototype.setShouldHighlightElement = function (shouldHighlight) {
1215
- this.shouldHighlightLocatedElement = shouldHighlight;
1216
- };
1217
-
1218
- /*****************************************************************/
1219
- /* BROWSER-SPECIFIC FUNCTIONS ONLY AFTER THIS LINE */
1220
-
1221
-
1222
- BrowserBot.prototype._registerAllLocatorFunctions = function() {
1223
- // TODO - don't do this in the constructor - only needed once ever
1224
- this.locationStrategies = {};
1225
- for (var functionName in this) {
1226
- var result = /^locateElementBy([A-Z].+)$/.exec(functionName);
1227
- if (result != null) {
1228
- var locatorFunction = this[functionName];
1229
- if (typeof(locatorFunction) != 'function') {
1230
- continue;
1231
- }
1232
- // Use a specified prefix in preference to one generated from
1233
- // the function name
1234
- var locatorPrefix = locatorFunction.prefix || result[1].toLowerCase();
1235
- this.locationStrategies[locatorPrefix] = locatorFunction;
1236
- }
1237
- }
1238
-
1239
- /**
1240
- * Find a locator based on a prefix.
1241
- */
1242
- this.findElementBy = function(locatorType, locator, inDocument, inWindow) {
1243
- var locatorFunction = this.locationStrategies[locatorType];
1244
- if (! locatorFunction) {
1245
- throw new SeleniumError("Unrecognised locator type: '" + locatorType + "'");
1246
- }
1247
- return locatorFunction.call(this, locator, inDocument, inWindow);
1248
- };
1249
-
1250
- /**
1251
- * The implicit locator, that is used when no prefix is supplied.
1252
- */
1253
- this.locationStrategies['implicit'] = function(locator, inDocument, inWindow) {
1254
- if (locator.startsWith('//')) {
1255
- return this.locateElementByXPath(locator, inDocument, inWindow);
1256
- }
1257
- if (locator.startsWith('document.')) {
1258
- return this.locateElementByDomTraversal(locator, inDocument, inWindow);
1259
- }
1260
- return this.locateElementByIdentifier(locator, inDocument, inWindow);
1261
- };
1262
- };
1263
-
1264
- BrowserBot.prototype.getDocument = function() {
1265
- return this.getCurrentWindow().document;
1266
- };
1267
-
1268
- BrowserBot.prototype.getTitle = function() {
1269
- var t = this.getDocument().title;
1270
- if (typeof(t) == "string") {
1271
- t = t.trim();
1272
- }
1273
- return t;
1274
- };
1275
-
1276
- BrowserBot.prototype.getCookieByName = function(cookieName, doc) {
1277
- if (!doc) doc = this.getDocument();
1278
- var ck = doc.cookie;
1279
- if (!ck) return null;
1280
- var ckPairs = ck.split(/;/);
1281
- for (var i = 0; i < ckPairs.length; i++) {
1282
- var ckPair = ckPairs[i].trim();
1283
- var ckNameValue = ckPair.split(/=/);
1284
- var ckName = decodeURIComponent(ckNameValue[0]);
1285
- if (ckName === cookieName) {
1286
- return decodeURIComponent(ckNameValue[1]);
1287
- }
1288
- }
1289
- return null;
1290
- };
1291
-
1292
- BrowserBot.prototype.getAllCookieNames = function(doc) {
1293
- if (!doc) doc = this.getDocument();
1294
- var ck = doc.cookie;
1295
- if (!ck) return [];
1296
- var cookieNames = [];
1297
- var ckPairs = ck.split(/;/);
1298
- for (var i = 0; i < ckPairs.length; i++) {
1299
- var ckPair = ckPairs[i].trim();
1300
- var ckNameValue = ckPair.split(/=/);
1301
- var ckName = decodeURIComponent(ckNameValue[0]);
1302
- cookieNames.push(ckName);
1303
- }
1304
- return cookieNames;
1305
- };
1306
-
1307
- BrowserBot.prototype.deleteCookie = function(cookieName, domain, path, doc) {
1308
- if (!doc) doc = this.getDocument();
1309
- var expireDateInMilliseconds = (new Date()).getTime() + (-1 * 1000);
1310
- var cookie = cookieName + "=deleted; ";
1311
- if (path) {
1312
- cookie += "path=" + path + "; ";
1313
- }
1314
- if (domain) {
1315
- cookie += "domain=" + domain + "; ";
1316
- }
1317
- cookie += "expires=" + new Date(expireDateInMilliseconds).toGMTString();
1318
- LOG.debug("Setting cookie to: " + cookie);
1319
- doc.cookie = cookie;
1320
- };
1321
-
1322
- /** Try to delete cookie, return false if it didn't work */
1323
- BrowserBot.prototype._maybeDeleteCookie = function(cookieName, domain, path, doc) {
1324
- this.deleteCookie(cookieName, domain, path, doc);
1325
- return (!this.getCookieByName(cookieName, doc));
1326
- };
1327
-
1328
-
1329
- BrowserBot.prototype._recursivelyDeleteCookieDomains = function(cookieName, domain, path, doc) {
1330
- var deleted = this._maybeDeleteCookie(cookieName, domain, path, doc);
1331
- if (deleted) return true;
1332
- var dotIndex = domain.indexOf(".");
1333
- if (dotIndex == 0) {
1334
- return this._recursivelyDeleteCookieDomains(cookieName, domain.substring(1), path, doc);
1335
- } else if (dotIndex != -1) {
1336
- return this._recursivelyDeleteCookieDomains(cookieName, domain.substring(dotIndex), path, doc);
1337
- } else {
1338
- // No more dots; try just not passing in a domain at all
1339
- return this._maybeDeleteCookie(cookieName, null, path, doc);
1340
- }
1341
- };
1342
-
1343
- BrowserBot.prototype._recursivelyDeleteCookie = function(cookieName, domain, path, doc) {
1344
- var slashIndex = path.lastIndexOf("/");
1345
- var finalIndex = path.length-1;
1346
- if (slashIndex == finalIndex) {
1347
- slashIndex--;
1348
- }
1349
- if (slashIndex != -1) {
1350
- deleted = this._recursivelyDeleteCookie(cookieName, domain, path.substring(0, slashIndex+1), doc);
1351
- if (deleted) return true;
1352
- }
1353
- return this._recursivelyDeleteCookieDomains(cookieName, domain, path, doc);
1354
- };
1355
-
1356
- BrowserBot.prototype.recursivelyDeleteCookie = function(cookieName, domain, path, win) {
1357
- if (!win) win = this.getCurrentWindow();
1358
- var doc = win.document;
1359
- if (!domain) {
1360
- domain = doc.domain;
1361
- }
1362
- if (!path) {
1363
- path = win.location.pathname;
1364
- }
1365
- var deleted = this._recursivelyDeleteCookie(cookieName, "." + domain, path, doc);
1366
- if (deleted) return;
1367
- // Finally try a null path (Try it last because it's uncommon)
1368
- deleted = this._recursivelyDeleteCookieDomains(cookieName, "." + domain, null, doc);
1369
- if (deleted) return;
1370
- throw new SeleniumError("Couldn't delete cookie " + cookieName);
1371
- };
1372
-
1373
- /*
1374
- * Finds an element recursively in frames and nested frames
1375
- * in the specified document, using various lookup protocols
1376
- */
1377
- BrowserBot.prototype.findElementRecursive = function(locatorType, locatorString, inDocument, inWindow) {
1378
-
1379
- var element = this.findElementBy(locatorType, locatorString, inDocument, inWindow);
1380
- if (element != null) {
1381
- return element;
1382
- }
1383
-
1384
- for (var i = 0; i < inWindow.frames.length; i++) {
1385
- // On some browsers, the document object is undefined for third-party
1386
- // frames. Make sure the document is valid before continuing.
1387
- if (inWindow.frames[i].document) {
1388
- element = this.findElementRecursive(locatorType, locatorString, inWindow.frames[i].document, inWindow.frames[i]);
1389
-
1390
- if (element != null) {
1391
- return element;
1392
- }
1393
- }
1394
- }
1395
- };
1396
-
1397
- /*
1398
- * Finds an element on the current page, using various lookup protocols
1399
- */
1400
- BrowserBot.prototype.findElementOrNull = function(locator, win) {
1401
- locator = parse_locator(locator);
1402
-
1403
- if (win == null) {
1404
- win = this.getCurrentWindow();
1405
- }
1406
- var element = this.findElementRecursive(locator.type, locator.string, win.document, win);
1407
-
1408
- if (element != null) {
1409
- return this.browserbot.highlight(element);
1410
- }
1411
-
1412
- // Element was not found by any locator function.
1413
- return null;
1414
- };
1415
-
1416
- BrowserBot.prototype.findElement = function(locator, win) {
1417
- var element = this.findElementOrNull(locator, win);
1418
- if (element == null) throw new SeleniumError("Element " + locator + " not found");
1419
- return element;
1420
- };
1421
-
1422
- /**
1423
- * In non-IE browsers, getElementById() does not search by name. Instead, we
1424
- * we search separately by id and name.
1425
- */
1426
- BrowserBot.prototype.locateElementByIdentifier = function(identifier, inDocument, inWindow) {
1427
- // HBC - use "this" instead of "BrowserBot.prototype"; otherwise we lose
1428
- // the non-prototype fields of the object!
1429
- return this.locateElementById(identifier, inDocument, inWindow)
1430
- || BrowserBot.prototype.locateElementByName(identifier, inDocument, inWindow)
1431
- || null;
1432
- };
1433
-
1434
- /**
1435
- * Find the element with id - can't rely on getElementById, coz it returns by name as well in IE..
1436
- */
1437
- BrowserBot.prototype.locateElementById = function(identifier, inDocument, inWindow) {
1438
- var element = inDocument.getElementById(identifier);
1439
- if (element && element.getAttribute('id') === identifier) {
1440
- return element;
1441
- }
1442
- else if (browserVersion.isIE || browserVersion.isOpera) {
1443
- // SEL-484
1444
- var elements = inDocument.getElementsByTagName('*');
1445
-
1446
- for (var i = 0, n = elements.length; i < n; ++i) {
1447
- element = elements[i];
1448
-
1449
- if (element.tagName.toLowerCase() == 'form') {
1450
- if (element.attributes['id'].nodeValue == identifier) {
1451
- return element;
1452
- }
1453
- }
1454
- else if (element.getAttribute('id') == identifier) {
1455
- return element;
1456
- }
1457
- }
1458
-
1459
- return null;
1460
- }
1461
- else {
1462
- return null;
1463
- }
1464
- };
1465
-
1466
- /**
1467
- * Find an element by name, refined by (optional) element-filter
1468
- * expressions.
1469
- */
1470
- BrowserBot.prototype.locateElementByName = function(locator, document, inWindow) {
1471
- var elements = document.getElementsByTagName("*");
1472
-
1473
- var filters = locator.split(' ');
1474
- filters[0] = 'name=' + filters[0];
1475
-
1476
- while (filters.length) {
1477
- var filter = filters.shift();
1478
- elements = this.selectElements(filter, elements, 'value');
1479
- }
1480
-
1481
- if (elements.length > 0) {
1482
- return elements[0];
1483
- }
1484
- return null;
1485
- };
1486
-
1487
- /**
1488
- * Finds an element using by evaluating the specfied string.
1489
- */
1490
- BrowserBot.prototype.locateElementByDomTraversal = function(domTraversal, document, window) {
1491
-
1492
- var browserbot = this.browserbot;
1493
- var element = null;
1494
- try {
1495
- element = eval(domTraversal);
1496
- } catch (e) {
1497
- return null;
1498
- }
1499
-
1500
- if (!element) {
1501
- return null;
1502
- }
1503
-
1504
- return element;
1505
- };
1506
-
1507
- BrowserBot.prototype.locateElementByDomTraversal.prefix = "dom";
1508
-
1509
- /**
1510
- * Finds an element identified by the xpath expression. Expressions _must_
1511
- * begin with "//".
1512
- */
1513
- BrowserBot.prototype.locateElementByXPath = function(xpath, inDocument, inWindow) {
1514
- return this.xpathEvaluator.selectSingleNode(inDocument, xpath, null,
1515
- this._namespaceResolver);
1516
- };
1517
-
1518
- BrowserBot.prototype._namespaceResolver = function(prefix) {
1519
- if (prefix == 'html' || prefix == 'xhtml' || prefix == 'x') {
1520
- return 'http://www.w3.org/1999/xhtml';
1521
- } else if (prefix == 'mathml') {
1522
- return 'http://www.w3.org/1998/Math/MathML';
1523
- } else {
1524
- throw new Error("Unknown namespace: " + prefix + ".");
1525
- }
1526
- };
1527
-
1528
- /**
1529
- * Returns the number of xpath results.
1530
- */
1531
- BrowserBot.prototype.evaluateXPathCount = function(xpath, inDocument) {
1532
- return this.xpathEvaluator.countNodes(inDocument, xpath, null,
1533
- this._namespaceResolver);
1534
- };
1535
-
1536
- /**
1537
- * Finds a link element with text matching the expression supplied. Expressions must
1538
- * begin with "link:".
1539
- */
1540
- BrowserBot.prototype.locateElementByLinkText = function(linkText, inDocument, inWindow) {
1541
- var links = inDocument.getElementsByTagName('a');
1542
- for (var i = 0; i < links.length; i++) {
1543
- var element = links[i];
1544
- if (PatternMatcher.matches(linkText, getText(element))) {
1545
- return element;
1546
- }
1547
- }
1548
- return null;
1549
- };
1550
-
1551
- BrowserBot.prototype.locateElementByLinkText.prefix = "link";
1552
-
1553
- /**
1554
- * Returns an attribute based on an attribute locator. This is made up of an element locator
1555
- * suffixed with @attribute-name.
1556
- */
1557
- BrowserBot.prototype.findAttribute = function(locator) {
1558
- // Split into locator + attributeName
1559
- var attributePos = locator.lastIndexOf("@");
1560
- var elementLocator = locator.slice(0, attributePos);
1561
- var attributeName = locator.slice(attributePos + 1);
1562
-
1563
- // Find the element.
1564
- var element = this.findElement(elementLocator);
1565
-
1566
- // Handle missing "class" attribute in IE.
1567
- if (browserVersion.isIE && attributeName == "class") {
1568
- attributeName = "className";
1569
- }
1570
-
1571
- // Get the attribute value.
1572
- var attributeValue = element.getAttribute(attributeName);
1573
-
1574
- // IE returns an object for the "style" attribute
1575
- if (attributeName == 'style' && typeof(attributeValue) != 'string') {
1576
- attributeValue = attributeValue.cssText;
1577
- }
1578
-
1579
- return attributeValue ? attributeValue.toString() : null;
1580
- };
1581
-
1582
- /*
1583
- * Select the specified option and trigger the relevant events of the element.
1584
- */
1585
- BrowserBot.prototype.selectOption = function(element, optionToSelect) {
1586
- triggerEvent(element, 'focus', false);
1587
- var changed = false;
1588
- for (var i = 0; i < element.options.length; i++) {
1589
- var option = element.options[i];
1590
- if (option.selected && option != optionToSelect) {
1591
- option.selected = false;
1592
- changed = true;
1593
- }
1594
- else if (!option.selected && option == optionToSelect) {
1595
- option.selected = true;
1596
- changed = true;
1597
- }
1598
- }
1599
-
1600
- if (changed) {
1601
- triggerEvent(element, 'change', true);
1602
- }
1603
- };
1604
-
1605
- /*
1606
- * Select the specified option and trigger the relevant events of the element.
1607
- */
1608
- BrowserBot.prototype.addSelection = function(element, option) {
1609
- this.checkMultiselect(element);
1610
- triggerEvent(element, 'focus', false);
1611
- if (!option.selected) {
1612
- option.selected = true;
1613
- triggerEvent(element, 'change', true);
1614
- }
1615
- };
1616
-
1617
- /*
1618
- * Select the specified option and trigger the relevant events of the element.
1619
- */
1620
- BrowserBot.prototype.removeSelection = function(element, option) {
1621
- this.checkMultiselect(element);
1622
- triggerEvent(element, 'focus', false);
1623
- if (option.selected) {
1624
- option.selected = false;
1625
- triggerEvent(element, 'change', true);
1626
- }
1627
- };
1628
-
1629
- BrowserBot.prototype.checkMultiselect = function(element) {
1630
- if (!element.multiple)
1631
- {
1632
- throw new SeleniumError("Not a multi-select");
1633
- }
1634
-
1635
- };
1636
-
1637
- BrowserBot.prototype.replaceText = function(element, stringValue) {
1638
- triggerEvent(element, 'focus', false);
1639
- triggerEvent(element, 'select', true);
1640
- var maxLengthAttr = element.getAttribute("maxLength");
1641
- var actualValue = stringValue;
1642
- if (maxLengthAttr != null) {
1643
- var maxLength = parseInt(maxLengthAttr);
1644
- if (stringValue.length > maxLength) {
1645
- actualValue = stringValue.substr(0, maxLength);
1646
- }
1647
- }
1648
-
1649
- if (getTagName(element) == "body") {
1650
- if (element.ownerDocument && element.ownerDocument.designMode) {
1651
- var designMode = new String(element.ownerDocument.designMode).toLowerCase();
1652
- if (designMode == "on") {
1653
- // this must be a rich text control!
1654
- element.innerHTML = actualValue;
1655
- }
1656
- }
1657
- } else {
1658
- element.value = actualValue;
1659
- }
1660
- // DGF this used to be skipped in chrome URLs, but no longer. Is xpcnativewrappers to blame?
1661
- try {
1662
- triggerEvent(element, 'change', true);
1663
- } catch (e) {}
1664
- };
1665
-
1666
- BrowserBot.prototype.submit = function(formElement) {
1667
- var actuallySubmit = true;
1668
- this._modifyElementTarget(formElement);
1669
- if (formElement.onsubmit) {
1670
- if (browserVersion.isHTA) {
1671
- // run the code in the correct window so alerts are handled correctly even in HTA mode
1672
- var win = this.browserbot.getCurrentWindow();
1673
- var now = new Date().getTime();
1674
- var marker = 'marker' + now;
1675
- win[marker] = formElement;
1676
- win.setTimeout("var actuallySubmit = "+marker+".onsubmit();" +
1677
- "if (actuallySubmit) { " +
1678
- marker+".submit(); " +
1679
- "if ("+marker+".target && !/^_/.test("+marker+".target)) {"+
1680
- "window.open('', "+marker+".target);"+
1681
- "}"+
1682
- "};"+
1683
- marker+"=null", 0);
1684
- // pause for up to 2s while this command runs
1685
- var terminationCondition = function () {
1686
- return !win[marker];
1687
- };
1688
- return Selenium.decorateFunctionWithTimeout(terminationCondition, 2000);
1689
- } else {
1690
- actuallySubmit = formElement.onsubmit();
1691
- if (actuallySubmit) {
1692
- formElement.submit();
1693
- if (formElement.target && !/^_/.test(formElement.target)) {
1694
- this.browserbot.openWindow('', formElement.target);
1695
- }
1696
- }
1697
- }
1698
- } else {
1699
- formElement.submit();
1700
- }
1701
- };
1702
-
1703
- BrowserBot.prototype.clickElement = function(element, clientX, clientY) {
1704
- this._fireEventOnElement("click", element, clientX, clientY);
1705
- };
1706
-
1707
- BrowserBot.prototype.doubleClickElement = function(element, clientX, clientY) {
1708
- this._fireEventOnElement("dblclick", element, clientX, clientY);
1709
- };
1710
-
1711
- // The contextmenu event is fired when the user right-clicks to open the context menu
1712
- BrowserBot.prototype.contextMenuOnElement = function(element, clientX, clientY) {
1713
- this._fireEventOnElement("contextmenu", element, clientX, clientY);
1714
- };
1715
-
1716
- BrowserBot.prototype._modifyElementTarget = function(element) {
1717
- if (element.target) {
1718
- if (element.target == "_blank" || /^selenium_blank/.test(element.target) ) {
1719
- var tagName = getTagName(element);
1720
- if (tagName == "a" || tagName == "form") {
1721
- var newTarget = "selenium_blank" + Math.round(100000 * Math.random());
1722
- LOG.warn("Link has target '_blank', which is not supported in Selenium! Randomizing target to be: " + newTarget);
1723
- this.browserbot.openWindow('', newTarget);
1724
- element.target = newTarget;
1725
- }
1726
- }
1727
- }
1728
- };
1729
-
1730
-
1731
- BrowserBot.prototype._handleClickingImagesInsideLinks = function(targetWindow, element) {
1732
- var itrElement = element;
1733
- while (itrElement != null) {
1734
- if (itrElement.href) {
1735
- targetWindow.location.href = itrElement.href;
1736
- break;
1737
- }
1738
- itrElement = itrElement.parentNode;
1739
- }
1740
- };
1741
-
1742
- BrowserBot.prototype._getTargetWindow = function(element) {
1743
- var targetWindow = element.ownerDocument.defaultView;
1744
- if (element.target) {
1745
- targetWindow = this._getFrameFromGlobal(element.target);
1746
- }
1747
- return targetWindow;
1748
- };
1749
-
1750
- BrowserBot.prototype._getFrameFromGlobal = function(target) {
1751
-
1752
- if (target == "_self") {
1753
- return this.getCurrentWindow();
1754
- }
1755
- if (target == "_top") {
1756
- return this.topFrame;
1757
- } else if (target == "_parent") {
1758
- return this.getCurrentWindow().parent;
1759
- } else if (target == "_blank") {
1760
- // TODO should this set cleverer window defaults?
1761
- return this.getCurrentWindow().open('', '_blank');
1762
- }
1763
- var frameElement = this.findElementBy("implicit", target, this.topFrame.document, this.topFrame);
1764
- if (frameElement) {
1765
- return frameElement.contentWindow;
1766
- }
1767
- var win = this.getWindowByName(target);
1768
- if (win) return win;
1769
- return this.getCurrentWindow().open('', target);
1770
- };
1771
-
1772
-
1773
- BrowserBot.prototype.bodyText = function() {
1774
- if (!this.getDocument().body) {
1775
- throw new SeleniumError("Couldn't access document.body. Is this HTML page fully loaded?");
1776
- }
1777
- return getText(this.getDocument().body);
1778
- };
1779
-
1780
- BrowserBot.prototype.getAllButtons = function() {
1781
- var elements = this.getDocument().getElementsByTagName('input');
1782
- var result = [];
1783
-
1784
- for (var i = 0; i < elements.length; i++) {
1785
- if (elements[i].type == 'button' || elements[i].type == 'submit' || elements[i].type == 'reset') {
1786
- result.push(elements[i].id);
1787
- }
1788
- }
1789
-
1790
- return result;
1791
- };
1792
-
1793
-
1794
- BrowserBot.prototype.getAllFields = function() {
1795
- var elements = this.getDocument().getElementsByTagName('input');
1796
- var result = [];
1797
-
1798
- for (var i = 0; i < elements.length; i++) {
1799
- if (elements[i].type == 'text') {
1800
- result.push(elements[i].id);
1801
- }
1802
- }
1803
-
1804
- return result;
1805
- };
1806
-
1807
- BrowserBot.prototype.getAllLinks = function() {
1808
- var elements = this.getDocument().getElementsByTagName('a');
1809
- var result = [];
1810
-
1811
- for (var i = 0; i < elements.length; i++) {
1812
- result.push(elements[i].id);
1813
- }
1814
-
1815
- return result;
1816
- };
1817
-
1818
- function isDefined(value) {
1819
- return typeof(value) != undefined;
1820
- };
1821
-
1822
- BrowserBot.prototype.goBack = function() {
1823
- this.getCurrentWindow().history.back();
1824
- };
1825
-
1826
- BrowserBot.prototype.goForward = function() {
1827
- this.getCurrentWindow().history.forward();
1828
- };
1829
-
1830
- BrowserBot.prototype.close = function() {
1831
- if (browserVersion.isIE) {
1832
- // fix "do you want to close this window" warning in IE
1833
- // You can only close windows that you have opened.
1834
- // So, let's "open" it.
1835
- try {
1836
- this.topFrame.name=new Date().getTime();
1837
- window.open("", this.topFrame.name, "");
1838
- this.topFrame.close();
1839
- return;
1840
- } catch (e) {}
1841
- }
1842
- if (browserVersion.isChrome || browserVersion.isSafari || browserVersion.isOpera) {
1843
- this.topFrame.close();
1844
- } else {
1845
- this.getCurrentWindow().eval("window.top.close();");
1846
- }
1847
- };
1848
-
1849
- BrowserBot.prototype.refresh = function() {
1850
- this.getCurrentWindow().location.reload(true);
1851
- };
1852
-
1853
- /**
1854
- * Refine a list of elements using a filter.
1855
- */
1856
- BrowserBot.prototype.selectElementsBy = function(filterType, filter, elements) {
1857
- var filterFunction = BrowserBot.filterFunctions[filterType];
1858
- if (! filterFunction) {
1859
- throw new SeleniumError("Unrecognised element-filter type: '" + filterType + "'");
1860
- }
1861
-
1862
- return filterFunction(filter, elements);
1863
- };
1864
-
1865
- BrowserBot.filterFunctions = {};
1866
-
1867
- BrowserBot.filterFunctions.name = function(name, elements) {
1868
- var selectedElements = [];
1869
- for (var i = 0; i < elements.length; i++) {
1870
- if (elements[i].name === name) {
1871
- selectedElements.push(elements[i]);
1872
- }
1873
- }
1874
- return selectedElements;
1875
- };
1876
-
1877
- BrowserBot.filterFunctions.value = function(value, elements) {
1878
- var selectedElements = [];
1879
- for (var i = 0; i < elements.length; i++) {
1880
- if (elements[i].value === value) {
1881
- selectedElements.push(elements[i]);
1882
- }
1883
- }
1884
- return selectedElements;
1885
- };
1886
-
1887
- BrowserBot.filterFunctions.index = function(index, elements) {
1888
- index = Number(index);
1889
- if (isNaN(index) || index < 0) {
1890
- throw new SeleniumError("Illegal Index: " + index);
1891
- }
1892
- if (elements.length <= index) {
1893
- throw new SeleniumError("Index out of range: " + index);
1894
- }
1895
- return [elements[index]];
1896
- };
1897
-
1898
- BrowserBot.prototype.selectElements = function(filterExpr, elements, defaultFilterType) {
1899
-
1900
- var filterType = (defaultFilterType || 'value');
1901
-
1902
- // If there is a filter prefix, use the specified strategy
1903
- var result = filterExpr.match(/^([A-Za-z]+)=(.+)/);
1904
- if (result) {
1905
- filterType = result[1].toLowerCase();
1906
- filterExpr = result[2];
1907
- }
1908
-
1909
- return this.selectElementsBy(filterType, filterExpr, elements);
1910
- };
1911
-
1912
- /**
1913
- * Find an element by class
1914
- */
1915
- BrowserBot.prototype.locateElementByClass = function(locator, document) {
1916
- return elementFindFirstMatchingChild(document,
1917
- function(element) {
1918
- return element.className == locator;
1919
- }
1920
- );
1921
- };
1922
-
1923
- /**
1924
- * Find an element by alt
1925
- */
1926
- BrowserBot.prototype.locateElementByAlt = function(locator, document) {
1927
- return elementFindFirstMatchingChild(document,
1928
- function(element) {
1929
- return element.alt == locator;
1930
- }
1931
- );
1932
- };
1933
-
1934
- /**
1935
- * Find an element by css selector
1936
- */
1937
- BrowserBot.prototype.locateElementByCss = function(locator, document) {
1938
- var elements = eval_css(locator, document);
1939
- if (elements.length != 0)
1940
- return elements[0];
1941
- return null;
1942
- };
1943
-
1944
- /**
1945
- * This function is responsible for mapping a UI specifier string to an element
1946
- * on the page, and returning it. If no element is found, null is returned.
1947
- * Returning null on failure to locate the element is part of the undocumented
1948
- * API for locator strategies.
1949
- */
1950
- BrowserBot.prototype.locateElementByUIElement = function(locator, inDocument) {
1951
- // offset locators are delimited by "->", which is much simpler than the
1952
- // previous scheme involving detecting the close-paren.
1953
- var locators = locator.split(/->/, 2);
1954
-
1955
- var locatedElement = null;
1956
- var pageElements = UIMap.getInstance()
1957
- .getPageElements(locators[0], inDocument);
1958
-
1959
- if (locators.length > 1) {
1960
- for (var i = 0; i < pageElements.length; ++i) {
1961
- var locatedElements = eval_locator(locators[1], inDocument,
1962
- pageElements[i]);
1963
- if (locatedElements.length) {
1964
- locatedElement = locatedElements[0];
1965
- break;
1966
- }
1967
- }
1968
- }
1969
- else if (pageElements.length) {
1970
- locatedElement = pageElements[0];
1971
- }
1972
-
1973
- return locatedElement;
1974
- };
1975
-
1976
- BrowserBot.prototype.locateElementByUIElement.prefix = 'ui';
1977
-
1978
- // define a function used to compare the result of a close UI element
1979
- // match with the actual interacted element. If they are close enough
1980
- // according to the heuristic, consider them a match.
1981
- /**
1982
- * A heuristic function for comparing a node with a target node. Typically the
1983
- * node is specified in a UI element definition, while the target node is
1984
- * returned by the recorder as the leaf element which had some event enacted
1985
- * upon it. This particular heuristic covers the case where the anchor element
1986
- * contains other inline tags, such as "em" or "img".
1987
- *
1988
- * @param node the node being compared to the target node
1989
- * @param target the target node
1990
- * @return true if node equals target, or if node is a link
1991
- * element and target is its descendant, or if node has
1992
- * an onclick attribute and target is its descendant.
1993
- * False otherwise.
1994
- */
1995
- BrowserBot.prototype.locateElementByUIElement.is_fuzzy_match = function(node, target) {
1996
- try {
1997
- var isMatch = (
1998
- (node == target) ||
1999
- ((node.nodeName == 'A' || node.onclick) && is_ancestor(node, target))
2000
- );
2001
- return isMatch;
2002
- }
2003
- catch (e) {
2004
- return false;
2005
- }
2006
- };
2007
-
2008
- /*****************************************************************/
2009
- /* BROWSER-SPECIFIC FUNCTIONS ONLY AFTER THIS LINE */
2010
-
2011
- function MozillaBrowserBot(frame) {
2012
- BrowserBot.call(this, frame);
2013
- };
2014
- objectExtend(MozillaBrowserBot.prototype, BrowserBot.prototype);
2015
-
2016
- function KonquerorBrowserBot(frame) {
2017
- BrowserBot.call(this, frame);
2018
- };
2019
- objectExtend(KonquerorBrowserBot.prototype, BrowserBot.prototype);
2020
-
2021
- KonquerorBrowserBot.prototype.setIFrameLocation = function(iframe, location) {
2022
- // Window doesn't fire onload event when setting src to the current value,
2023
- // so we set it to blank first.
2024
- iframe.src = "about:blank";
2025
- iframe.src = location;
2026
- };
2027
-
2028
- KonquerorBrowserBot.prototype.setOpenLocation = function(win, loc) {
2029
- // Window doesn't fire onload event when setting src to the current value,
2030
- // so we just refresh in that case instead.
2031
- loc = absolutify(loc, this.baseUrl);
2032
- loc = canonicalize(loc);
2033
- var startUrl = win.location.href;
2034
- if ("about:blank" != win.location.href) {
2035
- var startLoc = parseUrl(win.location.href);
2036
- startLoc.hash = null;
2037
- startUrl = reassembleLocation(startLoc);
2038
- }
2039
- LOG.debug("startUrl="+startUrl);
2040
- LOG.debug("win.location.href="+win.location.href);
2041
- LOG.debug("loc="+loc);
2042
- if (startUrl == loc) {
2043
- LOG.debug("opening exact same location");
2044
- this.refresh();
2045
- } else {
2046
- LOG.debug("locations differ");
2047
- win.location.href = loc;
2048
- }
2049
- // force the current polling thread to detect a page load
2050
- var marker = this.isPollingForLoad(win);
2051
- if (marker) {
2052
- delete win.location[marker];
2053
- }
2054
- };
2055
-
2056
- KonquerorBrowserBot.prototype._isSameDocument = function(originalDocument, currentDocument) {
2057
- // under Konqueror, there may be this case:
2058
- // originalDocument and currentDocument are different objects
2059
- // while their location are same.
2060
- if (originalDocument) {
2061
- return originalDocument.location == currentDocument.location;
2062
- } else {
2063
- return originalDocument === currentDocument;
2064
- }
2065
- };
2066
-
2067
- function SafariBrowserBot(frame) {
2068
- BrowserBot.call(this, frame);
2069
- }
2070
- objectExtend(SafariBrowserBot.prototype, BrowserBot.prototype);
2071
-
2072
- SafariBrowserBot.prototype.setIFrameLocation = KonquerorBrowserBot.prototype.setIFrameLocation;
2073
- SafariBrowserBot.prototype.setOpenLocation = KonquerorBrowserBot.prototype.setOpenLocation;
2074
-
2075
-
2076
- function OperaBrowserBot(frame) {
2077
- BrowserBot.call(this, frame);
2078
- };
2079
- objectExtend(OperaBrowserBot.prototype, BrowserBot.prototype);
2080
- OperaBrowserBot.prototype.setIFrameLocation = function(iframe, location) {
2081
- if (iframe.src == location) {
2082
- iframe.src = location + '?reload';
2083
- } else {
2084
- iframe.src = location;
2085
- }
2086
- };
2087
-
2088
- function IEBrowserBot(frame) {
2089
- BrowserBot.call(this, frame);
2090
- };
2091
- objectExtend(IEBrowserBot.prototype, BrowserBot.prototype);
2092
-
2093
- IEBrowserBot.prototype._handleClosedSubFrame = function(testWindow, doNotModify) {
2094
- if (this.proxyInjectionMode) {
2095
- return testWindow;
2096
- }
2097
-
2098
- try {
2099
- testWindow.location.href;
2100
- this.permDenied = 0;
2101
- } catch (e) {
2102
- this.permDenied++;
2103
- }
2104
- if (this._windowClosed(testWindow) || this.permDenied > 4) {
2105
- if (this.isSubFrameSelected) {
2106
- LOG.warn("Current subframe appears to have closed; selecting top frame");
2107
- this.selectFrame("relative=top");
2108
- return this.getCurrentWindow(doNotModify);
2109
- } else {
2110
- var closedError = new SeleniumError("Current window or frame is closed!");
2111
- closedError.windowClosed = true;
2112
- throw closedError;
2113
- }
2114
- }
2115
- return testWindow;
2116
- };
2117
-
2118
- IEBrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
2119
- BrowserBot.prototype.modifyWindowToRecordPopUpDialogs(windowToModify, browserBot);
2120
-
2121
- // we will call the previous version of this method from within our own interception
2122
- oldShowModalDialog = windowToModify.showModalDialog;
2123
-
2124
- windowToModify.showModalDialog = function(url, args, features) {
2125
- // Get relative directory to where TestRunner.html lives
2126
- // A risky assumption is that the user's TestRunner is named TestRunner.html
2127
- var doc_location = document.location.toString();
2128
- var end_of_base_ref = doc_location.indexOf('TestRunner.html');
2129
- var base_ref = doc_location.substring(0, end_of_base_ref);
2130
- var runInterval = '';
2131
-
2132
- // Only set run interval if options is defined
2133
- if (typeof(window.runOptions) != 'undefined') {
2134
- runInterval = "&runInterval=" + runOptions.runInterval;
2135
- }
2136
-
2137
- var testRunnerURL = "TestRunner.html?auto=true&singletest="
2138
- + escape(browserBot.modalDialogTest)
2139
- + "&autoURL="
2140
- + escape(url)
2141
- + runInterval;
2142
- var fullURL = base_ref + testRunnerURL;
2143
- browserBot.modalDialogTest = null;
2144
-
2145
- // If using proxy injection mode
2146
- if (this.proxyInjectionMode) {
2147
- var sessionId = runOptions.getSessionId();
2148
- if (sessionId == undefined) {
2149
- sessionId = injectedSessionId;
2150
- }
2151
- if (sessionId != undefined) {
2152
- LOG.debug("Invoking showModalDialog and injecting URL " + fullURL);
2153
- }
2154
- fullURL = url;
2155
- }
2156
- var returnValue = oldShowModalDialog(fullURL, args, features);
2157
- return returnValue;
2158
- };
2159
- };
2160
-
2161
- IEBrowserBot.prototype.modifySeparateTestWindowToDetectPageLoads = function(windowObject) {
2162
- this.pageUnloading = false;
2163
- var self = this;
2164
- var pageUnloadDetector = function() {
2165
- self.pageUnloading = true;
2166
- };
2167
- windowObject.attachEvent("onbeforeunload", pageUnloadDetector);
2168
- BrowserBot.prototype.modifySeparateTestWindowToDetectPageLoads.call(this, windowObject);
2169
- };
2170
-
2171
- IEBrowserBot.prototype.pollForLoad = function(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker) {
2172
- LOG.debug("IEBrowserBot.pollForLoad: " + marker);
2173
- if (!this.permDeniedCount[marker]) this.permDeniedCount[marker] = 0;
2174
- BrowserBot.prototype.pollForLoad.call(this, loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
2175
- var self;
2176
- if (this.pageLoadError) {
2177
- if (this.pageUnloading) {
2178
- self = this;
2179
- LOG.debug("pollForLoad UNLOADING (" + marker + "): caught exception while firing events on unloading page: " + this.pageLoadError.message);
2180
- this.reschedulePoller(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
2181
- this.pageLoadError = null;
2182
- return;
2183
- } else if (((this.pageLoadError.message == "Permission denied") || (/^Access is denied/.test(this.pageLoadError.message)))
2184
- && this.permDeniedCount[marker]++ < 8) {
2185
- if (this.permDeniedCount[marker] > 4) {
2186
- var canAccessThisWindow;
2187
- var canAccessCurrentlySelectedWindow;
2188
- try {
2189
- windowObject.location.href;
2190
- canAccessThisWindow = true;
2191
- } catch (e) {}
2192
- try {
2193
- this.getCurrentWindow(true).location.href;
2194
- canAccessCurrentlySelectedWindow = true;
2195
- } catch (e) {}
2196
- if (canAccessCurrentlySelectedWindow & !canAccessThisWindow) {
2197
- LOG.debug("pollForLoad (" + marker + ") ABORTING: " + this.pageLoadError.message + " (" + this.permDeniedCount[marker] + "), but the currently selected window is fine");
2198
- // returning without rescheduling
2199
- this.pageLoadError = null;
2200
- return;
2201
- }
2202
- }
2203
-
2204
- self = this;
2205
- LOG.debug("pollForLoad (" + marker + "): " + this.pageLoadError.message + " (" + this.permDeniedCount[marker] + "), waiting to see if it goes away");
2206
- this.reschedulePoller(loadFunction, windowObject, originalDocument, originalLocation, originalHref, marker);
2207
- this.pageLoadError = null;
2208
- return;
2209
- }
2210
- //handy for debugging!
2211
- //throw this.pageLoadError;
2212
- }
2213
- };
2214
-
2215
- IEBrowserBot.prototype._windowClosed = function(win) {
2216
- try {
2217
- var c = win.closed;
2218
- // frame windows claim to be non-closed when their parents are closed
2219
- // but you can't access their document objects in that case
2220
- if (!c) {
2221
- try {
2222
- win.document;
2223
- } catch (de) {
2224
- if (de.message == "Permission denied") {
2225
- // the window is probably unloading, which means it's probably not closed yet
2226
- return false;
2227
- }
2228
- else if (/^Access is denied/.test(de.message)) {
2229
- // rare variation on "Permission denied"?
2230
- LOG.debug("IEBrowserBot.windowClosed: got " + de.message + " (this.pageUnloading=" + this.pageUnloading + "); assuming window is unloading, probably not closed yet");
2231
- return false;
2232
- } else {
2233
- // this is probably one of those frame window situations
2234
- LOG.debug("IEBrowserBot.windowClosed: couldn't read win.document, assume closed: " + de.message + " (this.pageUnloading=" + this.pageUnloading + ")");
2235
- return true;
2236
- }
2237
- }
2238
- }
2239
- if (c == null) {
2240
- LOG.debug("IEBrowserBot.windowClosed: win.closed was null, assuming closed");
2241
- return true;
2242
- }
2243
- return c;
2244
- } catch (e) {
2245
- LOG.debug("IEBrowserBot._windowClosed: Got an exception trying to read win.closed; we'll have to take a guess!");
2246
-
2247
- if (browserVersion.isHTA) {
2248
- if (e.message == "Permission denied") {
2249
- // the window is probably unloading, which means it's not closed yet
2250
- return false;
2251
- } else {
2252
- // there's a good chance that we've lost contact with the window object if it is closed
2253
- return true;
2254
- }
2255
- } else {
2256
- // the window is probably unloading, which means it's not closed yet
2257
- return false;
2258
- }
2259
- }
2260
- };
2261
-
2262
- /**
2263
- * In IE, getElementById() also searches by name - this is an optimisation for IE.
2264
- */
2265
- IEBrowserBot.prototype.locateElementByIdentifer = function(identifier, inDocument, inWindow) {
2266
- return inDocument.getElementById(identifier);
2267
- };
2268
-
2269
- SafariBrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
2270
- BrowserBot.prototype.modifyWindowToRecordPopUpDialogs(windowToModify, browserBot);
2271
-
2272
- var originalOpen = windowToModify.open;
2273
- /*
2274
- * Safari seems to be broken, so that when we manually trigger the onclick method
2275
- * of a button/href, any window.open calls aren't resolved relative to the app location.
2276
- * So here we replace the open() method with one that does resolve the url correctly.
2277
- */
2278
- windowToModify.open = function(url, windowName, windowFeatures, replaceFlag) {
2279
-
2280
- if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")) {
2281
- return originalOpen(url, windowName, windowFeatures, replaceFlag);
2282
- }
2283
-
2284
- // Reduce the current path to the directory
2285
- var currentPath = windowToModify.location.pathname || "/";
2286
- currentPath = currentPath.replace(/\/[^\/]*$/, "/");
2287
-
2288
- // Remove any leading "./" from the new url.
2289
- url = url.replace(/^\.\//, "");
2290
-
2291
- newUrl = currentPath + url;
2292
-
2293
- var openedWindow = originalOpen(newUrl, windowName, windowFeatures, replaceFlag);
2294
- LOG.debug("window.open call intercepted; window ID (which you can use with selectWindow()) is \"" + windowName + "\"");
2295
- if (windowName!=null) {
2296
- openedWindow["seleniumWindowName"] = windowName;
2297
- }
2298
- return openedWindow;
2299
- };
2300
- };
2301
-
2302
- MozillaBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX, clientY) {
2303
- var win = this.getCurrentWindow();
2304
- triggerEvent(element, 'focus', false);
2305
-
2306
- // Add an event listener that detects if the default action has been prevented.
2307
- // (This is caused by a javascript onclick handler returning false)
2308
- // we capture the whole event, rather than the getPreventDefault() state at the time,
2309
- // because we need to let the entire event bubbling and capturing to go through
2310
- // before making a decision on whether we should force the href
2311
- var savedEvent = null;
2312
-
2313
- element.addEventListener(eventType, function(evt) {
2314
- savedEvent = evt;
2315
- }, false);
2316
-
2317
- this._modifyElementTarget(element);
2318
-
2319
- // Trigger the event.
2320
- this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
2321
-
2322
- if (this._windowClosed(win)) {
2323
- return;
2324
- }
2325
-
2326
- // Perform the link action if preventDefault was set.
2327
- // In chrome URL, the link action is already executed by triggerMouseEvent.
2328
- if (!browserVersion.isChrome && savedEvent != null && !savedEvent.getPreventDefault()) {
2329
- var targetWindow = this.browserbot._getTargetWindow(element);
2330
- if (element.href) {
2331
- targetWindow.location.href = element.href;
2332
- } else {
2333
- this.browserbot._handleClickingImagesInsideLinks(targetWindow, element);
2334
- }
2335
- }
2336
-
2337
- };
2338
-
2339
-
2340
- OperaBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX, clientY) {
2341
- var win = this.getCurrentWindow();
2342
- triggerEvent(element, 'focus', false);
2343
-
2344
- this._modifyElementTarget(element);
2345
-
2346
- // Trigger the click event.
2347
- this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
2348
-
2349
- if (this._windowClosed(win)) {
2350
- return;
2351
- }
2352
-
2353
- };
2354
-
2355
-
2356
- KonquerorBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX, clientY) {
2357
- var win = this.getCurrentWindow();
2358
- triggerEvent(element, 'focus', false);
2359
-
2360
- this._modifyElementTarget(element);
2361
-
2362
- if (element[eventType]) {
2363
- element[eventType]();
2364
- }
2365
- else {
2366
- this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
2367
- }
2368
-
2369
- if (this._windowClosed(win)) {
2370
- return;
2371
- }
2372
-
2373
- };
2374
-
2375
- SafariBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX, clientY) {
2376
- triggerEvent(element, 'focus', false);
2377
- var wasChecked = element.checked;
2378
-
2379
- this._modifyElementTarget(element);
2380
-
2381
- // For form element it is simple.
2382
- if (element[eventType]) {
2383
- element[eventType]();
2384
- }
2385
- // For links and other elements, event emulation is required.
2386
- else {
2387
- var targetWindow = this.browserbot._getTargetWindow(element);
2388
- // todo: deal with anchors?
2389
- this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
2390
-
2391
- }
2392
-
2393
- };
2394
-
2395
- SafariBrowserBot.prototype.refresh = function() {
2396
- var win = this.getCurrentWindow();
2397
- if (win.location.hash) {
2398
- // DGF Safari refuses to refresh when there's a hash symbol in the URL
2399
- win.location.hash = "";
2400
- var actuallyReload = function() {
2401
- win.location.reload(true);
2402
- };
2403
- window.setTimeout(actuallyReload, 1);
2404
- } else {
2405
- win.location.reload(true);
2406
- }
2407
- };
2408
-
2409
- IEBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX, clientY) {
2410
- var win = this.getCurrentWindow();
2411
- triggerEvent(element, 'focus', false);
2412
-
2413
- var wasChecked = element.checked;
2414
-
2415
- // Set a flag that records if the page will unload - this isn't always accurate, because
2416
- // <a href="javascript:alert('foo'):"> triggers the onbeforeunload event, even thought the page won't unload
2417
- var pageUnloading = false;
2418
- var pageUnloadDetector = function() {
2419
- pageUnloading = true;
2420
- };
2421
- win.attachEvent("onbeforeunload", pageUnloadDetector);
2422
- this._modifyElementTarget(element);
2423
- if (element[eventType]) {
2424
- element[eventType]();
2425
- }
2426
- else {
2427
- this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
2428
- }
2429
-
2430
-
2431
- // If the page is going to unload - still attempt to fire any subsequent events.
2432
- // However, we can't guarantee that the page won't unload half way through, so we need to handle exceptions.
2433
- try {
2434
- win.detachEvent("onbeforeunload", pageUnloadDetector);
2435
-
2436
- if (this._windowClosed(win)) {
2437
- return;
2438
- }
2439
-
2440
- // Onchange event is not triggered automatically in IE.
2441
- if (isDefined(element.checked) && wasChecked != element.checked) {
2442
- triggerEvent(element, 'change', true);
2443
- }
2444
-
2445
- }
2446
- catch (e) {
2447
- // If the page is unloading, we may get a "Permission denied" or "Unspecified error".
2448
- // Just ignore it, because the document may have unloaded.
2449
- if (pageUnloading) {
2450
- LOG.logHook = function() {
2451
- };
2452
- LOG.warn("Caught exception when firing events on unloading page: " + e.message);
2453
- return;
2454
- }
2455
- throw e;
2456
- }
2457
- };