Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/js/qunit/qunit_test_runner.js
4506 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* @fileoverview QUnit test runner adapter for Selenium's Java test harness.
20
*
21
* This script registers QUnit callbacks to track test execution and exposes
22
* a simple API on window.top that the Java ClosureTestStatement can poll
23
* to determine when tests are finished and whether they passed.
24
*/
25
(function() {
26
'use strict';
27
28
var results = {
29
finished: false,
30
passed: false,
31
report: '',
32
failures: []
33
};
34
35
// Expose the test runner interface on window.top for the Java harness to poll
36
window.top.QUnitTestRunner = {
37
isFinished: function() {
38
return results.finished;
39
},
40
isSuccess: function() {
41
return results.passed;
42
},
43
getReport: function() {
44
return results.report;
45
}
46
};
47
48
QUnit.on('testEnd', function(testEnd) {
49
if (testEnd.status === 'failed') {
50
var fullName = testEnd.fullName.join(' > ');
51
var errors = testEnd.errors.map(function(err) {
52
var msg = err.message || '';
53
if (err.actual !== undefined && err.expected !== undefined) {
54
msg += '\n Expected: ' + JSON.stringify(err.expected);
55
msg += '\n Actual: ' + JSON.stringify(err.actual);
56
}
57
if (err.stack) {
58
msg += '\n Stack: ' + err.stack;
59
}
60
return msg;
61
});
62
results.failures.push({
63
name: fullName,
64
errors: errors
65
});
66
}
67
});
68
69
QUnit.on('runEnd', function(runEnd) {
70
results.finished = true;
71
results.passed = runEnd.status === 'passed';
72
73
var lines = [];
74
lines.push('QUnit Test Results');
75
lines.push('==================');
76
lines.push('Status: ' + runEnd.status);
77
lines.push('Total: ' + runEnd.testCounts.total);
78
lines.push('Passed: ' + runEnd.testCounts.passed);
79
lines.push('Failed: ' + runEnd.testCounts.failed);
80
lines.push('Skipped: ' + runEnd.testCounts.skipped);
81
lines.push('Todo: ' + runEnd.testCounts.todo);
82
lines.push('Runtime: ' + runEnd.runtime + 'ms');
83
84
if (results.failures.length > 0) {
85
lines.push('');
86
lines.push('Failures:');
87
lines.push('---------');
88
results.failures.forEach(function(failure) {
89
lines.push('');
90
lines.push('Test: ' + failure.name);
91
failure.errors.forEach(function(err) {
92
lines.push(' ' + err);
93
});
94
});
95
}
96
97
results.report = lines.join('\n');
98
});
99
})();
100
101