2
* Copyright 2004 ThoughtWorks, Inc
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
// An object representing the current test, used external
19
var currentTest = null; // TODO: get rid of this global, which mirrors the htmlTestRunner.currentTest
23
var HtmlTestRunner = classCreate();
24
objectExtend(HtmlTestRunner.prototype, {
25
initialize: function() {
26
this.metrics = new Metrics();
27
this.controlPanel = new HtmlTestRunnerControlPanel();
28
this.testFailed = false;
29
this.currentTest = null;
30
this.runAllTests = false;
31
this.appWindow = null;
32
// we use a timeout here to make sure the LOG has loaded first, so we can see _every_ error
33
setTimeout(fnBind(function() {
34
this.loadSuiteFrame();
38
getTestSuite: function() {
39
return suiteFrame.getCurrentTestSuite();
42
markFailed: function() {
43
this.testFailed = true;
44
this.getTestSuite().markFailed();
47
loadSuiteFrame: function() {
48
var logLevel = this.controlPanel.getDefaultLogLevel();
50
LOG.setLogLevelThreshold(logLevel);
52
if (selenium == null) {
53
var appWindow = this._getApplicationWindow();
54
try { appWindow.location; }
56
// when reloading, we may be pointing at an old window (Perm Denied)
57
setTimeout(fnBind(function() {
58
this.loadSuiteFrame();
62
selenium = Selenium.createForWindow(appWindow);
63
this._registerCommandHandlers();
65
this.controlPanel.setHighlightOption();
66
var testSuiteName = this.controlPanel.getTestSuiteName();
69
suiteFrame.load(testSuiteName, function() {setTimeout(fnBind(self._onloadTestSuite, self), 50)} );
70
selenium.browserbot.baseUrl = absolutify(testSuiteName, window.location.href);
72
// DGF or should we use the old default?
73
// selenium.browserbot.baseUrl = window.location.href;
74
if (this.controlPanel.getBaseUrl()) {
75
selenium.browserbot.baseUrl = this.controlPanel.getBaseUrl();
79
_getApplicationWindow: function () {
80
if (this.controlPanel.isMultiWindowMode()) {
81
return this._getSeparateApplicationWindow();
83
return sel$('selenium_myiframe').contentWindow;
86
_getSeparateApplicationWindow: function () {
87
if (this.appWindow == null) {
88
this.appWindow = openSeparateApplicationWindow('TestRunner-splash.html', this.controlPanel.isAutomatedRun());
90
return this.appWindow;
93
_onloadTestSuite:function () {
94
suiteFrame = new HtmlTestSuiteFrame(getSuiteFrame());
95
if (! this.getTestSuite().isAvailable()) {
98
if (this.controlPanel.isAutomatedRun()) {
99
this.startTestSuite();
100
} else if (this.controlPanel.getAutoUrl()) {
101
//todo what is the autourl doing, left to check it out
102
addLoadListener(this._getApplicationWindow(), fnBind(this._startSingleTest, this));
103
this._getApplicationWindow().src = this.controlPanel.getAutoUrl();
105
var testCaseLoaded = fnBind(function(){this.testCaseLoaded=true;},this);
107
if (this.controlPanel.getTestNumber() != null){
108
var testNumber = this.controlPanel.getTestNumber() - 1;
110
this.getTestSuite().getSuiteRows()[testNumber].loadTestCase(testCaseLoaded);
114
_startSingleTest:function () {
115
removeLoadListener(getApplicationWindow(), fnBind(this._startSingleTest, this));
116
var singleTestName = this.controlPanel.getSingleTestName();
117
testFrame.load(singleTestName, fnBind(this.startTest, this));
120
_registerCommandHandlers: function () {
121
this.commandFactory = new CommandHandlerFactory();
122
this.commandFactory.registerAll(selenium);
125
startTestSuite: function() {
126
this.controlPanel.reset();
127
this.metrics.resetMetrics();
128
this.getTestSuite().reset();
129
this.runAllTests = true;
133
runNextTest: function () {
134
this.getTestSuite().updateSuiteWithResultOfPreviousTest();
135
if (!this.runAllTests) {
138
this.getTestSuite().runNextTestInSuite();
141
startTest: function () {
142
this.controlPanel.reset();
143
testFrame.scrollToTop();
144
//todo: move testFailed and storedVars to TestCase
145
this.testFailed = false;
146
storedVars = new Object();
147
storedVars.nbsp = String.fromCharCode(160);
148
storedVars.space = ' ';
149
this.currentTest = new HtmlRunnerTestLoop(testFrame.getCurrentTestCase(), this.metrics, this.commandFactory);
150
currentTest = this.currentTest;
151
this.currentTest.start();
154
runSingleTest:function() {
155
this.runAllTests = false;
156
this.metrics.resetMetrics();
163
/** SeleniumFrame encapsulates an iframe element */
164
var SeleniumFrame = classCreate();
165
objectExtend(SeleniumFrame.prototype, {
167
initialize : function(frame) {
169
addLoadListener(this.frame, fnBind(this._handleLoad, this));
172
getWindow : function() {
173
return this.frame.contentWindow;
176
getDocument : function() {
177
return this.frame.contentWindow.document;
180
_handleLoad: function() {
181
this._attachStylesheet();
183
if (this.loadCallback) {
188
_attachStylesheet: function() {
189
var d = this.getDocument();
190
var head = d.getElementsByTagName('head').item(0);
191
var styleLink = d.createElement("link");
192
styleLink.rel = "stylesheet";
193
styleLink.type = "text/css";
194
if (browserVersion && browserVersion.isChrome) {
195
// DGF We have to play a clever trick to get the right absolute path.
196
// This trick works on most browsers, (not IE), but is only needed in
198
var tempLink = window.document.createElement("link");
199
tempLink.href = "selenium-test.css"; // this will become an absolute href
200
styleLink.href = tempLink.href;
202
// this works in every browser (except Firefox in chrome mode)
203
var styleSheetPath = window.location.pathname.replace(/[^\/\\]+$/, "selenium-test.css");
204
if (browserVersion.isIE && window.location.protocol == "file:") {
205
styleSheetPath = "file:///" + styleSheetPath;
207
styleLink.href = styleSheetPath;
209
// DGF You're only going to see this log message if you set defaultLogLevel=debug
210
LOG.debug("styleLink.href="+styleLink.href);
211
head.appendChild(styleLink);
214
_onLoad: function() {
217
scrollToTop : function() {
218
this.frame.contentWindow.scrollTo(0, 0);
221
_setLocation: function(location) {
222
var isChrome = browserVersion.isChrome || false;
223
var isHTA = browserVersion.isHTA || false;
224
// DGF TODO multiWindow
225
location += (location.indexOf("?") == -1 ? "?" : "&");
226
location += "thisIsChrome=" + isChrome + "&thisIsHTA=" + isHTA;
227
if (browserVersion.isSafari) {
228
// safari doesn't reload the page when the location equals to current location.
229
// hence, set the location to blank so that the page will reload automatically.
230
this.frame.src = "about:blank";
231
this.frame.src = location;
233
this.frame.contentWindow.location.replace(location);
237
load: function(/* url, [callback] */) {
238
if (arguments.length > 1) {
239
this.loadCallback = arguments[1];
242
this._setLocation(arguments[0]);
247
/** HtmlTestSuiteFrame - encapsulates the suite iframe element */
248
var HtmlTestSuiteFrame = classCreate();
249
objectExtend(HtmlTestSuiteFrame.prototype, SeleniumFrame.prototype);
250
objectExtend(HtmlTestSuiteFrame.prototype, {
252
getCurrentTestSuite: function() {
253
if (!this.currentTestSuite) {
254
this.currentTestSuite = new HtmlTestSuite(this.getDocument());
256
return this.currentTestSuite;
261
/** HtmlTestFrame - encapsulates the test-case iframe element */
262
var HtmlTestFrame = classCreate();
263
objectExtend(HtmlTestFrame.prototype, SeleniumFrame.prototype);
264
objectExtend(HtmlTestFrame.prototype, {
266
_onLoad: function() {
267
this.currentTestCase = new HtmlTestCase(this.getWindow(), htmlTestRunner.getTestSuite().getCurrentRow());
270
getCurrentTestCase: function() {
271
return this.currentTestCase;
276
function onSeleniumLoad() {
277
suiteFrame = new HtmlTestSuiteFrame(getSuiteFrame());
278
testFrame = new HtmlTestFrame(getTestFrame());
279
htmlTestRunner = new HtmlTestRunner();
285
function getSuiteFrame() {
286
var f = sel$('testSuiteFrame');
289
// proxyInjection mode does not set selenium_myiframe
294
function getTestFrame() {
295
var f = sel$('testFrame');
298
// proxyInjection mode does not set selenium_myiframe
303
var HtmlTestRunnerControlPanel = classCreate();
304
objectExtend(HtmlTestRunnerControlPanel.prototype, URLConfiguration.prototype);
305
objectExtend(HtmlTestRunnerControlPanel.prototype, {
306
initialize: function() {
307
this._acquireQueryString();
309
this.runInterval = 0;
311
this.highlightOption = sel$('highlightOption');
312
this.pauseButton = sel$('pauseTest');
313
this.stepButton = sel$('stepTest');
315
this.highlightOption.onclick = fnBindAsEventListener((function() {
316
this.setHighlightOption();
318
this.pauseButton.onclick = fnBindAsEventListener(this.pauseCurrentTest, this);
319
this.stepButton.onclick = fnBindAsEventListener(this.stepCurrentTest, this);
322
this.speedController = new Control.Slider('speedHandle', 'speedTrack', {
324
onSlide: fnBindAsEventListener(this.setRunInterval, this),
325
onChange: fnBindAsEventListener(this.setRunInterval, this)
328
this._parseQueryParameter();
331
setHighlightOption: function () {
332
var isHighlight = this.highlightOption.checked;
333
selenium.browserbot.setShouldHighlightElement(isHighlight);
336
_parseQueryParameter: function() {
337
var tempRunInterval = this._getQueryParameter("runInterval");
338
if (tempRunInterval) {
339
this.setRunInterval(tempRunInterval);
341
this.highlightOption.checked = this._getQueryParameter("highlight");
344
setRunInterval: function(runInterval) {
345
this.runInterval = runInterval;
348
setToPauseAtNextCommand: function() {
349
this.runInterval = -1;
352
pauseCurrentTest: function () {
353
this.setToPauseAtNextCommand();
354
this._switchPauseButtonToContinue();
357
continueCurrentTest: function () {
359
currentTest.resume();
363
this.runInterval = this.speedController.value;
364
this._switchContinueButtonToPause();
367
_switchContinueButtonToPause: function() {
368
this.pauseButton.className = "cssPauseTest";
369
this.pauseButton.onclick = fnBindAsEventListener(this.pauseCurrentTest, this);
372
_switchPauseButtonToContinue: function() {
373
sel$('stepTest').disabled = false;
374
this.pauseButton.className = "cssContinueTest";
375
this.pauseButton.onclick = fnBindAsEventListener(this.continueCurrentTest, this);
378
stepCurrentTest: function () {
379
this.setToPauseAtNextCommand();
380
currentTest.resume();
383
isAutomatedRun: function() {
384
return this._isQueryParameterTrue("auto");
387
shouldSaveResultsToFile: function() {
388
return this._isQueryParameterTrue("save");
391
closeAfterTests: function() {
392
return this._isQueryParameterTrue("close");
395
getTestSuiteName: function() {
396
return this._getQueryParameter("test");
399
getTestNumber: function() {
400
return this._getQueryParameter("testNumber");
403
getSingleTestName: function() {
404
return this._getQueryParameter("singletest");
407
getAutoUrl: function() {
408
return this._getQueryParameter("autoURL");
411
getDefaultLogLevel: function() {
412
return this._getQueryParameter("defaultLogLevel");
415
getResultsUrl: function() {
416
return this._getQueryParameter("resultsUrl");
419
_acquireQueryString: function() {
420
if (this.queryString) return;
421
if (browserVersion.isHTA) {
422
var args = this._extractArgs();
423
if (args.length < 2) return null;
424
this.queryString = args[1];
426
this.queryString = location.search.substr(1);
432
var AbstractResultAwareRow = classCreate();
433
objectExtend(AbstractResultAwareRow.prototype, {
435
initialize: function(trElement) {
436
this.trElement = trElement;
439
setStatus: function(status) {
441
this.trElement.className = this.trElement.className.replace(/status_[a-z]+/, "");
443
addClassName(this.trElement, "status_" + status);
448
addClassName(this.trElement, "selected");
449
safeScrollIntoView(this.trElement);
452
unselect: function() {
453
removeClassName(this.trElement, "selected");
456
markPassed: function() {
457
this.setStatus("passed");
460
markDone: function() {
461
this.setStatus("done");
464
markFailed: function() {
465
this.setStatus("failed");
470
var TitleRow = classCreate();
471
objectExtend(TitleRow.prototype, AbstractResultAwareRow.prototype);
472
objectExtend(TitleRow.prototype, {
474
initialize: function(trElement) {
475
this.trElement = trElement;
476
trElement.className = "title";
481
var HtmlTestCaseRow = classCreate();
482
objectExtend(HtmlTestCaseRow.prototype, AbstractResultAwareRow.prototype);
483
objectExtend(HtmlTestCaseRow.prototype, {
485
getCommand: function () {
486
return new SeleniumCommand(getText(this.trElement.cells[0]),
487
getText(this.trElement.cells[1]),
488
getText(this.trElement.cells[2]),
489
this.isBreakpoint());
492
markFailed: function(errorMsg) {
493
AbstractResultAwareRow.prototype.markFailed.call(this, errorMsg);
494
this.setMessage(errorMsg);
497
setMessage: function(message) {
498
setText(this.trElement.cells[2], message);
502
this.setStatus(null);
503
var thirdCell = this.trElement.cells[2];
505
if (thirdCell.originalHTML) {
506
thirdCell.innerHTML = thirdCell.originalHTML;
508
thirdCell.originalHTML = thirdCell.innerHTML;
513
onClick: function() {
514
if (this.trElement.isBreakpoint == undefined) {
515
this.trElement.isBreakpoint = true;
516
addClassName(this.trElement, "breakpoint");
518
this.trElement.isBreakpoint = undefined;
519
removeClassName(this.trElement, "breakpoint");
523
addBreakpointSupport: function() {
524
elementSetStyle(this.trElement, {"cursor" : "pointer"});
525
this.trElement.onclick = fnBindAsEventListener(function() {
530
isBreakpoint: function() {
531
if (this.trElement.isBreakpoint == undefined || this.trElement.isBreakpoint == null) {
534
return this.trElement.isBreakpoint;
538
var HtmlTestSuiteRow = classCreate();
539
objectExtend(HtmlTestSuiteRow.prototype, AbstractResultAwareRow.prototype);
540
objectExtend(HtmlTestSuiteRow.prototype, {
542
initialize: function(trElement, testFrame, htmlTestSuite) {
543
this.trElement = trElement;
544
this.testFrame = testFrame;
545
this.htmlTestSuite = htmlTestSuite;
546
this.link = trElement.getElementsByTagName("a")[0];
547
this.link.onclick = fnBindAsEventListener(this._onClick, this);
551
this.setStatus(null);
554
_onClick: function() {
555
this.loadTestCase(null);
559
loadTestCase: function(onloadFunction) {
560
this.htmlTestSuite.unselectCurrentRow();
562
this.htmlTestSuite.currentRowInSuite = this.trElement.rowIndex - 1;
563
// If the row has a stored results table, use that
564
var resultsFromPreviousRun = this.trElement.cells[1];
565
if (resultsFromPreviousRun) {
566
// todo: delegate to TestFrame, e.g.
567
// this.testFrame.restoreTestCase(resultsFromPreviousRun.innerHTML);
568
var testBody = this.testFrame.getDocument().body;
569
testBody.innerHTML = resultsFromPreviousRun.innerHTML;
570
this.testFrame._onLoad();
571
if (onloadFunction) {
575
this.testFrame.load(this.link.href, onloadFunction);
579
saveTestResults: function() {
580
// todo: GLOBAL ACCESS!
581
var resultHTML = this.testFrame.getDocument().body.innerHTML;
582
if (!resultHTML) return;
584
// todo: why create this div?
585
var divElement = this.trElement.ownerDocument.createElement("div");
586
divElement.innerHTML = resultHTML;
588
var hiddenCell = this.trElement.ownerDocument.createElement("td");
589
hiddenCell.appendChild(divElement);
590
hiddenCell.style.display = "none";
592
this.trElement.appendChild(hiddenCell);
597
var HtmlTestSuite = classCreate();
598
objectExtend(HtmlTestSuite.prototype, {
600
initialize: function(suiteDocument) {
601
this.suiteDocument = suiteDocument;
602
this.suiteRows = this._collectSuiteRows();
603
var testTable = this.getTestTable();
604
if (!testTable) return;
605
this.titleRow = new TitleRow(testTable.rows[0]);
611
this.currentRowInSuite = -1;
612
this.titleRow.setStatus(null);
613
for (var i = 0; i < this.suiteRows.length; i++) {
614
var row = this.suiteRows[i];
619
getSuiteRows: function() {
620
return this.suiteRows;
623
getTestTable: function() {
624
var tables = sel$A(this.suiteDocument.getElementsByTagName("table"));
628
isAvailable: function() {
629
return this.getTestTable() != null;
632
_collectSuiteRows: function () {
634
var tables = sel$A(this.suiteDocument.getElementsByTagName("table"));
635
var testTable = tables[0];
636
if (!testTable) return;
637
for (rowNum = 1; rowNum < testTable.rows.length; rowNum++) {
638
var rowElement = testTable.rows[rowNum];
639
result.push(new HtmlTestSuiteRow(rowElement, testFrame, this));
642
// process the unsuited rows as well
643
for (var tableNum = 1; tableNum < sel$A(this.suiteDocument.getElementsByTagName("table")).length; tableNum++) {
644
testTable = tables[tableNum];
645
for (rowNum = 1; rowNum < testTable.rows.length; rowNum++) {
646
var rowElement = testTable.rows[rowNum];
647
new HtmlTestSuiteRow(rowElement, testFrame, this);
653
getCurrentRow: function() {
654
if (this.currentRowInSuite == -1) {
657
return this.suiteRows[this.currentRowInSuite];
660
unselectCurrentRow: function() {
661
var currentRow = this.getCurrentRow()
663
currentRow.unselect();
667
markFailed: function() {
669
this.titleRow.markFailed();
672
markDone: function() {
674
this.titleRow.markPassed();
678
_startCurrentTestCase: function() {
679
this.getCurrentRow().loadTestCase(fnBind(htmlTestRunner.startTest, htmlTestRunner));
682
_onTestSuiteComplete: function() {
684
new SeleniumTestResult(this.failed, this.getTestTable()).post();
687
updateSuiteWithResultOfPreviousTest: function() {
688
if (this.currentRowInSuite >= 0) {
689
this.getCurrentRow().saveTestResults();
693
runNextTestInSuite: function() {
694
this.currentRowInSuite++;
696
// If we are done with all of the tests, set the title bar as pass or fail
697
if (this.currentRowInSuite >= this.suiteRows.length) {
698
this._onTestSuiteComplete();
700
this._startCurrentTestCase();
708
var SeleniumTestResult = classCreate();
709
objectExtend(SeleniumTestResult.prototype, {
711
// Post the results to a servlet, CGI-script, etc. The URL of the
712
// results-handler defaults to "/postResults", but an alternative location
713
// can be specified by providing a "resultsUrl" query parameter.
715
// Parameters passed to the results-handler are:
716
// result: passed/failed depending on whether the suite passed or failed
717
// totalTime: the total running time in seconds for the suite.
719
// numTestPasses: the total number of tests which passed.
720
// numTestFailures: the total number of tests which failed.
722
// numCommandPasses: the total number of commands which passed.
723
// numCommandFailures: the total number of commands which failed.
724
// numCommandErrors: the total number of commands which errored.
726
// suite: the suite table, including the hidden column of test results
727
// testTable.1 to testTable.N: the individual test tables
729
initialize: function (suiteFailed, suiteTable) {
730
this.controlPanel = htmlTestRunner.controlPanel;
731
this.metrics = htmlTestRunner.metrics;
732
this.suiteFailed = suiteFailed;
733
this.suiteTable = suiteTable;
737
if (!this.controlPanel.isAutomatedRun()) {
740
var form = document.createElement("form");
741
document.body.appendChild(form);
743
form.id = "resultsForm";
744
form.method = "post";
745
form.target = "selenium_myiframe";
747
var resultsUrl = this.controlPanel.getResultsUrl();
749
resultsUrl = "./postResults";
752
var actionAndParameters = resultsUrl.split('?', 2);
753
form.action = actionAndParameters[0];
754
var resultsUrlQueryString = actionAndParameters[1];
756
form.createHiddenField = function(name, value) {
757
input = document.createElement("input");
758
input.type = "hidden";
761
this.appendChild(input);
764
if (resultsUrlQueryString) {
765
var clauses = resultsUrlQueryString.split('&');
766
for (var i = 0; i < clauses.length; i++) {
767
var keyValuePair = clauses[i].split('=', 2);
768
var key = unescape(keyValuePair[0]);
769
var value = unescape(keyValuePair[1]);
770
form.createHiddenField(key, value);
774
form.createHiddenField("selenium.version", Selenium.version);
775
form.createHiddenField("selenium.revision", Selenium.revision);
777
form.createHiddenField("result", this.suiteFailed ? "failed" : "passed");
779
form.createHiddenField("totalTime", Math.floor((this.metrics.currentTime - this.metrics.startTime) / 1000));
780
form.createHiddenField("numTestPasses", this.metrics.numTestPasses);
781
form.createHiddenField("numTestFailures", this.metrics.numTestFailures);
782
form.createHiddenField("numCommandPasses", this.metrics.numCommandPasses);
783
form.createHiddenField("numCommandFailures", this.metrics.numCommandFailures);
784
form.createHiddenField("numCommandErrors", this.metrics.numCommandErrors);
786
// Create an input for each test table. The inputs are named
787
// testTable.1, testTable.2, etc.
788
for (rowNum = 1; rowNum < this.suiteTable.rows.length; rowNum++) {
789
// If there is a second column, then add a new input
790
if (this.suiteTable.rows[rowNum].cells.length > 1) {
791
var resultCell = this.suiteTable.rows[rowNum].cells[1];
792
form.createHiddenField("testTable." + rowNum, resultCell.innerHTML);
793
// remove the resultCell, so it's not included in the suite HTML
794
resultCell.parentNode.removeChild(resultCell);
798
form.createHiddenField("numTestTotal", rowNum-1);
800
// Add HTML for the suite itself
801
form.createHiddenField("suite", this.suiteTable.parentNode.innerHTML);
803
var logMessages = [];
804
while (LOG.pendingMessages.length > 0) {
805
var msg = LOG.pendingMessages.shift();
806
logMessages.push(msg.type);
807
logMessages.push(": ");
808
logMessages.push(msg.msg);
809
logMessages.push('\n');
811
var logOutput = logMessages.join("");
812
form.createHiddenField("log", logOutput);
814
if (this.controlPanel.shouldSaveResultsToFile()) {
815
this._saveToFile(resultsUrl, form);
819
document.body.removeChild(form);
820
if (this.controlPanel.closeAfterTests()) {
825
_saveToFile: function (fileName, form) {
826
// This only works when run as an IE HTA
827
var inputs = new Object();
828
for (var i = 0; i < form.elements.length; i++) {
829
inputs[form.elements[i].name] = form.elements[i].value;
832
var objFSO = new ActiveXObject("Scripting.FileSystemObject")
837
var styleSheetPath = window.location.pathname.replace(/[^\/\\]+$/, "selenium-test.css");
838
if (window.location.protocol == "file:") {
839
var stylesFile = objFSO.OpenTextFile(styleSheetPath, 1);
840
styles = stylesFile.ReadAll();
842
var xhr = XmlHttp.create();
843
xhr.open("GET", styleSheetPath, false);
845
styles = xhr.responseText;
849
var scriptFile = objFSO.CreateTextFile(fileName);
852
scriptFile.WriteLine("<html><head><title>Test suite results</title><style>");
853
scriptFile.WriteLine(styles);
854
scriptFile.WriteLine("</style>");
855
scriptFile.WriteLine("<body>\n<h1>Test suite results</h1>" +
856
"\n\n<table>\n<tr>\n<td>result:</td>\n<td>" + inputs["result"] + "</td>\n" +
857
"</tr>\n<tr>\n<td>totalTime:</td>\n<td>" + inputs["totalTime"] + "</td>\n</tr>\n" +
858
"<tr>\n<td>numTestTotal:</td>\n<td>" + inputs["numTestTotal"] + "</td>\n</tr>\n" +
859
"<tr>\n<td>numTestPasses:</td>\n<td>" + inputs["numTestPasses"] + "</td>\n</tr>\n" +
860
"<tr>\n<td>numTestFailures:</td>\n<td>" + inputs["numTestFailures"] + "</td>\n</tr>\n" +
861
"<tr>\n<td>numCommandPasses:</td>\n<td>" + inputs["numCommandPasses"] + "</td>\n</tr>\n" +
862
"<tr>\n<td>numCommandFailures:</td>\n<td>" + inputs["numCommandFailures"] + "</td>\n</tr>\n" +
863
"<tr>\n<td>numCommandErrors:</td>\n<td>" + inputs["numCommandErrors"] + "</td>\n</tr>\n" +
864
"<tr>\n<td>" + inputs["suite"] + "</td>\n<td> </td>\n</tr></table><table>");
865
var testNum = inputs["numTestTotal"];
867
for (var rowNum = 1; rowNum <= testNum; rowNum++) {
868
scriptFile.WriteLine("<tr>\n<td>" + inputs["testTable." + rowNum] + "</td>\n<td> </td>\n</tr>");
870
scriptFile.WriteLine("</table><pre>");
871
var log = inputs["log"];
872
log=log.replace(/&/gm,"&").replace(/</gm,"<").replace(/>/gm,">").replace(/"/gm,""").replace(/'/gm,"'");
873
scriptFile.WriteLine(log);
874
scriptFile.WriteLine("</pre></body></html>");
879
/** HtmlTestCase encapsulates an HTML test document */
880
var HtmlTestCase = classCreate();
881
objectExtend(HtmlTestCase.prototype, {
883
initialize: function(testWindow, htmlTestSuiteRow) {
884
if (testWindow == null) {
885
throw "testWindow should not be null";
887
if (htmlTestSuiteRow == null) {
888
throw "htmlTestSuiteRow should not be null";
890
this.testWindow = testWindow;
891
this.testDocument = testWindow.document;
892
this.pathname = "'unknown'";
894
if (this.testWindow.location) {
895
this.pathname = this.testWindow.location.pathname;
899
this.htmlTestSuiteRow = htmlTestSuiteRow;
900
this.headerRow = new TitleRow(this.testDocument.getElementsByTagName("tr")[0]);
901
this.commandRows = this._collectCommandRows();
902
this.nextCommandRowIndex = 0;
903
this._addBreakpointSupport();
906
_collectCommandRows: function () {
907
var commandRows = [];
908
var tables = sel$A(this.testDocument.getElementsByTagName("table"));
910
for (var i = 0; i < tables.length; i++) {
911
var table = tables[i];
912
var tableRows = sel$A(table.rows);
913
for (var j = 0; j < tableRows.length; j++) {
914
var candidateRow = tableRows[j];
915
if (self.isCommandRow(candidateRow)) {
916
commandRows.push(new HtmlTestCaseRow(candidateRow));
923
isCommandRow: function (row) {
924
return row.cells.length >= 3;
929
* reset the test to runnable state
931
this.nextCommandRowIndex = 0;
934
for (var i = 0; i < this.commandRows.length; i++) {
935
var row = this.commandRows[i];
939
// remove any additional fake "error" row added to the end of the document
940
var errorElement = this.testDocument.getElementById('error');
942
errorElement.parentNode.removeChild(errorElement);
946
getCommandRows: function () {
947
return this.commandRows;
950
setStatus: function(status) {
951
this.headerRow.setStatus(status);
954
markFailed: function() {
955
this.setStatus("failed");
956
this.htmlTestSuiteRow.markFailed();
959
markPassed: function() {
960
this.setStatus("passed");
961
this.htmlTestSuiteRow.markPassed();
964
addErrorMessage: function(errorMsg, currentRow) {
965
errorMsg = errorMsg.replace(/ /g, String.fromCharCode(160)).replace("\n", '\\n');
967
currentRow.markFailed(errorMsg);
969
var errorElement = this.testDocument.createElement("p");
970
errorElement.id = "error";
971
setText(errorElement, errorMsg);
972
this.testDocument.body.appendChild(errorElement);
973
errorElement.className = "status_failed";
977
_addBreakpointSupport: function() {
978
for (var i = 0; i < this.commandRows.length; i++) {
979
var row = this.commandRows[i];
980
row.addBreakpointSupport();
984
hasMoreCommandRows: function() {
985
return this.nextCommandRowIndex < this.commandRows.length;
988
getNextCommandRow: function() {
989
if (this.hasMoreCommandRows()) {
990
return this.commandRows[this.nextCommandRowIndex++];
998
// TODO: split out an JavascriptTestCase class to handle the "sejs" stuff
1000
var get_new_rows = function() {
1001
var row_array = new Array();
1002
for (var i = 0; i < new_block.length; i++) {
1004
var new_source = (new_block[i][0].tokenizer.source.slice(new_block[i][0].start,
1005
new_block[i][0].end));
1007
var row = '<td style="display:none;" class="js">getEval</td>' +
1008
'<td style="display:none;">currentTest.doNextCommand()</td>' +
1009
'<td style="white-space: pre;">' + new_source + '</td>' +
1012
row_array.push(row);
1018
var Metrics = classCreate();
1019
objectExtend(Metrics.prototype, {
1020
initialize: function() {
1021
// The number of tests run
1022
this.numTestPasses = 0;
1023
// The number of tests that have failed
1024
this.numTestFailures = 0;
1025
// The number of commands which have passed
1026
this.numCommandPasses = 0;
1027
// The number of commands which have failed
1028
this.numCommandFailures = 0;
1029
// The number of commands which have caused errors (element not found)
1030
this.numCommandErrors = 0;
1031
// The time that the test was started.
1032
this.startTime = null;
1033
// The current time.
1034
this.currentTime = null;
1037
printMetrics: function() {
1038
setText(sel$('commandPasses'), this.numCommandPasses);
1039
setText(sel$('commandFailures'), this.numCommandFailures);
1040
setText(sel$('commandErrors'), this.numCommandErrors);
1041
setText(sel$('testRuns'), this.numTestPasses + this.numTestFailures);
1042
setText(sel$('testFailures'), this.numTestFailures);
1044
this.currentTime = new Date().getTime();
1046
var timeDiff = this.currentTime - this.startTime;
1047
var totalSecs = Math.floor(timeDiff / 1000);
1049
var minutes = Math.floor(totalSecs / 60);
1050
var seconds = totalSecs % 60;
1052
setText(sel$('elapsedTime'), this._pad(minutes) + ":" + this._pad(seconds));
1055
// Puts a leading 0 on num if it is less than 10
1056
_pad: function(num) {
1057
return (num > 9) ? num : "0" + num;
1060
resetMetrics: function() {
1061
this.numTestPasses = 0;
1062
this.numTestFailures = 0;
1063
this.numCommandPasses = 0;
1064
this.numCommandFailures = 0;
1065
this.numCommandErrors = 0;
1066
this.startTime = new Date().getTime();
1071
var HtmlRunnerCommandFactory = classCreate();
1072
objectExtend(HtmlRunnerCommandFactory.prototype, {
1074
initialize: function(seleniumCommandFactory, testLoop) {
1075
this.seleniumCommandFactory = seleniumCommandFactory;
1076
this.testLoop = testLoop;
1078
//todo: register commands
1081
getCommandHandler: function(command) {
1082
if (this.handlers[command]) {
1083
return this.handlers[command];
1085
return this.seleniumCommandFactory.getCommandHandler(command);
1090
var HtmlRunnerTestLoop = classCreate();
1091
objectExtend(HtmlRunnerTestLoop.prototype, new TestLoop());
1092
objectExtend(HtmlRunnerTestLoop.prototype, {
1093
initialize: function(htmlTestCase, metrics, seleniumCommandFactory) {
1095
this.commandFactory = new HtmlRunnerCommandFactory(seleniumCommandFactory, this);
1096
this.metrics = metrics;
1098
this.htmlTestCase = htmlTestCase;
1099
LOG.info("Starting test " + htmlTestCase.pathname);
1101
this.currentRow = null;
1102
this.currentRowIndex = 0;
1104
// used for selenium tests in javascript
1105
this.currentItem = null;
1106
this.commandAgenda = new Array();
1107
this.expectedFailure = null;
1108
this.expectedFailureType = null;
1110
this.htmlTestCase.reset();
1113
_advanceToNextRow: function() {
1114
if (this.htmlTestCase.hasMoreCommandRows()) {
1115
this.currentRow = this.htmlTestCase.getNextCommandRow();
1116
if (this.sejsElement) {
1117
this.currentItem = agenda.pop();
1118
this.currentRowIndex++;
1121
this.currentRow = null;
1122
this.currentItem = null;
1126
nextCommand : function() {
1127
this._advanceToNextRow();
1128
if (this.currentRow == null) {
1131
return this.currentRow.getCommand();
1134
commandStarted : function() {
1135
sel$('pauseTest').disabled = false;
1136
this.currentRow.select();
1137
this.metrics.printMetrics();
1140
commandComplete : function(result) {
1141
this._checkExpectedFailure(result);
1142
if (result.failed) {
1143
this.metrics.numCommandFailures += 1;
1144
this._recordFailure(result.failureMessage);
1145
} else if (result.passed) {
1146
this.metrics.numCommandPasses += 1;
1147
this.currentRow.markPassed();
1149
this.currentRow.markDone();
1153
_checkExpectedFailure : function(result) {
1154
if (this.expectedFailure != null) {
1155
if (this.expectedFailureJustSet) {
1156
this.expectedFailureJustSet = false;
1159
if (!result.failed) {
1160
result.passed = false;
1161
result.failed = true;
1162
result.failureMessage = "Expected " + this.expectedFailureType + " did not occur.";
1164
if (PatternMatcher.matches(this.expectedFailure, result.failureMessage)) {
1165
var failureType = result.error ? "error" : "failure";
1166
if (failureType == this.expectedFailureType) {
1167
result.failed = false;
1168
result.passed = true;
1170
result.failed = true;
1171
result.failureMessage = "Expected "+this.expectedFailureType+", but "+failureType+" occurred instead";
1174
result.failed = true;
1175
result.failureMessage = "Expected " + this.expectedFailureType + " message '" + this.expectedFailure
1176
+ "' but was '" + result.failureMessage + "'";
1179
this.expectedFailure = null;
1180
this.expectedFailureType = null;
1184
commandError : function(errorMessage) {
1185
var tempResult = {};
1186
tempResult.passed = false;
1187
tempResult.failed = true;
1188
tempResult.error = true;
1189
tempResult.failureMessage = errorMessage;
1190
this._checkExpectedFailure(tempResult);
1191
if (tempResult.passed) {
1192
this.currentRow.markDone();
1195
errorMessage = tempResult.failureMessage;
1196
this.metrics.numCommandErrors += 1;
1197
this._recordFailure(errorMessage);
1200
_recordFailure : function(errorMsg) {
1201
LOG.warn("currentTest.recordFailure: " + errorMsg);
1202
htmlTestRunner.markFailed();
1203
this.htmlTestCase.addErrorMessage(errorMsg, this.currentRow);
1206
testComplete : function() {
1207
sel$('pauseTest').disabled = true;
1208
sel$('stepTest').disabled = true;
1209
if (htmlTestRunner.testFailed) {
1210
this.htmlTestCase.markFailed();
1211
this.metrics.numTestFailures += 1;
1213
this.htmlTestCase.markPassed();
1214
this.metrics.numTestPasses += 1;
1217
this.metrics.printMetrics();
1219
window.setTimeout(function() {
1220
htmlTestRunner.runNextTest();
1224
getCommandInterval : function() {
1225
return htmlTestRunner.controlPanel.runInterval;
1228
pause : function() {
1229
htmlTestRunner.controlPanel.pauseCurrentTest();
1232
doNextCommand: function() {
1233
var _n = this.currentItem[0];
1234
var _x = this.currentItem[1];
1236
new_block = new Array()
1238
if (new_block.length > 0) {
1239
var the_table = this.htmlTestCase.testDocument.getElementById("se-js-table")
1240
var loc = this.currentRowIndex
1241
var new_rows = get_new_rows()
1243
// make the new statements visible on screen...
1244
for (var i = 0; i < new_rows.length; i++) {
1245
the_table.insertRow(loc + 1);
1246
the_table.rows[loc + 1].innerHTML = new_rows[i];
1247
this.commandRows.unshift(the_table.rows[loc + 1])
1255
Selenium.prototype.doPause = function(waitTime) {
1256
/** Wait for the specified amount of time (in milliseconds)
1257
* @param waitTime the amount of time to sleep (in milliseconds)
1259
// todo: should not refer to currentTest directly
1260
currentTest.pauseInterval = waitTime;
1263
Selenium.prototype.doBreak = function() {
1264
/** Halt the currently running test, and wait for the user to press the Continue button.
1265
* This command is useful for debugging, but be careful when using it, because it will
1266
* force automated tests to hang until a user intervenes manually.
1268
// todo: should not refer to controlPanel directly
1269
htmlTestRunner.controlPanel.setToPauseAtNextCommand();
1272
Selenium.prototype.doStore = function(expression, variableName) {
1273
/** This command is a synonym for storeExpression.
1274
* @param expression the value to store
1275
* @param variableName the name of a <a href="#storedVars">variable</a> in which the result is to be stored.
1277
storedVars[variableName] = expression;
1281
* Click on the located element, and attach a callback to notify
1282
* when the page is reloaded.
1284
// DGF TODO this code has been broken for some time... what is it trying to accomplish?
1285
Selenium.prototype.XXXdoModalDialogTest = function(returnValue) {
1286
this.browserbot.doModalDialogTest(returnValue);
1289
Selenium.prototype.doEcho = function(message) {
1290
/** Prints the specified message into the third table cell in your Selenese tables.
1291
* Useful for debugging.
1292
* @param message the message to print
1294
currentTest.currentRow.setMessage(message);
1298
* doSetSpeed and getSpeed are already defined in selenium-api.js,
1299
* so we're defining these functions in a tricky way so that doc.js doesn't
1300
* try to read API doc from the function definitions here.
1302
Selenium.prototype._doSetSpeed = function(value) {
1303
var milliseconds = parseInt(value);
1304
if (milliseconds < 0) milliseconds = 0;
1305
htmlTestRunner.controlPanel.speedController.setValue(milliseconds);
1306
htmlTestRunner.controlPanel.setRunInterval(milliseconds);
1308
Selenium.prototype.doSetSpeed = Selenium.prototype._doSetSpeed;
1310
Selenium.prototype._getSpeed = function() {
1311
return htmlTestRunner.controlPanel.runInterval;
1313
Selenium.prototype.getSpeed = Selenium.prototype._getSpeed;
1315
Selenium.prototype.assertSelected = function(selectLocator, optionLocator) {
1317
* Verifies that the selected option of a drop-down satisfies the optionSpecifier. <i>Note that this command is deprecated; you should use assertSelectedLabel, assertSelectedValue, assertSelectedIndex, or assertSelectedId instead.</i>
1319
* <p>See the select command for more information about option locators.</p>
1321
* @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
1322
* @param optionLocator an option locator, typically just an option label (e.g. "John Smith")
1324
var element = this.page().findElement(selectLocator);
1325
var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
1326
if (element.selectedIndex == -1)
1328
Assert.fail("No option selected");
1330
locator.assertSelected(element);
1333
Selenium.prototype.assertFailureOnNext = function(message) {
1335
* Tell Selenium to expect a failure on the next command execution.
1336
* @param message The failure message we should expect. This command will fail if the wrong failure message appears.
1339
throw new SeleniumError("Message must be provided");
1342
currentTest.expectedFailure = message;
1343
currentTest.expectedFailureType = "failure";
1344
currentTest.expectedFailureJustSet = true;
1347
Selenium.prototype.assertErrorOnNext = function(message) {
1349
* Tell Selenium to expect an error on the next command execution.
1350
* @param message The error message we should expect. This command will fail if the wrong error message appears.
1352
// This command temporarily installs a CommandFactory that generates
1353
// CommandHandlers that expect an error.
1355
throw new SeleniumError("Message must be provided");
1358
currentTest.expectedFailure = message;
1359
currentTest.expectedFailureType = "error";
1360
currentTest.expectedFailureJustSet = true;