Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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