rubinium 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/CHANGES +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +137 -0
  4. data/Rakefile +139 -0
  5. data/TODO +7 -0
  6. data/doc/examples/rtc_site_live.rb +12 -0
  7. data/doc/examples/rts_main.rb +9 -0
  8. data/doc/examples/rts_shared_code.rb +25 -0
  9. data/lib/rubinium.rb +9 -0
  10. data/lib/rubinium/string.rb +3 -0
  11. data/lib/rubinium/test_base.rb +80 -0
  12. data/lib/rubinium/test_suite.rb +53 -0
  13. data/lib/rubinium/validator.rb +16 -0
  14. data/test/selenium_tests/test_click.rb +22 -0
  15. data/test/selenium_tests/test_open.rb +11 -0
  16. data/test/tc_file_creation.rb +60 -0
  17. data/test/ts_rubinium.rb +1 -0
  18. data/vendor/selenium-0.6.0/install-readme.txt +9 -0
  19. data/vendor/selenium-0.6.0/selenium/SeleneseRunner.html +253 -0
  20. data/vendor/selenium-0.6.0/selenium/SeleniumLog.html +61 -0
  21. data/vendor/selenium-0.6.0/selenium/TestRunner-splash.html +55 -0
  22. data/vendor/selenium-0.6.0/selenium/TestRunner.hta +146 -0
  23. data/vendor/selenium-0.6.0/selenium/TestRunner.html +146 -0
  24. data/vendor/selenium-0.6.0/selenium/devtests/TestClickInFrame.html +58 -0
  25. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenInFrame.html +48 -0
  26. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenInNewWindow.html +78 -0
  27. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenMeta.html +43 -0
  28. data/vendor/selenium-0.6.0/selenium/devtests/TestSuite.html +39 -0
  29. data/vendor/selenium-0.6.0/selenium/devtests/meta/page.html +5 -0
  30. data/vendor/selenium-0.6.0/selenium/dom-images/butmin.gif +0 -0
  31. data/vendor/selenium-0.6.0/selenium/dom-images/butplus.gif +0 -0
  32. data/vendor/selenium-0.6.0/selenium/dom-styles/default.css +298 -0
  33. data/vendor/selenium-0.6.0/selenium/domviewer.html +16 -0
  34. data/vendor/selenium-0.6.0/selenium/html-xpath/carnation.jpg +0 -0
  35. data/vendor/selenium-0.6.0/selenium/html-xpath/example.html +75 -0
  36. data/vendor/selenium-0.6.0/selenium/html-xpath/html-xpath-patched.js +657 -0
  37. data/vendor/selenium-0.6.0/selenium/html-xpath/html-xpath.js +610 -0
  38. data/vendor/selenium-0.6.0/selenium/html-xpath/license.txt +504 -0
  39. data/vendor/selenium-0.6.0/selenium/html-xpath/rainbow.jpg +0 -0
  40. data/vendor/selenium-0.6.0/selenium/htmlutils.js +283 -0
  41. data/vendor/selenium-0.6.0/selenium/index.html +60 -0
  42. data/vendor/selenium-0.6.0/selenium/jsmock/mock-tests.html +205 -0
  43. data/vendor/selenium-0.6.0/selenium/jsmock/mock.js +124 -0
  44. data/vendor/selenium-0.6.0/selenium/selenium-api.js +683 -0
  45. data/vendor/selenium-0.6.0/selenium/selenium-browserbot.js +930 -0
  46. data/vendor/selenium-0.6.0/selenium/selenium-commandhandlers.js +286 -0
  47. data/vendor/selenium-0.6.0/selenium/selenium-domviewer.js +188 -0
  48. data/vendor/selenium-0.6.0/selenium/selenium-executionloop.js +250 -0
  49. data/vendor/selenium-0.6.0/selenium/selenium-fitrunner.js +597 -0
  50. data/vendor/selenium-0.6.0/selenium/selenium-logging.js +88 -0
  51. data/vendor/selenium-0.6.0/selenium/selenium-logo.png +0 -0
  52. data/vendor/selenium-0.6.0/selenium/selenium-tableparser.js +50 -0
  53. data/vendor/selenium-0.6.0/selenium/selenium.css +211 -0
  54. data/vendor/selenium-0.6.0/selenium/tests/ErrorCheckingTestSuite.html +36 -0
  55. data/vendor/selenium-0.6.0/selenium/tests/GoogleTestSearch.html +69 -0
  56. data/vendor/selenium-0.6.0/selenium/tests/GoogleTestSuite.html +32 -0
  57. data/vendor/selenium-0.6.0/selenium/tests/JsUnitSuite.html +38 -0
  58. data/vendor/selenium-0.6.0/selenium/tests/TestClick.html +128 -0
  59. data/vendor/selenium-0.6.0/selenium/tests/TestClickJavascriptHref.html +115 -0
  60. data/vendor/selenium-0.6.0/selenium/tests/TestCommandError.html +79 -0
  61. data/vendor/selenium-0.6.0/selenium/tests/TestConfirmations.html +77 -0
  62. data/vendor/selenium-0.6.0/selenium/tests/TestErrorChecking.html +71 -0
  63. data/vendor/selenium-0.6.0/selenium/tests/TestFailingAssert.html +59 -0
  64. data/vendor/selenium-0.6.0/selenium/tests/TestFailingVerifications.html +198 -0
  65. data/vendor/selenium-0.6.0/selenium/tests/TestFocusOnBlur.html +53 -0
  66. data/vendor/selenium-0.6.0/selenium/tests/TestGoBack.html +81 -0
  67. data/vendor/selenium-0.6.0/selenium/tests/TestImplicitLocators.html +81 -0
  68. data/vendor/selenium-0.6.0/selenium/tests/TestJavascriptParameters.html +91 -0
  69. data/vendor/selenium-0.6.0/selenium/tests/TestLocators.html +161 -0
  70. data/vendor/selenium-0.6.0/selenium/tests/TestModalDialog.html +58 -0
  71. data/vendor/selenium-0.6.0/selenium/tests/TestModalDialogDialog.html +48 -0
  72. data/vendor/selenium-0.6.0/selenium/tests/TestOpen.html +66 -0
  73. data/vendor/selenium-0.6.0/selenium/tests/TestPatternMatching.html +127 -0
  74. data/vendor/selenium-0.6.0/selenium/tests/TestPause.html +78 -0
  75. data/vendor/selenium-0.6.0/selenium/tests/TestPrompting.html +82 -0
  76. data/vendor/selenium-0.6.0/selenium/tests/TestProxy.html +62 -0
  77. data/vendor/selenium-0.6.0/selenium/tests/TestSelect.html +111 -0
  78. data/vendor/selenium-0.6.0/selenium/tests/TestSelectWindow.html +106 -0
  79. data/vendor/selenium-0.6.0/selenium/tests/TestStore.html +165 -0
  80. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-InternetExplorer.html +79 -0
  81. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-Konqueror.html +75 -0
  82. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-Safari.html +75 -0
  83. data/vendor/selenium-0.6.0/selenium/tests/TestSuite.html +75 -0
  84. data/vendor/selenium-0.6.0/selenium/tests/TestType.html +79 -0
  85. data/vendor/selenium-0.6.0/selenium/tests/TestUserExtensions.html +81 -0
  86. data/vendor/selenium-0.6.0/selenium/tests/TestVerifications.html +164 -0
  87. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyAlerts.html +80 -0
  88. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyAlertsFailures.html +108 -0
  89. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyConfirmationFailures.html +86 -0
  90. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyEditable.html +70 -0
  91. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyEditableFailures.html +95 -0
  92. data/vendor/selenium-0.6.0/selenium/tests/TestVisibility.html +91 -0
  93. data/vendor/selenium-0.6.0/selenium/tests/TestVisibilityFailures.html +131 -0
  94. data/vendor/selenium-0.6.0/selenium/tests/TestWait.html +112 -0
  95. data/vendor/selenium-0.6.0/selenium/tests/TestWaitFor.html +63 -0
  96. data/vendor/selenium-0.6.0/selenium/tests/TestWaitInPopupWindow.html +94 -0
  97. data/vendor/selenium-0.6.0/selenium/tests/TestXPathLocators.html +98 -0
  98. data/vendor/selenium-0.6.0/selenium/tests/browserbot/alert-handling-tests.html +79 -0
  99. data/vendor/selenium-0.6.0/selenium/tests/browserbot/assert-tests.html +113 -0
  100. data/vendor/selenium-0.6.0/selenium/tests/browserbot/browserbot-tests.html +123 -0
  101. data/vendor/selenium-0.6.0/selenium/tests/browserbot/command-factory-tests.html +290 -0
  102. data/vendor/selenium-0.6.0/selenium/tests/browserbot/command-handler-tests.html +115 -0
  103. data/vendor/selenium-0.6.0/selenium/tests/browserbot/confirm-handling-tests.html +97 -0
  104. data/vendor/selenium-0.6.0/selenium/tests/browserbot/error-checking-command-tests.html +198 -0
  105. data/vendor/selenium-0.6.0/selenium/tests/browserbot/event-bubble-tests.html +106 -0
  106. data/vendor/selenium-0.6.0/selenium/tests/browserbot/optionlocator-tests.html +180 -0
  107. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-accessor-tests.html +65 -0
  108. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-action-tests.html +200 -0
  109. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-attribute-tests.html +98 -0
  110. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-locator-tests-include.html +33 -0
  111. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-locator-tests.html +258 -0
  112. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-property-tests.html +49 -0
  113. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pattern-matcher-tests.html +66 -0
  114. data/vendor/selenium-0.6.0/selenium/tests/browserbot/selenium-api-tests.html +412 -0
  115. data/vendor/selenium-0.6.0/selenium/tests/browserbot/selenium-parameter-tests.html +98 -0
  116. data/vendor/selenium-0.6.0/selenium/tests/browserbot/suite.html +52 -0
  117. data/vendor/selenium-0.6.0/selenium/tests/browserbot/testloop-handle-error-tests.html +74 -0
  118. data/vendor/selenium-0.6.0/selenium/tests/events/TestButtonEvents.html +72 -0
  119. data/vendor/selenium-0.6.0/selenium/tests/events/TestCheckboxEvents.html +107 -0
  120. data/vendor/selenium-0.6.0/selenium/tests/events/TestFireEvents.html +75 -0
  121. data/vendor/selenium-0.6.0/selenium/tests/events/TestLinkEvents.html +43 -0
  122. data/vendor/selenium-0.6.0/selenium/tests/events/TestRadioEvents.html +149 -0
  123. data/vendor/selenium-0.6.0/selenium/tests/events/TestSelectEvents.html +122 -0
  124. data/vendor/selenium-0.6.0/selenium/tests/events/TestTextEvents.html +87 -0
  125. data/vendor/selenium-0.6.0/selenium/tests/events/readme.txt +26 -0
  126. data/vendor/selenium-0.6.0/selenium/tests/html/banner.gif +0 -0
  127. data/vendor/selenium-0.6.0/selenium/tests/html/test_async_event.html +36 -0
  128. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_javascript_page.html +34 -0
  129. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_page1.html +31 -0
  130. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_page2.html +30 -0
  131. data/vendor/selenium-0.6.0/selenium/tests/html/test_confirm.html +34 -0
  132. data/vendor/selenium-0.6.0/selenium/tests/html/test_dummy_page.html +26 -0
  133. data/vendor/selenium-0.6.0/selenium/tests/html/test_editable.html +36 -0
  134. data/vendor/selenium-0.6.0/selenium/tests/html/test_focus_on_blur.html +33 -0
  135. data/vendor/selenium-0.6.0/selenium/tests/html/test_form_events.html +98 -0
  136. data/vendor/selenium-0.6.0/selenium/tests/html/test_framed_page.html +7 -0
  137. data/vendor/selenium-0.6.0/selenium/tests/html/test_just_text.html +22 -0
  138. data/vendor/selenium-0.6.0/selenium/tests/html/test_locators.html +34 -0
  139. data/vendor/selenium-0.6.0/selenium/tests/html/test_modal_dialog.html +29 -0
  140. data/vendor/selenium-0.6.0/selenium/tests/html/test_modal_dialog_dialog.html +35 -0
  141. data/vendor/selenium-0.6.0/selenium/tests/html/test_open.html +23 -0
  142. data/vendor/selenium-0.6.0/selenium/tests/html/test_prompt.html +34 -0
  143. data/vendor/selenium-0.6.0/selenium/tests/html/test_reload_onchange_page.html +32 -0
  144. data/vendor/selenium-0.6.0/selenium/tests/html/test_select.html +35 -0
  145. data/vendor/selenium-0.6.0/selenium/tests/html/test_select_window.html +29 -0
  146. data/vendor/selenium-0.6.0/selenium/tests/html/test_select_window_popup.html +28 -0
  147. data/vendor/selenium-0.6.0/selenium/tests/html/test_slowloading_page.html +27 -0
  148. data/vendor/selenium-0.6.0/selenium/tests/html/test_store_value.html +23 -0
  149. data/vendor/selenium-0.6.0/selenium/tests/html/test_type_page1.html +37 -0
  150. data/vendor/selenium-0.6.0/selenium/tests/html/test_type_page2.html +61 -0
  151. data/vendor/selenium-0.6.0/selenium/tests/html/test_verifications.html +42 -0
  152. data/vendor/selenium-0.6.0/selenium/tests/html/test_verify_alert.html +46 -0
  153. data/vendor/selenium-0.6.0/selenium/tests/html/test_visibility.html +53 -0
  154. data/vendor/selenium-0.6.0/selenium/tests/readme.txt +1 -0
  155. data/vendor/selenium-0.6.0/selenium/tests/tableparser/tableparser-tests.html +122 -0
  156. data/vendor/selenium-0.6.0/selenium/tests/tinyWebServer.py +70 -0
  157. data/vendor/selenium-0.6.0/selenium/user-extensions.js.sample +62 -0
  158. data/vendor/selenium-0.6.0/selenium/version.txt +1 -0
  159. data/vendor/selenium-0.6.0/selenium/xmlextras.js +153 -0
  160. data/vendor/selenium-0.6.0/selenium/xpath.js +3910 -0
  161. metadata +216 -0
