summaryrefslogtreecommitdiff
path: root/tests/FunctionalTests/selenium/prado-functional-test.js
blob: 37e265161f0027fc87f8a129270410c94c1d25ec (plain)
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

function runNextTest() {
    if (!runAllTests)
            return;

    suiteTable = getIframeDocument(getSuiteFrame()).getElementsByTagName("table")[0];

    // Do not change the row color of the first row
    if (currentRowInSuite > 0) {
        // Provide test-status feedback
        if (testFailed) {
            setCellColor(suiteTable.rows, currentRowInSuite, 0, failColor);
        } else {
            setCellColor(suiteTable.rows, currentRowInSuite, 0, passColor);
        }

        // Set the results from the previous test run
        setResultsData(suiteTable, currentRowInSuite);
    }

    currentRowInSuite++;

    // If we are done with all of the tests, set the title bar as pass or fail
    if (currentRowInSuite >= suiteTable.rows.length) {
        if (suiteFailed) {
            setCellColor(suiteTable.rows, 0, 0, failColor);
        } else {
            setCellColor(suiteTable.rows, 0, 0, passColor);
        }

        LOG.warn("next? ", "warn");
        // If this is an automated run (i.e., build script), then submit
        // the test results by posting to a form

        postTestResults(suiteFailed, suiteTable);
    }

    else {
        // Make the current row blue
        setCellColor(suiteTable.rows, currentRowInSuite, 0, workingColor);

        testLink = suiteTable.rows[currentRowInSuite].cells[0].getElementsByTagName("a")[0];
        testLink.focus();

        var testFrame = getTestFrame();
        addLoadListener(testFrame, startTest);

        selenium.browserbot.setIFrameLocation(testFrame, testLink.href);
    }
}

// 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) {

    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((currentTime - startTime) / 1000));
    form.createHiddenField("numTestPasses", numTestPasses);
    form.createHiddenField("numTestFailures", numTestFailures);
    form.createHiddenField("numCommandPasses", numCommandPasses);
    form.createHiddenField("numCommandFailures", numCommandFailures);
    form.createHiddenField("numCommandErrors", 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 == passColor) return "passed";
	if(color == failColor) return "failed";
	if(color == doneColor) return "done";
	return "";
}