From 3ac04dd9cbb3c14fb2522793b2268b910837d8c4 Mon Sep 17 00:00:00 2001 From: wei <> Date: Wed, 31 May 2006 04:26:21 +0000 Subject: Update selenium javascript, now runs in Safari! --- .../core/scripts/selenium-seleneserunner.js | 300 +++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100755 tests/FunctionalTests/selenium/core/scripts/selenium-seleneserunner.js (limited to 'tests/FunctionalTests/selenium/core/scripts/selenium-seleneserunner.js') diff --git a/tests/FunctionalTests/selenium/core/scripts/selenium-seleneserunner.js b/tests/FunctionalTests/selenium/core/scripts/selenium-seleneserunner.js new file mode 100755 index 00000000..041b3bf9 --- /dev/null +++ b/tests/FunctionalTests/selenium/core/scripts/selenium-seleneserunner.js @@ -0,0 +1,300 @@ +/* +* Copyright 2005 ThoughtWorks, Inc +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +passColor = "#cfffcf"; +failColor = "#ffcfcf"; +errorColor = "#ffffff"; +workingColor = "#DEE7EC"; +doneColor = "#FFFFCC"; + +slowMode = false; + +var cmd1 = document.createElement("div"); +var cmd2 = document.createElement("div"); +var cmd3 = document.createElement("div"); +var cmd4 = document.createElement("div"); + +var postResult = "START"; + +queryString = null; + +function runTest() { + var testAppFrame = document.getElementById('myiframe'); + selenium = Selenium.createForFrame(testAppFrame); + + commandFactory = new CommandHandlerFactory(); + commandFactory.registerAll(selenium); + + testLoop = new TestLoop(commandFactory); + + testLoop.nextCommand = nextCommand; + testLoop.commandStarted = commandStarted; + testLoop.commandComplete = commandComplete; + testLoop.commandError = commandError; + testLoop.requiresCallBack = true; + testLoop.testComplete = function() { + window.status = "Selenium Tests Complete, for this Test" + // Continue checking for new results + testLoop.continueTest(); + postResult = "START"; + }; + + document.getElementById("commandList").appendChild(cmd4); + document.getElementById("commandList").appendChild(cmd3); + document.getElementById("commandList").appendChild(cmd2); + document.getElementById("commandList").appendChild(cmd1); + + var doContinue = getQueryVariable("continue"); + if (doContinue != null) postResult = "OK"; + + testLoop.start(); +} + +function getQueryString() { + if (queryString != null) return queryString; + if (browserVersion.isHTA) { + var args = extractArgs(); + if (args.length < 2) return null; + queryString = args[1]; + return queryString; + } else { + return location.search.substr(1); + } +} + +function extractArgs() { + var str = SeleniumHTARunner.commandLine; + if (str == null || str == "") return new Array(); + var matches = str.match(/(?:"([^"]+)"|(?!"([^"]+)")(\S+))/g); + // We either want non quote stuff ([^"]+) surrounded by quotes + // or we want to look-ahead, see that the next character isn't + // a quoted argument, and then grab all the non-space stuff + // this will return for the line: "foo" bar + // the results "\"foo\"" and "bar" + + // So, let's unquote the quoted arguments: + var args = new Array; + for (var i = 0; i < matches.length; i++) { + args[i] = matches[i]; + args[i] = args[i].replace(/^"(.*)"$/, "$1"); + } + return args; +} + +function getQueryVariable(variable) { + var query = getQueryString(); + if (query == null) return null; + var vars = query.split("&"); + for (var i=0;i " + e[key] + "\n" + } + LOG.error(s); + return null; + } + return null; +} + + function handleHttpResponse() { + if (xmlHttp.readyState == 4) { + if (xmlHttp.status == 200) { + var command = extractCommand(xmlHttp); + testLoop.currentCommand = command; + testLoop.beginNextTest(); + } else { + var s = 'xmlHttp returned: ' + xmlHttp.status + ": " + xmlHttp.statusText; + LOG.error(s); + testLoop.currentCommand = null; + setTimeout("testLoop.beginNextTest();", 2000); + } + + } + } + + +function extractCommand(xmlHttp) { + if (slowMode) { + delay(2000); + } + + var command; + try { + command = xmlHttp.responseText; + } catch (e) { + alert('could not get responseText: ' + e.message); + } + if (command.substr(0,'|testComplete'.length)=='|testComplete') { + return null; + } + + return createCommandFromRequest(command); +} + +function commandStarted(command) { + commandNode = document.createElement("div"); + innerHTML = command.command + '('; + if (command.target != null && command.target != "") { + innerHTML += command.target; + if (command.value != null && command.value != "") { + innerHTML += ', ' + command.value; + } + } + innerHTML += ")"; + commandNode.innerHTML = innerHTML; + commandNode.style.backgroundColor = workingColor; + document.getElementById("commandList").removeChild(cmd1); + document.getElementById("commandList").removeChild(cmd2); + document.getElementById("commandList").removeChild(cmd3); + document.getElementById("commandList").removeChild(cmd4); + cmd4 = cmd3; + cmd3 = cmd2; + cmd2 = cmd1; + cmd1 = commandNode; + document.getElementById("commandList").appendChild(cmd4); + document.getElementById("commandList").appendChild(cmd3); + document.getElementById("commandList").appendChild(cmd2); + document.getElementById("commandList").appendChild(cmd1); +} + +function commandComplete(result) { + if (result.failed) { + if (postResult == "CONTINUATION") { + testLoop.aborted = true; + } + postResult = result.failureMessage; + commandNode.title = result.failureMessage; + commandNode.style.backgroundColor = failColor; + } else if (result.passed) { + postResult = "OK"; + commandNode.style.backgroundColor = passColor; + } else { + if (result.result == null) { + postResult = "OK"; + } else { + postResult = "OK," + result.result; + } + commandNode.style.backgroundColor = doneColor; + } +} + +function commandError(message) { + postResult = "ERROR: " + message; + commandNode.style.backgroundColor = errorColor; + commandNode.title = message; +} + +function slowClicked() { + slowMode = !slowMode; +} + +function delay(millis) { + startMillis = new Date(); + while (true) { + milli = new Date(); + if (milli-startMillis > millis) { + break; + } + } +} + +function getIframeDocument(iframe) { + if (iframe.contentDocument) { + return iframe.contentDocument; + } + else { + return iframe.contentWindow.document; + } +} + +// Parses a URI query string into a SeleniumCommand object +function createCommandFromRequest(commandRequest) { + //decodeURIComponent doesn't strip plus signs + var processed = commandRequest.replace(/\+/g, "%20"); + // strip trailing spaces + var processed = processed.replace(/\s+$/, ""); + var vars = processed.split("&"); + var cmdArgs = new Object(); + for (var i=0;i