Alex, There wasn't other interest so I didn't put together any test cases or documentation. Here's a quick usage overview of the changes I made. I've also attached the SVN patch file as you requested.
Below are simple examples of the branching usage. Each "[]" is a table cells/rows. Conditional branches test against the last run assert/verify, postfix style. --Robert Gesswein ==Unconditional Goto== [open] [http://localhost/Welcome.aspx] [] [goto] [MyLabel] [] [...some tests...] [:MyLabel] [] [] // label starts with ":" [...some tests...] ==Conditional Goto== [open] [http://localhost/Welcome.aspx] [] [verifyTitle] [Login] [] [...any non assert/verify tests...] [goto] [MyLabel] [pass] // goto only if verifyTitle passed [...some tests...] [:MyLabel] [] [] [...additional tests...] ==Unconditional Gosub== [open] [http://localhost/Welcome.aspx] [] [gosub] [MyLabel] [] [...some tests...] [:MyLabel] [] [] [...additional tests...] [return] [] [] // returns to "...some tests..." ==Conditional Gosub== [open] [http://localhost/Welcome.aspx] [] [verifyTitle] [Login] [] [...any non assert/verify tests...] [gosub] [MyLabel] [fail] // gosub only if verifyTitle failed [...some tests...] [:MyLabel] [] [] [...additional tests...] [return] [] [] // returns to "...some tests..." =========================== Alex Dvoretskiy wrote:
Yes, I am interested. Can you post it to this mailing list as attachment? The svn patch format is preferable.
Index: selenium-api.js =================================================================== --- selenium-api.js (revision 630) +++ selenium-api.js (working copy) @@ -508,6 +508,64 @@ }; }; + +/* + * Goto the row specified in the target cell + * the target row's command cell is formatted ":Label" + * value = "" is unconditional jump. + * value = pass/true jumps if last verify test passed. + * value = fail/false jumps if last verify test failed. + */ +Selenium.prototype.doGoto = function(target, value) { + value = value.toLowerCase(); + if (value=="") { + gotoCommand(target); + } + else if (value=="pass" || value=="true") { + if (!lastAssertFailed) { + gotoCommand(target); + } + } + else if (value=="fail" || value=="false") { + if (lastAssertFailed) { + gotoCommand(target); + } + } +}; + +/* + * Gosub the row specified in the target cell + * the target row's command cell is formatted ":Label" + * value = "" is unconditional jump. + * value = pass/true jumps if last verify test passed. + * value = fail/false jumps if last verify test failed. + */ +Selenium.prototype.doGosub = function(target, value) { + value = value.toLowerCase(); + if (value=="") { + gosubCommand(target); + } + else if (value=="pass" || value=="true") { + if (!lastAssertFailed) { + gosubCommand(target); + } + } + else if (value=="fail" || value=="false") { + if (lastAssertFailed) { + gosubCommand(target); + } + } +}; + +/* + * Return from the last Gosub call. + * Ignored if no pending return. + */ +Selenium.prototype.doReturn = function() { + returnFromCommand(); +}; + + /** * Evaluate a parameter, performing javascript evaluation and variable substitution. * If the string matches the pattern "javascript{ ... }", evaluate the string between the braces. Index: selenium-fitrunner.js =================================================================== --- selenium-fitrunner.js (revision 630) +++ selenium-fitrunner.js (working copy) @@ -15,6 +15,7 @@ * */ +defaultColor = "white"; passColor = "#cfffcf"; failColor = "#ffcfcf"; workingColor = "#DEE7EC"; @@ -33,6 +34,16 @@ testFailed = false; suiteFailed = false; +// Holds the command row being executed prior to a "jump" (goto, gosub, or return). +// (Used to allow stepping colors to change correctly.) +fromCommandRow = 0; + +// Status of the last Assert/Verify check. Used by conditional Goto/Gosub. +lastAssertFailed = false; + +// Return stack for Gosubs +returnStack = new Array(); + // Holds the handlers for each command. commandHandlers = null; @@ -266,6 +277,7 @@ inputTable = getIframeDocument(getTestFrame()).getElementsByTagName("table")[0]; inputTableRows = inputTable.rows; currentCommandRow = 0; + returnStack.length = 0; // clear the return stack testFailed = false; storedVars = new Object(); @@ -277,7 +289,7 @@ function clearRowColours() { for (var i = 0; i <= inputTableRows.length - 1; i++) { - inputTableRows[i].bgColor = "white"; + inputTableRows[i].bgColor = defaultColor; } } @@ -494,13 +506,18 @@ } function nextCommand() { - if (currentCommandRow >= inputTableRows.length - 1) { - return null; + while (true) { + if (currentCommandRow >= inputTableRows.length - 1) { + return null; + } + + currentCommandRow++; + + var commandName = getCellText(currentCommandRow, 0); + if (commandName.substr(0,1) != ":") { + break; + } } - - currentCommandRow++; - - var commandName = getCellText(currentCommandRow, 0); var target = getCellText(currentCommandRow, 1); var value = getCellText(currentCommandRow, 2); @@ -508,6 +525,30 @@ return command; } +function gotoCommand(label) { + label = ":" + label.toUpperCase(); + for (i = 1; i<inputTableRows.length; i++) { + var commandName = getCellText(i, 0); + if (commandName.toUpperCase() == label) { + fromCommandRow = currentCommandRow; + currentCommandRow = i; + return; + } + } +} + +function gosubCommand(label) { + returnStack.push(currentCommandRow); + gotoCommand(label); +} + +function returnFromCommand() { + if (returnStack.length > 0) { + fromCommandRow = currentCommandRow; + currentCommandRow = returnStack.pop(); + } +} + function removeNbsp(value) { return value.replace(/\240/g, ""); @@ -522,7 +563,11 @@ // scrollIntoView (like Konqueror) } -function commandStarted() { +function commandStarted(command) { + if (commandFactory.asserts[command.command] != null) { // verify command is an assertion + lastAssertFailed = false; + //alert(command.command); + } inputTableRows[currentCommandRow].bgColor = workingColor; scrollIntoView(inputTableRows[currentCommandRow].cells[0]); printMetrics(); @@ -531,19 +576,27 @@ function commandComplete(result) { if (result.failed) { setRowFailed(result.failureMessage, FAILURE); + if (commandFactory.asserts[command.command] != null) { // verify command is an assertion + lastAssertFailed = true; + } } else if (result.passed) { setRowPassed(); } else { - setRowWhite(); + setRowColorToDefault(); } + + if (fromCommandRow!=0) { + inputTableRows[fromCommandRow].bgColor = defaultColor; + fromCommandRow = 0; + } } function commandError(errorMessage) { setRowFailed(errorMessage, ERROR); } -function setRowWhite() { - inputTableRows[currentCommandRow].bgColor = "white"; +function setRowColorToDefault() { + inputTableRows[currentCommandRow].bgColor = defaultColor; } function setRowPassed() {
_______________________________________________ Selenium-devel mailing list Selenium-devel@lists.public.thoughtworks.org http://lists.public.thoughtworks.org/mailman/listinfo/selenium-devel