From 61bb16ee2e5f0a66234e1575242169a10fde47b5 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 7 Jul 2006 14:54:15 +0000 Subject: Merge from 3.0 branch till 1253. --- tests/test_tools/selenium/prado-functional-test.js | 247 +++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 tests/test_tools/selenium/prado-functional-test.js (limited to 'tests/test_tools/selenium/prado-functional-test.js') diff --git a/tests/test_tools/selenium/prado-functional-test.js b/tests/test_tools/selenium/prado-functional-test.js new file mode 100644 index 00000000..306f6a74 --- /dev/null +++ b/tests/test_tools/selenium/prado-functional-test.js @@ -0,0 +1,247 @@ + +/** + * 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. + * + *

See the select command for more information about option locators.

+ * + * @param selectLocator an element locator 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; +} + +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= 0) + return; + Assert.fail("Unable to find '"+(expectedValue.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, "\""))+"' was found in document.body"); +}; \ No newline at end of file -- cgit v1.2.3