rubinium 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,250 @@
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
+ SELENIUM_PROCESS_WAIT = "wait";
18
+
19
+ starting_up = true;
20
+ TEST_FINISHED = true;
21
+ TEST_CONTINUE = false;
22
+
23
+ function TestLoop(commandFactory) {
24
+ this.commandFactory = commandFactory;
25
+
26
+ this.start = function() {
27
+ selenium.reset();
28
+ this.continueCurrentTest();
29
+ };
30
+
31
+ this.continueCurrentTest = function() {
32
+ var testStatus = this.kickoffNextCommandExecution();
33
+
34
+ if (testStatus == TEST_FINISHED) {
35
+ this.testComplete();
36
+ }
37
+ };
38
+
39
+ this.kickoffNextCommandExecution = function() {
40
+
41
+ var command;
42
+ if (starting_up == true) {
43
+ command = this.firstCommand();
44
+ starting_up = false;
45
+ } else {
46
+ command = this.nextCommand();
47
+ }
48
+
49
+ if (!command) return TEST_FINISHED;
50
+
51
+ this.commandStarted(command);
52
+
53
+ LOG.info("Executing: |" + command.command + " | " + command.target + " | " + command.value + " |");
54
+
55
+ var result;
56
+ try {
57
+ var handler = this.commandFactory.getCommandHandler(command.command);
58
+ if(handler == null) {
59
+ throw new Error("Unknown command: '" + command.command + "'");
60
+ }
61
+
62
+ command.target = selenium.preprocessParameter(command.target);
63
+ command.value = selenium.preprocessParameter(command.value);
64
+
65
+ result = handler.execute(selenium, command);
66
+ } catch (e) {
67
+ this.handleCommandError(e);
68
+ return TEST_FINISHED;
69
+ }
70
+
71
+ // Record the result so that we can continue the execution using
72
+ // window.setTimeout()
73
+ this.lastCommandResult = result;
74
+ if (result.processState == SELENIUM_PROCESS_WAIT) {
75
+ this.waitForCondition = function() {
76
+ return selenium.browserbot.isNewPageLoaded();
77
+ };
78
+ }
79
+
80
+ if (this.waitForCondition) {
81
+ this.pollUntilConditionIsTrue();
82
+ } else {
83
+ // Continue processing
84
+ this.continueCommandExecutionWithDelay();
85
+ }
86
+
87
+ // Test is not finished.
88
+ return TEST_CONTINUE;
89
+ };
90
+
91
+ this.handleCommandError = function(e) {
92
+ if (!e.isSeleniumError) {
93
+ LOG.exception(e);
94
+ var msg = "Selenium failure. Please report to selenium-devel@lists.public.thoughtworks.org, with details from the logs at the base of the page.";
95
+ if (e.message) {
96
+ msg += " The error message is: " + e.message;
97
+ }
98
+ this.commandError(msg);
99
+ } else {
100
+ LOG.error(e.message);
101
+ this.commandError(e.message);
102
+ }
103
+ };
104
+
105
+ /**
106
+ * Busy wait for waitForCondition() to become true, and then continue
107
+ * command execution.
108
+ */
109
+ this.pollUntilConditionIsTrue = function () {
110
+ if (this.waitForCondition()) {
111
+ this.waitForCondition = null;
112
+ this.continueCommandExecutionWithDelay();
113
+ } else {
114
+ window.setTimeout("testLoop.pollUntilConditionIsTrue()", 10);
115
+ }
116
+ };
117
+
118
+
119
+ /**
120
+ * Continue the command execution, after waiting for the specified
121
+ * delay.
122
+ */
123
+ this.continueCommandExecutionWithDelay = function() {
124
+ // Get the interval to use for this command execution, using the pauseInterval as
125
+ // specified. Reset the pause interval, since it's a one-off thing.
126
+ var interval = this.pauseInterval || this.getCommandInterval();
127
+ this.pauseInterval = undefined;
128
+
129
+ if (interval < 0) {
130
+ // Enable the "next/continue" button
131
+ this.pause();
132
+ }
133
+ else {
134
+ // Continue processing
135
+ window.setTimeout("testLoop.finishCommandExecution()", interval);
136
+ }
137
+ };
138
+
139
+ /**
140
+ * Finish the execution of the previous command, and continue the test.
141
+ */
142
+ this.finishCommandExecution = function() {
143
+ this.commandComplete(this.lastCommandResult);
144
+ this.continueCurrentTest();
145
+ };
146
+ }
147
+
148
+ /** The default is not to have any interval between commands. */
149
+ TestLoop.prototype.getCommandInterval = function() {
150
+ return 0;
151
+ };
152
+
153
+ TestLoop.prototype.firstCommand = noop;
154
+
155
+ TestLoop.prototype.nextCommand = noop;
156
+
157
+ TestLoop.prototype.commandStarted = noop;
158
+
159
+ TestLoop.prototype.commandError = noop;
160
+
161
+ TestLoop.prototype.commandComplete = noop;
162
+
163
+ TestLoop.prototype.testComplete = noop;
164
+
165
+ TestLoop.prototype.pause = noop;
166
+
167
+ function noop() {
168
+
169
+ };
170
+
171
+ /**
172
+ * Tell Selenium to expect a failure on the next command execution. This
173
+ * command temporarily installs a CommandFactory that generates
174
+ * CommandHandlers that expect a failure.
175
+ */
176
+ Selenium.prototype.assertFailureOnNext = function(message) {
177
+ if (!message) {
178
+ throw new Error("Message must be provided");
179
+ }
180
+
181
+ var expectFailureCommandFactory =
182
+ new ExpectFailureCommandFactory(testLoop.commandFactory, message);
183
+ expectFailureCommandFactory.baseExecutor = executeCommandAndReturnFailureMessage;
184
+ testLoop.commandFactory = expectFailureCommandFactory;
185
+ };
186
+
187
+ /**
188
+ * Tell Selenium to expect an error on the next command execution. This
189
+ * command temporarily installs a CommandFactory that generates
190
+ * CommandHandlers that expect a failure.
191
+ */
192
+ Selenium.prototype.assertErrorOnNext = function(message) {
193
+ if (!message) {
194
+ throw new Error("Message must be provided");
195
+ }
196
+
197
+ var expectFailureCommandFactory =
198
+ new ExpectFailureCommandFactory(testLoop.commandFactory, message);
199
+ expectFailureCommandFactory.baseExecutor = executeCommandAndReturnErrorMessage;
200
+ testLoop.commandFactory = expectFailureCommandFactory;
201
+ };
202
+
203
+ function ExpectFailureCommandFactory(originalCommandFactory, expectedErrorMessage) {
204
+ this.getCommandHandler = function(name) {
205
+ var baseHandler = originalCommandFactory.getCommandHandler(name);
206
+ var baseExecutor = this.baseExecutor;
207
+ var expectFailureCommand = {};
208
+ expectFailureCommand.execute = function() {
209
+ var baseFailureMessage = baseExecutor(baseHandler, arguments);
210
+ var result = new CommandResult();
211
+ if (!baseFailureMessage) {
212
+ result.failed = true;
213
+ result.failureMessage = "Command should have failed.";
214
+ }
215
+ else {
216
+ if (! PatternMatcher.matches(expectedErrorMessage, baseFailureMessage)) {
217
+ result.failed = true;
218
+ result.failureMessage = "Expected failure message '" + expectedErrorMessage
219
+ + "' but was '" + baseFailureMessage + "'";
220
+ }
221
+ else {
222
+ result.passed = true;
223
+ result.result = baseFailureMessage;
224
+ }
225
+ }
226
+ testLoop.commandFactory = originalCommandFactory;
227
+ return result;
228
+ };
229
+ return expectFailureCommand;
230
+ };
231
+ };
232
+
233
+ function executeCommandAndReturnFailureMessage(baseHandler, originalArguments) {
234
+ var baseResult = baseHandler.execute.apply(baseHandler, originalArguments);
235
+ if (baseResult.passed) {
236
+ return null;
237
+ }
238
+ return baseResult.failureMessage;
239
+ };
240
+
241
+ function executeCommandAndReturnErrorMessage(baseHandler, originalArguments) {
242
+ try {
243
+ baseHandler.execute.apply(baseHandler, originalArguments);
244
+ return null;
245
+ }
246
+ catch (expected) {
247
+ return expected.message;
248
+ }
249
+ };
250
+
@@ -0,0 +1,597 @@
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
+ passColor = "#cfffcf";
19
+ failColor = "#ffcfcf";
20
+ workingColor = "#DEE7EC";
21
+
22
+ // The current row in the list of commands (test script)
23
+ currentCommandRow = 0;
24
+ inputTableRows = null;
25
+
26
+ // The current row in the list of tests (test suite)
27
+ currentTestRow = 0;
28
+
29
+ // Whether or not the jsFT should run all tests in the suite
30
+ runAllTests = false;
31
+
32
+ // Whether or not the current test has any errors;
33
+ testFailed = false;
34
+ suiteFailed = false;
35
+
36
+ // Holds the handlers for each command.
37
+ commandHandlers = null;
38
+
39
+ // The number of tests run
40
+ numTestPasses = 0;
41
+
42
+ // The number of tests that have failed
43
+ numTestFailures = 0;
44
+
45
+ // The number of commands which have passed
46
+ numCommandPasses = 0;
47
+
48
+ // The number of commands which have failed
49
+ numCommandFailures = 0;
50
+
51
+ // The number of commands which have caused errors (element not found)
52
+ numCommandErrors = 0;
53
+
54
+ // The time that the test was started.
55
+ startTime = null;
56
+
57
+ // The current time.
58
+ currentTime = null;
59
+
60
+ // An simple enum for failureType
61
+ ERROR = 0;
62
+ FAILURE = 1;
63
+
64
+ runInterval = 0;
65
+
66
+ function setRunInterval() {
67
+ // Get the value of the checked runMode option.
68
+ // There should be a way of getting the value of the "group", but I don't know how.
69
+ var runModeOptions = document.forms['controlPanel'].runMode;
70
+ for (var i = 0; i < runModeOptions.length; i++) {
71
+ if (runModeOptions[i].checked) {
72
+ runInterval = runModeOptions[i].value;
73
+ break;
74
+ }
75
+ }
76
+ }
77
+
78
+ function continueCurrentTest() {
79
+ document.getElementById('continueTest').disabled = true;
80
+ testLoop.finishCommandExecution();
81
+ }
82
+
83
+ function getApplicationFrame() {
84
+ return document.getElementById('myiframe');
85
+ }
86
+
87
+ function getSuiteFrame() {
88
+ return document.getElementById('testSuiteFrame');
89
+ }
90
+
91
+ function getTestFrame(){
92
+ return document.getElementById('testFrame');
93
+ }
94
+
95
+ function loadAndRunIfAuto() {
96
+ loadSuiteFrame();
97
+ }
98
+
99
+ function start() {
100
+ setRunInterval();
101
+ loadSuiteFrame();
102
+ }
103
+
104
+ function loadSuiteFrame() {
105
+ var testAppFrame = document.getElementById('myiframe');
106
+ selenium = Selenium.createForFrame(testAppFrame);
107
+ registerCommandHandlers();
108
+
109
+ //set the runInterval if there is a queryParameter for it
110
+ var tempRunInterval = getQueryParameter("runInterval");
111
+ if (tempRunInterval) {
112
+ runInterval = tempRunInterval;
113
+ }
114
+
115
+ document.getElementById("modeRun").onclick = setRunInterval;
116
+ document.getElementById('modeWalk').onclick = setRunInterval;
117
+ document.getElementById('modeStep').onclick = setRunInterval;
118
+ document.getElementById('continueTest').onclick = continueCurrentTest;
119
+
120
+ var testSuiteName = getQueryParameter("test");
121
+
122
+ if (testSuiteName) {
123
+ addLoadListener(getSuiteFrame(), onloadTestSuite);
124
+ getSuiteFrame().src = testSuiteName;
125
+ } else {
126
+ onloadTestSuite();
127
+ }
128
+ }
129
+
130
+ function startSingleTest() {
131
+ removeLoadListener(getApplicationFrame(), startSingleTest);
132
+ var singleTestName = getQueryParameter("singletest");
133
+ addLoadListener(getTestFrame(), startTest);
134
+ getTestFrame().src = singleTestName;
135
+ }
136
+
137
+ function getIframeDocument(iframe)
138
+ {
139
+ if (iframe.contentDocument) {
140
+ return iframe.contentDocument;
141
+ }
142
+ else {
143
+ return iframe.contentWindow.document;
144
+ }
145
+ }
146
+
147
+ function onloadTestSuite() {
148
+ removeLoadListener(getSuiteFrame(), onloadTestSuite);
149
+ suiteTable = getIframeDocument(getSuiteFrame()).getElementsByTagName("table")[0];
150
+
151
+ // Add an onclick function to each link in the suite table
152
+ for(rowNum = 1;rowNum < suiteTable.rows.length; rowNum++) {
153
+ addOnclick(suiteTable, rowNum);
154
+ }
155
+
156
+
157
+ if (isAutomatedRun()) {
158
+ startTestSuite();
159
+ } else if (getQueryParameter("autoURL")) {
160
+
161
+ addLoadListener(getApplicationFrame(), startSingleTest);
162
+
163
+ getApplicationFrame().src = getQueryParameter("autoURL");
164
+
165
+ } else {
166
+ testLink = suiteTable.rows[currentTestRow+1].cells[0].getElementsByTagName("a")[0];
167
+ getTestFrame().src = testLink.href;
168
+ }
169
+ }
170
+
171
+ // Adds an onclick function to the link in the given row in suite table.
172
+ // This function checks whether the test has already been run and the data is
173
+ // stored. If the data is stored, it sets the test frame to be the stored data.
174
+ // Otherwise, it loads the fresh page.
175
+ function addOnclick(suiteTable, rowNum) {
176
+ aLink = suiteTable.rows[rowNum].cells[0].getElementsByTagName("a")[0];
177
+ aLink.onclick = function(eventObj) {
178
+ srcObj = null;
179
+
180
+ // For mozilla-like browsers
181
+ if(eventObj)
182
+ srcObj = eventObj.target;
183
+
184
+ // For IE-like browsers
185
+ else if (getSuiteFrame().contentWindow.event)
186
+ srcObj = getSuiteFrame().contentWindow.event.srcElement;
187
+
188
+ // The target row (the event source is not consistently reported by browsers)
189
+ row = srcObj.parentNode.parentNode.rowIndex || srcObj.parentNode.parentNode.parentNode.rowIndex;
190
+
191
+ // If the row has a stored results table, use that
192
+ if(suiteTable.rows[row].cells[1]) {
193
+ var bodyElement = getIframeDocument(getTestFrame()).body;
194
+
195
+ // Create a div element to hold the results table.
196
+ var tableNode = getIframeDocument(getTestFrame()).createElement("div");
197
+ var resultsCell = suiteTable.rows[row].cells[1];
198
+ tableNode.innerHTML = resultsCell.innerHTML;
199
+
200
+ // Append this text node, and remove all the preceding nodes.
201
+ bodyElement.appendChild(tableNode);
202
+ while (bodyElement.firstChild != bodyElement.lastChild) {
203
+ bodyElement.removeChild(bodyElement.firstChild);
204
+ }
205
+ }
206
+ // Otherwise, just open up the fresh page.
207
+ else {
208
+ getTestFrame().src = suiteTable.rows[row].cells[0].getElementsByTagName("a")[0].href;
209
+ }
210
+
211
+ return false;
212
+ };
213
+ }
214
+
215
+ function isQueryParameterTrue(name) {
216
+ parameterValue = getQueryParameter(name);
217
+ return (parameterValue != null && parameterValue.toLowerCase() == "true");
218
+ }
219
+
220
+ function getQueryParameter(searchKey) {
221
+ var clauses = location.search.substr(1).split('&');
222
+ for (var i = 0; i < clauses.length; i++) {
223
+ var keyValuePair = clauses[i].split('=',2);
224
+ var key = unescape(keyValuePair[0]);
225
+ if (key == searchKey) {
226
+ return unescape(keyValuePair[1]);
227
+ }
228
+ }
229
+ return null;
230
+ }
231
+
232
+ function isNewWindow() {
233
+ return isQueryParameterTrue("newWindow");
234
+ }
235
+
236
+ function isAutomatedRun() {
237
+ return isQueryParameterTrue("auto");
238
+ }
239
+
240
+ function resetMetrics() {
241
+ numTestPasses = 0;
242
+ numTestFailures = 0;
243
+ numCommandPasses = 0;
244
+ numCommandFailures = 0;
245
+ numCommandErrors = 0;
246
+ startTime = new Date().getTime();
247
+ }
248
+
249
+ function runSingleTest() {
250
+ runAllTests = false;
251
+ resetMetrics();
252
+ startTest();
253
+ }
254
+
255
+ function startTest() {
256
+ removeLoadListener(getTestFrame(), startTest);
257
+
258
+ // Scroll to the top of the test frame
259
+ if (getTestFrame().contentWindow) {
260
+ getTestFrame().contentWindow.scrollTo(0,0);
261
+ }
262
+ else {
263
+ frames['testFrame'].scrollTo(0,0);
264
+ }
265
+
266
+ inputTable = getIframeDocument(getTestFrame()).getElementsByTagName("table")[0];
267
+ inputTableRows = inputTable.rows;
268
+ currentCommandRow = 0;
269
+ testFailed = false;
270
+ storedVars = new Object();
271
+
272
+ clearRowColours();
273
+
274
+ testLoop = initialiseTestLoop();
275
+ testLoop.start();
276
+ }
277
+
278
+ function clearRowColours() {
279
+ for (var i = 0; i <= inputTableRows.length - 1; i++) {
280
+ inputTableRows[i].bgColor = "white";
281
+ }
282
+ }
283
+
284
+ function startTestSuite() {
285
+ resetMetrics();
286
+ currentTestRow = 0;
287
+ runAllTests = true;
288
+ suiteFailed = false;
289
+
290
+ runNextTest();
291
+ }
292
+
293
+ function runNextTest() {
294
+ if (!runAllTests)
295
+ return;
296
+
297
+ suiteTable = getIframeDocument(getSuiteFrame()).getElementsByTagName("table")[0];
298
+
299
+ // Do not change the row color of the first row
300
+ if(currentTestRow > 0) {
301
+ // Make the previous row green or red depending if the test passed or failed
302
+ if(testFailed)
303
+ setCellColor(suiteTable.rows, currentTestRow, 0, failColor);
304
+ else
305
+ setCellColor(suiteTable.rows, currentTestRow, 0, passColor);
306
+
307
+ // Set the results from the previous test run
308
+ setResultsData(suiteTable, currentTestRow);
309
+ }
310
+
311
+ currentTestRow++;
312
+
313
+ // If we are done with all of the tests, set the title bar as pass or fail
314
+ if(currentTestRow >= suiteTable.rows.length) {
315
+ if(suiteFailed)
316
+ setCellColor(suiteTable.rows, 0, 0, failColor);
317
+ else
318
+ setCellColor(suiteTable.rows, 0, 0, passColor);
319
+
320
+ // If this is an automated run (i.e., build script), then submit
321
+ // the test results by posting to a form
322
+ if (isAutomatedRun())
323
+ postTestResults(suiteFailed, suiteTable);
324
+ }
325
+
326
+ else {
327
+ // Make the current row blue
328
+ setCellColor(suiteTable.rows, currentTestRow, 0, workingColor);
329
+
330
+ testLink = suiteTable.rows[currentTestRow].cells[0].getElementsByTagName("a")[0];
331
+ testLink.focus();
332
+
333
+ var testFrame = getTestFrame();
334
+ addLoadListener(testFrame, startTest);
335
+
336
+ selenium.browserbot.setIFrameLocation(testFrame, testLink.href);
337
+ }
338
+ }
339
+
340
+ function setCellColor(tableRows, row, col, colorStr) {
341
+ tableRows[row].cells[col].bgColor = colorStr;
342
+ }
343
+
344
+ // Sets the results from a test into a hidden column on the suite table. So,
345
+ // for each tests, the second column is set to the HTML from the test table.
346
+ function setResultsData(suiteTable, row) {
347
+ // Create a text node of the test table
348
+ var resultTable = getIframeDocument(getTestFrame()).body.innerHTML;
349
+ if (!resultTable) return;
350
+
351
+ var tableNode = suiteTable.ownerDocument.createElement("div");
352
+ tableNode.innerHTML = resultTable;
353
+
354
+ var new_column = suiteTable.ownerDocument.createElement("td");
355
+ new_column.appendChild(tableNode);
356
+
357
+ // Set the column to be invisible
358
+ new_column.style.cssText = "display: none;";
359
+
360
+ // Add the invisible column
361
+ suiteTable.rows[row].appendChild(new_column);
362
+ }
363
+
364
+ // Post the results to a servlet, CGI-script, etc. The URL of the
365
+ // results-handler defaults to "/postResults", but an alternative location
366
+ // can be specified by providing a "resultsUrl" query parameter.
367
+ //
368
+ // Parameters passed to the results-handler are:
369
+ // result: passed/failed depending on whether the suite passed or failed
370
+ // totalTime: the total running time in seconds for the suite.
371
+ //
372
+ // numTestPasses: the total number of tests which passed.
373
+ // numTestFailures: the total number of tests which failed.
374
+ //
375
+ // numCommandPasses: the total number of commands which passed.
376
+ // numCommandFailures: the total number of commands which failed.
377
+ // numCommandErrors: the total number of commands which errored.
378
+ //
379
+ // suite: the suite table, including the hidden column of test results
380
+ // testTable.1 to testTable.N: the individual test tables
381
+ //
382
+ function postTestResults(suiteFailed, suiteTable) {
383
+
384
+ form = document.createElement("form");
385
+ document.body.appendChild(form);
386
+
387
+ form.id = "resultsForm";
388
+ form.method="post";
389
+ form.target="myiframe";
390
+
391
+ var resultsUrl = getQueryParameter("resultsUrl");
392
+ if (!resultsUrl) {
393
+ resultsUrl = "./postResults";
394
+ }
395
+
396
+ var actionAndParameters = resultsUrl.split('?',2);
397
+ form.action = actionAndParameters[0];
398
+ var resultsUrlQueryString = actionAndParameters[1];
399
+
400
+ form.createHiddenField = function(name, value) {
401
+ input = document.createElement("input");
402
+ input.type = "hidden";
403
+ input.name = name;
404
+ input.value = value;
405
+ this.appendChild(input);
406
+ };
407
+
408
+ if (resultsUrlQueryString) {
409
+ var clauses = resultsUrlQueryString.split('&');
410
+ for (var i = 0; i < clauses.length; i++) {
411
+ var keyValuePair = clauses[i].split('=',2);
412
+ var key = unescape(keyValuePair[0]);
413
+ var value = unescape(keyValuePair[1]);
414
+ form.createHiddenField(key, value);
415
+ }
416
+ }
417
+
418
+ form.createHiddenField("result", suiteFailed == true ? "failed" : "passed");
419
+
420
+ form.createHiddenField("totalTime", Math.floor((currentTime - startTime) / 1000));
421
+ form.createHiddenField("numTestPasses", numTestPasses);
422
+ form.createHiddenField("numTestFailures", numTestFailures);
423
+ form.createHiddenField("numCommandPasses", numCommandPasses);
424
+ form.createHiddenField("numCommandFailures", numCommandFailures);
425
+ form.createHiddenField("numCommandErrors", numCommandErrors);
426
+
427
+ // Create an input for each test table. The inputs are named
428
+ // testTable.1, testTable.2, etc.
429
+ for (rowNum = 1; rowNum < suiteTable.rows.length;rowNum++) {
430
+ // If there is a second column, then add a new input
431
+ if (suiteTable.rows[rowNum].cells.length > 1) {
432
+ var resultCell = suiteTable.rows[rowNum].cells[1];
433
+ form.createHiddenField("testTable." + rowNum, resultCell.innerHTML);
434
+ // remove the resultCell, so it's not included in the suite HTML
435
+ resultCell.parentNode.removeChild(resultCell);
436
+ }
437
+ }
438
+
439
+ // Add HTML for the suite itself
440
+ form.createHiddenField("suite", suiteTable.parentNode.innerHTML);
441
+
442
+ form.submit();
443
+ document.body.removeChild(form);
444
+
445
+ }
446
+
447
+ function printMetrics() {
448
+ setText(document.getElementById("commandPasses"), numCommandPasses);
449
+ setText(document.getElementById("commandFailures"), numCommandFailures);
450
+ setText(document.getElementById("commandErrors"), numCommandErrors);
451
+ setText(document.getElementById("testRuns"), numTestPasses + numTestFailures);
452
+ setText(document.getElementById("testFailures"), numTestFailures);
453
+
454
+ currentTime = new Date().getTime();
455
+
456
+ timeDiff = currentTime - startTime;
457
+ totalSecs = Math.floor(timeDiff / 1000);
458
+
459
+ minutes = Math.floor(totalSecs / 60);
460
+ seconds = totalSecs % 60;
461
+
462
+ setText(document.getElementById("elapsedTime"), pad(minutes)+":"+pad(seconds));
463
+ }
464
+
465
+ // Puts a leading 0 on num if it is less than 10
466
+ function pad (num) {
467
+ return (num > 9) ? num : "0" + num;
468
+ }
469
+
470
+ /*
471
+ * Register all of the built-in command handlers with the CommandHandlerFactory.
472
+ * TODO work out an easy way for people to register handlers without modifying the Selenium sources.
473
+ */
474
+ function registerCommandHandlers() {
475
+ commandFactory = new CommandHandlerFactory();
476
+ commandFactory.registerAll(selenium);
477
+
478
+ }
479
+
480
+ function initialiseTestLoop() {
481
+ testLoop = new TestLoop(commandFactory);
482
+
483
+ testLoop.getCommandInterval = function() { return runInterval; };
484
+ testLoop.firstCommand = nextCommand;
485
+ testLoop.nextCommand = nextCommand;
486
+ testLoop.commandStarted = commandStarted;
487
+ testLoop.commandComplete = commandComplete;
488
+ testLoop.commandError = commandError;
489
+ testLoop.testComplete = testComplete;
490
+ testLoop.pause = function() {
491
+ document.getElementById('continueTest').disabled = false;
492
+ };
493
+ return testLoop;
494
+ }
495
+
496
+ function nextCommand() {
497
+ if (currentCommandRow >= inputTableRows.length - 1) {
498
+ return null;
499
+ }
500
+
501
+ currentCommandRow++;
502
+
503
+ var commandName = getCellText(currentCommandRow, 0);
504
+ var target = getCellText(currentCommandRow, 1);
505
+ var value = getCellText(currentCommandRow, 2);
506
+
507
+ var command = new SeleniumCommand(commandName, target, removeNbsp(value));
508
+ return command;
509
+ }
510
+
511
+ function removeNbsp(value)
512
+ {
513
+ return value.replace(/\240/g, "");
514
+ }
515
+
516
+ function scrollIntoView(element) {
517
+ if (element.scrollIntoView) {
518
+ element.scrollIntoView(false);
519
+ return;
520
+ }
521
+ // TODO: work out how to scroll browsers that don't support
522
+ // scrollIntoView (like Konqueror)
523
+ }
524
+
525
+ function commandStarted() {
526
+ inputTableRows[currentCommandRow].bgColor = workingColor;
527
+ scrollIntoView(inputTableRows[currentCommandRow].cells[0]);
528
+ printMetrics();
529
+ }
530
+
531
+ function commandComplete(result) {
532
+ if (result.failed) {
533
+ setRowFailed(result.failureMessage, FAILURE);
534
+ } else if (result.passed) {
535
+ setRowPassed();
536
+ } else {
537
+ setRowWhite();
538
+ }
539
+ }
540
+
541
+ function commandError(errorMessage) {
542
+ setRowFailed(errorMessage, ERROR);
543
+ }
544
+
545
+ function setRowWhite() {
546
+ inputTableRows[currentCommandRow].bgColor = "white";
547
+ }
548
+
549
+ function setRowPassed() {
550
+ numCommandPasses += 1;
551
+
552
+ // Set cell background to green
553
+ inputTableRows[currentCommandRow].bgColor = passColor;
554
+ }
555
+
556
+ function setRowFailed(errorMsg, failureType) {
557
+ if (failureType == ERROR)
558
+ numCommandErrors += 1;
559
+ else if (failureType == FAILURE)
560
+ numCommandFailures += 1;
561
+
562
+ // Set cell background to red
563
+ inputTableRows[currentCommandRow].bgColor = failColor;
564
+
565
+ // Set error message
566
+ inputTableRows[currentCommandRow].cells[2].innerHTML = errorMsg;
567
+ inputTableRows[currentCommandRow].title = errorMsg;
568
+ testFailed = true;
569
+ suiteFailed = true;
570
+ }
571
+
572
+ function testComplete() {
573
+ if(testFailed) {
574
+ inputTableRows[0].bgColor = failColor;
575
+ numTestFailures += 1;
576
+ }
577
+ else {
578
+ inputTableRows[0].bgColor = passColor;
579
+ numTestPasses += 1;
580
+ }
581
+
582
+ printMetrics();
583
+
584
+ window.setTimeout("runNextTest()", 1);
585
+ }
586
+
587
+ function getCellText(rowNumber, columnNumber) {
588
+ var cell = inputTableRows[rowNumber].cells[columnNumber];
589
+ if (! cell.cachedText) {
590
+ cell.cachedText = getText(cell);
591
+ }
592
+ return cell.cachedText;
593
+ }
594
+
595
+ Selenium.prototype.doPause = function(waitTime) {
596
+ testLoop.pauseInterval = waitTime;
597
+ };