1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
Object.extend(HtmlTestRunner.prototype, {
loadSuiteFrame: function() {
if (selenium == null) {
selenium = Selenium.createForWindow(this._getApplicationWindow());
this._registerCommandHandlers();
}
this.controlPanel.setHighlightOption();
//var testSuiteName = this.controlPanel.getTestSuiteName();
var testSuiteName = document.location+'?testSuites';
if (testSuiteName) {
suiteFrame.load(testSuiteName, this._onloadTestSuite.bind(this));
}
}
});
Object.extend(HtmlTestRunnerControlPanel.prototype, {
_parseQueryParameter: function() {
var tempRunInterval = this._getQueryParameter("runInterval");
if (tempRunInterval) {
this.setRunInterval(tempRunInterval);
}
}
});
/**
* Override selenium implementation.
*/
Selenium.prototype.getAttribute = function(target) {
return this.page().findAttribute(target);
};
/**
* Override selenium implementation.
*/
Selenium.prototype.isVisible = function(locator) {
var element;
element = this.page().findElement(locator);
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
var visibility = element.style["visibility"];
else
var visibility = this.findEffectiveStyleProperty(element, "visibility");
var _isDisplayed = this._isDisplayed(element);
return (visibility != "hidden" && _isDisplayed);
};
/**
* Override selenium implementation.
*/
Selenium.prototype._isDisplayed = function(element) {
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
var display = element.style["display"];
else
var display = this.findEffectiveStyleProperty(element, "display");
if (display == "none") return false;
if (element.parentNode.style) {
return this._isDisplayed(element.parentNode);
}
return true;
};
Selenium.prototype.assertEmptySelection = function(selectLocator, optionLocator)
{
/**
* Verifies that the selected option of a drop-down satisfies the optionSpecifier.
*
* <p>See the select command for more information about option locators.</p>
*
* @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
* @param optionLocator an option locator, typically just an option label (e.g. "John Smith")
*/
var element = this.page().findElement(selectLocator);
var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
return element.selectedIndex == -1;
}
Object.extend(HtmlTestSuite.prototype, {
_onTestSuiteComplete: function() {
this.markDone();
var result = new TestResult(this.failed, this.getTestTable());
postTestResults(this.failed, this.getTestTable(), result);
}
});
// Post the results to a servlet, CGI-script, etc. The URL of the
// results-handler defaults to "/postResults", but an alternative location
// can be specified by providing a "resultsUrl" query parameter.
//
// Parameters passed to the results-handler are:
// result: passed/failed depending on whether the suite passed or failed
// totalTime: the total running time in seconds for the suite.
//
// numTestPasses: the total number of tests which passed.
// numTestFailures: the total number of tests which failed.
//
// numCommandPasses: the total number of commands which passed.
// numCommandFailures: the total number of commands which failed.
// numCommandErrors: the total number of commands which errored.
//
// suite: the suite table, including the hidden column of test results
// testTable.1 to testTable.N: the individual test tables
//
function postTestResults(suiteFailed, suiteTable, result) {
form = document.createElement("form");
document.body.appendChild(form);
form.id = "resultsForm";
form.method="post";
form.target="myiframe";
var resultsUrl = post_results_to;
if (!resultsUrl) {
resultsUrl = "./results.php";
}
var actionAndParameters = resultsUrl.split('?',2);
form.action = actionAndParameters[0];
LOG.warn(form.action)
var resultsUrlQueryString = actionAndParameters[1];
form.createHiddenField = function(name, value) {
input = document.createElement("input");
input.type = "hidden";
input.name = name;
input.value = value;
this.appendChild(input);
};
if (resultsUrlQueryString) {
var clauses = resultsUrlQueryString.split('&');
for (var i = 0; i < clauses.length; i++) {
var keyValuePair = clauses[i].split('=',2);
var key = unescape(keyValuePair[0]);
var value = unescape(keyValuePair[1]);
form.createHiddenField(key, value);
}
}
form.createHiddenField("result", suiteFailed == true ? "failed" : "passed");
form.createHiddenField("totalTime", Math.floor((result.metrics.currentTime - result.metrics.startTime) / 1000));
form.createHiddenField("numTestPasses", result.metrics.numTestPasses);
form.createHiddenField("numTestFailures", result.metrics.numTestFailures);
form.createHiddenField("numCommandPasses", result.metrics.numCommandPasses);
form.createHiddenField("numCommandFailures", result.metrics.numCommandFailures);
form.createHiddenField("numCommandErrors", result.metrics.numCommandErrors);
// Create an input for each test table. The inputs are named
// testTable.1, testTable.2, etc.
for (rowNum = 1; rowNum < suiteTable.rows.length;rowNum++) {
// If there is a second column, then add a new input
if (suiteTable.rows[rowNum].cells.length > 1) {
var resultCell = suiteTable.rows[rowNum].cells[1];
parse_resultCell(resultCell,rowNum,form);
//form.createHiddenField("tests[]", resultCell.innerHTML);
// remove the resultCell, so it's not included in the suite HTML
//resultCell.parentNode.removeChild(resultCell);
}
}
// Add HTML for the suite itself
//form.createHiddenField("suite", suiteTable.parentNode.innerHTML);
form.submit();
document.body.removeChild(form);
}
function parse_resultCell(resultCell,rowNum,form)
{
var div = resultCell.childNodes[0];
var table;
for(var i = 0; i<div.childNodes.length; i++)
{
if(div.childNodes[i].nodeName.toLowerCase() == 'table')
table = div.childNodes[i];
}
//LOG.info(div.innerHTML);
var testname = table.rows[0].cells[0].firstChild.innerHTML;
var resultColor = get_color_status(table.rows[0]);
form.createHiddenField("tests["+rowNum+"][testcase]",testname);
//var trace = window.testSuiteFrame.prado_trace[testname];
for(var i = 1; i<table.rows.length; i++)
{
var msg = table.rows[i].getAttribute("title");
var result = get_color_status(table.rows[i]);
var action = table.rows[i].cells[0].innerHTML;
var target = table.rows[i].cells[1].innerHTML;
var param = table.rows[i].cells[2].innerHTML;
var id = "tests["+rowNum+"][commands]["+(i-1)+"]";
form.createHiddenField(id+"[command]", "|"+action+"|"+target+"|"+param+"|");
form.createHiddenField(id+"[result]", result);
form.createHiddenField(id+"[msg]", msg);
//form.createHiddenField(id+"[trace]", trace[i-1]);
}
}
function get_color_status(element)
{
var color = element.getAttribute("bgcolor");
if(color == FeedbackColors.passColor) return "passed";
if(color == FeedbackColors.failColor) return "failed";
if(color == FeedbackColors.doneColor) return "done";
return "";
}
Selenium.prototype.assertHTMLPresent = function(expectedValue) {
var actualValue = this.page().currentDocument.body.innerHTML;
if(actualValue.indexOf(expectedValue) >= 0)
return;
Assert.fail("Unable to find '"+(expectedValue.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\""))+"' in document.body");
};
Selenium.prototype.assertHTMLNotPresent = function(expectedValue) {
var actualValue = this.page().currentDocument.body.innerHTML;
if(actualValue.indexOf(expectedValue) < 0)
return;
Assert.fail("'"+(expectedValue.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\""))+"' was found in document.body");
};
|