@@ -0,0 +1,286 @@
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
+ function CommandHandlerFactory() {
18
+ this.actions = {};
19
+ this.asserts = {};
20
+ this.accessors = {};
21
+
22
+ var self = this;
23
+
24
+ this.registerAction = function(name, action, wait) {
25
+ var handler = new ActionHandler(action, wait);
26
+ this.actions[name] = handler;
27
+ };
28
+
29
+ this.registerAccessor = function(name, accessor) {
30
+ var handler = new AccessorHandler(accessor);
31
+ this.accessors[name] = handler;
32
+ };
33
+
34
+ this.registerAssert = function(name, assertion, haltOnFailure) {
35
+ var handler = new AssertHandler(assertion, haltOnFailure);
36
+ this.asserts[name] = handler;
37
+ };
38
+
39
+ self.registerAssertUsingMatcherHandler = function(name, matcherHandler, haltOnFailure) {
40
+ var handler = new AssertUsingMatcherHandler(matcherHandler, haltOnFailure);
41
+ this.asserts[name] = handler;
42
+ }
43
+
44
+ this.getCommandHandler = function(name) {
45
+ return this.actions[name] || this.accessors[name] || this.asserts[name] || null;
46
+ };
47
+
48
+ this.registerAll = function(commandObject) {
49
+ registerAllActions(commandObject);
50
+ registerAllAsserts(commandObject);
51
+ registerAllAccessors(commandObject);
52
+ };
53
+
54
+ var registerAllActions = function(commandObject) {
55
+ for (var functionName in commandObject) {
56
+ var result = /^do([A-Z].+)$/.exec(functionName);
57
+ if (result != null) {
58
+ var actionName = result[1].lcfirst();
59
+
60
+ // Register the action without the wait flag.
61
+ var action = commandObject[functionName];
62
+ self.registerAction(actionName, action, false);
63
+
64
+ // Register actionName + "AndWait" with the wait flag;
65
+ var waitActionName = actionName + "AndWait";
66
+ self.registerAction(waitActionName, action, true);
67
+ }
68
+ }
69
+ };
70
+
71
+ var registerAllAsserts = function(commandObject) {
72
+ for (var functionName in commandObject) {
73
+ var result = /^assert([A-Z].+)$/.exec(functionName);
74
+ if (result != null) {
75
+ var assert = commandObject[functionName];
76
+
77
+ // Register the assert with the "assert" prefix, and halt on failure.
78
+ var assertName = functionName;
79
+ self.registerAssert(assertName, assert, true);
80
+
81
+ // Register the assert with the "verify" prefix, and do not halt on failure.
82
+ var verifyName = "verify" + result[1];
83
+ self.registerAssert(verifyName, assert, false);
84
+ }
85
+ }
86
+ };
87
+
88
+ // Given an accessor function, return a function that matches against the command.value
89
+ // the value returned by the accessor when applied to a command.target.
90
+ // Used by commands that take a target and a value (e.g. assertValue | target | value)
91
+ this.createMatcherHandlerFromSingleArgAccessor = function(accessor) {
92
+ return function(seleniumApi, command) {
93
+ var accessorResult = accessor.call(seleniumApi, command.target);
94
+ if (PatternMatcher.matches(command.value, accessorResult)) {
95
+ return new MatcherHandlerResult(true, "Actual value '" + accessorResult + "' did match '" + command.value + "'");
96
+ } else {
97
+ return new MatcherHandlerResult(false, "Actual value '" + accessorResult + "' did not match '" + command.value + "'");
98
+ }
99
+ };
100
+ };
101
+
102
+ // Given an accessor function, return a function that matches against the command.target
103
+ // the value returned by the (no-arg) accessor returns a value that matches against the command.target
104
+ // Used by commands that only take a target (e.g. assertTitle | target |  )
105
+ this.createMatcherHandlerFromNoArgAccessor = function(accessor) {
106
+ return function(seleniumApi, command) {
107
+ var accessorResult = accessor.call(seleniumApi);
108
+ if (PatternMatcher.matches(command.target, accessorResult)) {
109
+ return new MatcherHandlerResult(true, "Actual value '" + accessorResult + "' did match '" + command.target + "'");
110
+ } else {
111
+ return new MatcherHandlerResult(false, "Actual value '" + accessorResult + "' did not match '" + command.target + "'");
112
+ }
113
+ };
114
+ };
115
+
116
+ // Given a matcherHandler function, return a function that returns the same result
117
+ // as the matcherHandler, but with the result negated.
118
+ // Used to create assertNot and verifyNot commands (and soon hopefully waitForNot commands).
119
+ this.createMatcherHandlerNegator = function(matcherHandler) {
120
+ return function(seleniumApi, command) {
121
+ var result = matcherHandler(seleniumApi, command);
122
+ result.didMatch = ! result.didMatch;
123
+ return result;
124
+ };
125
+ };
126
+
127
+
128
+ // Methods of the form getFoo(target) result in commands:
129
+ // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
130
+ var registerAllAccessors = function(commandObject) {
131
+ for (var functionName in commandObject) {
132
+ var match = /^get([A-Z].+)$/.exec(functionName);
133
+ if (match != null) {
134
+ var accessor = commandObject[functionName];
135
+ var baseName = match[1];
136
+ self.registerAccessor(functionName, accessor);
137
+
138
+ if (accessor.length > 1) {
139
+ continue;
140
+ }
141
+ var matcherHandler;
142
+ if (accessor.length == 1) {
143
+ matcherHandler = self.createMatcherHandlerFromSingleArgAccessor(accessor);
144
+ } else {
145
+ matcherHandler = self.createMatcherHandlerFromNoArgAccessor(accessor);
146
+ }
147
+ // Register an assert with the "assert" prefix, and halt on failure.
148
+ self.registerAssertUsingMatcherHandler("assert" + baseName, matcherHandler, true);
149
+ // Register a verify with the "verify" prefix, and do not halt on failure.
150
+ self.registerAssertUsingMatcherHandler("verify" + baseName, matcherHandler, false);
151
+
152
+ var negativeMatcherHandler = self.createMatcherHandlerNegator(matcherHandler);
153
+ // Register an assertNot with the "assertNot" prefix, and halt on failure.
154
+ self.registerAssertUsingMatcherHandler("assertNot"+baseName, negativeMatcherHandler, true);
155
+ // Register a verifyNot with the "verifyNot" prefix, and do not halt on failure.
156
+ self.registerAssertUsingMatcherHandler("verifyNot"+baseName, negativeMatcherHandler, false);
157
+ }
158
+ }
159
+ };
160
+
161
+ }
162
+
163
+ function MatcherHandlerResult(didMatch, message) {
164
+ this.didMatch = didMatch;
165
+ this.message = message;
166
+ }
167
+
168
+ // NOTE: The CommandHandler is effectively an abstract base for ActionHandler,
169
+ // AccessorHandler and AssertHandler.
170
+ function CommandHandler(type, haltOnFailure, executor) {
171
+ this.type = type;
172
+ this.haltOnFailure = haltOnFailure;
173
+ this.executor = executor;
174
+ }
175
+ CommandHandler.prototype.execute = function(seleniumApi, command) {
176
+ return new CommandResult(this.executor.call(seleniumApi, command.target, command.value));
177
+ };
178
+
179
+ function ActionHandler(action, wait) {
180
+ CommandHandler.call(this, "action", true, action);
181
+ if (wait) {
182
+ this.wait = true;
183
+ }
184
+ }
185
+ ActionHandler.prototype = new CommandHandler;
186
+ ActionHandler.prototype.execute = function(seleniumApi, command) {
187
+ if ( seleniumApi.browserbot.hasAlerts() ) {
188
+ throw new SeleniumCommandError("There was an unexpected Alert! [" + seleniumApi.browserbot.getNextAlert() + "]");
189
+ }
190
+ if ( seleniumApi.browserbot.hasConfirmations() ) {
191
+ throw new SeleniumCommandError("There was an unexpected Confirmation! [" + seleniumApi.browserbot.getNextConfirmation() + "]");
192
+ }
193
+ var processState = this.executor.call(seleniumApi, command.target, command.value);
194
+ // If the handler didn't return a wait flag, check to see if the
195
+ // handler was registered with the wait flag.
196
+ if (processState == undefined && this.wait) {
197
+ processState = SELENIUM_PROCESS_WAIT;
198
+ }
199
+ return new CommandResult(processState);
200
+ };
201
+
202
+ function AccessorHandler(accessor) {
203
+ CommandHandler.call(this, "accessor", true, accessor);
204
+ }
205
+ AccessorHandler.prototype = new CommandHandler;
206
+ AccessorHandler.prototype.execute = function(seleniumApi, command) {
207
+ var returnValue = this.executor.call(seleniumApi, command.target, command.value);
208
+ var result = new CommandResult();
209
+ result.result = returnValue;
210
+ return result;
211
+ };
212
+
213
+ /**
214
+ * Abstract handler for assertions and verifications.
215
+ * Subclasses need to override executeAssertion() which in turn
216
+ * should throw an AssertFailedError if the assertion is to fail.
217
+ */
218
+ function AbstractAssertHandler(assertion, haltOnFailure) {
219
+ CommandHandler.call(this, "assert", haltOnFailure || false, assertion);
220
+ }
221
+ AbstractAssertHandler.prototype = new CommandHandler;
222
+ AbstractAssertHandler.prototype.execute = function(seleniumApi, command) {
223
+ var result = new CommandResult();
224
+ try {
225
+ this.executeAssertion(seleniumApi, command);
226
+ result.passed = true;
227
+ } catch (e) {
228
+ // If this is not a AssertionFailedError, or we should haltOnFailure, rethrow.
229
+ if (!e.isAssertionFailedError) {
230
+ throw e;
231
+ }
232
+ if (this.haltOnFailure) {
233
+ var error = new SeleniumCommandError(e.failureMessage);
234
+ throw error;
235
+ }
236
+ result.failed = true;
237
+ result.failureMessage = e.failureMessage;
238
+ }
239
+ return result;
240
+ };
241
+
242
+ /**
243
+ * Simple assertion handler whose command is expected to do the actual assertion.
244
+ */
245
+ function AssertHandler(assertion, haltOnFailure) {
246
+ CommandHandler.call(this, "assert", haltOnFailure || false, assertion);
247
+ };
248
+ AssertHandler.prototype = new AbstractAssertHandler;
249
+ AssertHandler.prototype.executeAssertion = function(seleniumApi, command) {
250
+ this.executor.call(seleniumApi, command.target, command.value);
251
+ };
252
+
253
+ /**
254
+ * Assertion handler whose command is expected to be a matcher-handler
255
+ */
256
+ function AssertUsingMatcherHandler(matcherHandler, haltOnFailure) {
257
+ CommandHandler.call(this, "assert", haltOnFailure || false, matcherHandler);
258
+ };
259
+ AssertUsingMatcherHandler.prototype = new AbstractAssertHandler;
260
+ AssertUsingMatcherHandler.prototype.executeAssertion = function(seleniumApi, command) {
261
+ var matcherResult = this.executor(seleniumApi, command);
262
+ if (!matcherResult.didMatch) {
263
+ Assert.fail(matcherResult.message);
264
+ }
265
+ };
266
+
267
+
268
+ function CommandResult(processState) {
269
+ this.processState = processState;
270
+ this.result = "OK";
271
+ }
272
+
273
+ function SeleniumCommand(command, target, value) {
274
+ this.command = command;
275
+ this.target = target;
276
+ this.value = value;
277
+ }
278
+
279
+ // TODO: dkemp - This is the same as SeleniumError as defined in selenium-browserbot.js
280
+ // I defined a new error simply to avoid creating a new dependency.
281
+ // Need to revisit to avoid this duplication.
282
+ function SeleniumCommandError(message) {
283
+ var error = new Error(message);
284
+ error.isSeleniumError = true;
285
+ return error;
286
+ };
@@ -0,0 +1,188 @@
1
+ var HIDDEN="hidden";
2
+ var LEVEL = "level";
3
+ var PLUS_SRC="dom-images/butplus.gif";
4
+ var MIN_SRC="dom-images/butmin.gif";
5
+ var newRoot;
6
+ var maxColumns=1;
7
+
8
+ function loadDomViewer() {
9
+ // See if the rootDocument variable has been set on this window.
10
+ var rootDocument = window.rootDocument;
11
+
12
+ // If not look to the opener for an explicity rootDocument variable, otherwise, use the opener document
13
+ if (!rootDocument && window.opener) {
14
+ rootDocument = window.opener.rootDocument || window.opener.document;
15
+ }
16
+
17
+ if (rootDocument) {
18
+ document.body.innerHTML = displayDOM(rootDocument);
19
+ }
20
+ else {
21
+ document.body.innerHTML = "<b>Must specify rootDocument for window. This can be done by setting the rootDocument variable on this window, or on the opener window for a popup window.</b>";
22
+ }
23
+ }
24
+
25
+
26
+ function displayDOM(root){
27
+ var str = "";
28
+ str+="<table>";
29
+ str += treeTraversal(root,0);
30
+ // to make table columns work well.
31
+ str += "<tr>";
32
+ for (var i=0; i < maxColumns; i++) {
33
+ str+= "<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
34
+ }
35
+ str += "</tr>";
36
+ str += "</table>";
37
+ return str;
38
+ }
39
+
40
+ function checkForChildren(element){
41
+ if(!element.hasChildNodes())
42
+ return false;
43
+
44
+ var nodes = element.childNodes;
45
+ var size = nodes.length;
46
+ var count=0;
47
+
48
+ for(var i=0; i< size; i++){
49
+ var node = nodes.item(i);
50
+ //if(node.toString()=="[object Text]"){
51
+ //this is equalent to the above
52
+ //but will work with more browsers
53
+ if(node.nodeType!=1){
54
+ count++;
55
+ }
56
+ }
57
+
58
+ if(count == size)
59
+ return false;
60
+ else
61
+ return true;
62
+ }
63
+
64
+ function treeTraversal(root, level){
65
+ var str = "";
66
+ var nodes= null;
67
+ var size = null;
68
+ //it is supposed to show the last node,
69
+ //but the last node is always nodeText type
70
+ //and we don't show it
71
+ if(!root.hasChildNodes())
72
+ return "";//displayNode(root,level,false);
73
+
74
+ nodes = root.childNodes;
75
+ size = nodes.length;
76
+
77
+ for(var i=0; i< size; i++){
78
+ var element = nodes.item(i);
79
+ //if the node is textNode, don't display
80
+ if(element.nodeType==1){
81
+ str+= displayNode(element,level,checkForChildren(element));
82
+ str+=treeTraversal(element, level+1);
83
+ }
84
+ }
85
+ return str;
86
+ }
87
+
88
+ function displayNode(element, level, isLink){
89
+ nodeContent = getNodeContent(element);
90
+ columns = Math.round((nodeContent.length / 12) + 0.5);
91
+ if (columns + level > maxColumns) {
92
+ maxColumns = columns + level;
93
+ }
94
+ var str ="<tr class='"+LEVEL+level+"'>";
95
+ for (var i=0; i < level; i++)
96
+ str+= "<td> </td>";
97
+ str+="<td colspan='"+ columns +"' class='box"+" boxlevel"+level+"' >";
98
+ if(isLink){
99
+ str+='<a onclick="hide(this);return false;" href="javascript:void();">';
100
+ str+='<img src="'+MIN_SRC+'" />';
101
+ }
102
+ str += nodeContent;
103
+ if(isLink)
104
+ str+="</a></td></tr>";
105
+ return str;
106
+ }
107
+
108
+ function getNodeContent(element) {
109
+ str = "";
110
+ id ="";
111
+ if (element.id != null && element.id != "") {
112
+ id = " ID(" + element.id +")";
113
+ }
114
+ name ="";
115
+ if (element.name != null && element.name != "") {
116
+ name = " NAME(" + element.name + ")";
117
+ }
118
+ value ="";
119
+ if (element.value != null && element.value != "") {
120
+ value = " VALUE(" + element.value + ")";
121
+ }
122
+ href ="";
123
+ if (element.href != null && element.href != "") {
124
+ href = " HREF(" + element.href + ")";
125
+ }
126
+ text ="";
127
+ if (element.text != null && element.text != "" && element.text != "undefined") {
128
+ text = " #TEXT(" + trim(element.text) +")";
129
+ }
130
+ str+=" <b>"+ element.nodeName + id + name + value + href + text + "</b>";
131
+ return str;
132
+
133
+ }
134
+
135
+ function trim(val) {
136
+ val2 = val.substring(0,20) + " ";
137
+ var spaceChr = String.fromCharCode(32);
138
+ var length = val2.length;
139
+ var retVal = "";
140
+ var ix = length -1;
141
+
142
+ while(ix > -1){
143
+ if(val2.charAt(ix) == spaceChr) {
144
+ } else {
145
+ retVal = val2.substring(0, ix +1);
146
+ break;
147
+ }
148
+ ix = ix-1;
149
+ }
150
+ if (val.length > 20) {
151
+ retVal += "...";
152
+ }
153
+ return retVal;
154
+ }
155
+
156
+ function hide(hlink){
157
+ var isHidden = false;
158
+ var image = hlink.firstChild;
159
+ if(image.src.toString().indexOf(MIN_SRC)!=-1){
160
+ image.src=PLUS_SRC;
161
+ isHidden=true;
162
+ }else{
163
+ image.src=MIN_SRC;
164
+ }
165
+ var rowObj= hlink.parentNode.parentNode;
166
+ var rowLevel = parseInt(rowObj.className.substring(LEVEL.length));
167
+
168
+ var sibling = rowObj.nextSibling;
169
+ var siblingLevel = sibling.className.substring(LEVEL.length);
170
+ if(siblingLevel.indexOf(HIDDEN)!=-1){
171
+ siblingLevel = siblingLevel.substring(0,siblingLevel.length - HIDDEN.length-1);
172
+ }
173
+ siblingLevel=parseInt(siblingLevel);
174
+ while(sibling!=null && rowLevel<siblingLevel){
175
+ if(isHidden){
176
+ sibling.className += " "+ HIDDEN;
177
+ }else if(!isHidden && sibling.className.indexOf(HIDDEN)!=-1){
178
+ var str = sibling.className;
179
+ sibling.className=str.substring(0, str.length - HIDDEN.length-1);
180
+ }
181
+ sibling = sibling.nextSibling;
182
+ siblingLevel = parseInt(sibling.className.substring(LEVEL.length));
183
+ }
184
+ }
185
+
186
+ function LOG(message) {
187
+ window.opener.LOG.warn(message);
188
+ }