[ Index ] |
|
Code source de PRADO 3.0.6 |
1 /* 2 * Copyright 2004 ThoughtWorks, Inc 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 function TestLoop(commandFactory) { 18 this.commandFactory = commandFactory; 19 } 20 21 TestLoop.prototype = { 22 23 start : function() { 24 selenium.reset(); 25 LOG.debug("currentTest.start()"); 26 this.continueTest(); 27 }, 28 29 continueTest : function() { 30 /** 31 * Select the next command and continue the test. 32 */ 33 LOG.debug("currentTest.continueTest() - acquire the next command"); 34 if (! this.aborted) { 35 this.currentCommand = this.nextCommand(); 36 } 37 if (! this.requiresCallBack) { 38 this.continueTestAtCurrentCommand(); 39 } // otherwise, just finish and let the callback invoke continueTestAtCurrentCommand() 40 }, 41 42 continueTestAtCurrentCommand : function() { 43 LOG.debug("currentTest.continueTestAtCurrentCommand()"); 44 if (this.currentCommand) { 45 // TODO: rename commandStarted to commandSelected, OR roll it into nextCommand 46 this.commandStarted(this.currentCommand); 47 this._resumeAfterDelay(); 48 } else { 49 this._testComplete(); 50 } 51 }, 52 53 _resumeAfterDelay : function() { 54 /** 55 * Pause, then execute the current command. 56 */ 57 58 // Get the command delay. If a pauseInterval is set, use it once 59 // and reset it. Otherwise, use the defined command-interval. 60 var delay = this.pauseInterval || this.getCommandInterval(); 61 this.pauseInterval = undefined; 62 63 if (this.currentCommand.isBreakpoint || delay < 0) { 64 // Pause: enable the "next/continue" button 65 this.pause(); 66 } else { 67 window.setTimeout(this.resume.bind(this), delay); 68 } 69 }, 70 71 resume: function() { 72 /** 73 * Select the next command and continue the test. 74 */ 75 LOG.debug("currentTest.resume() - actually execute"); 76 try { 77 selenium.browserbot.runScheduledPollers(); 78 this._executeCurrentCommand(); 79 this.continueTestWhenConditionIsTrue(); 80 } catch (e) { 81 this._handleCommandError(e); 82 this._testComplete(); 83 return; 84 } 85 }, 86 87 _testComplete : function() { 88 selenium.ensureNoUnhandledPopups(); 89 this.testComplete(); 90 }, 91 92 _executeCurrentCommand : function() { 93 /** 94 * Execute the current command. 95 * 96 * @return a function which will be used to determine when 97 * execution can continue, or null if we can continue immediately 98 */ 99 var command = this.currentCommand; 100 LOG.info("Executing: |" + command.command + " | " + command.target + " | " + command.value + " |"); 101 102 var handler = this.commandFactory.getCommandHandler(command.command); 103 if (handler == null) { 104 throw new SeleniumError("Unknown command: '" + command.command + "'"); 105 } 106 107 command.target = selenium.preprocessParameter(command.target); 108 command.value = selenium.preprocessParameter(command.value); 109 LOG.debug("Command found, going to execute " + command.command); 110 var result = handler.execute(selenium, command); 111 LOG.debug("Command complete"); 112 this.commandComplete(result); 113 114 this.waitForCondition = result.terminationCondition; 115 116 }, 117 118 _handleCommandError : function(e) { 119 if (!e.isSeleniumError) { 120 LOG.exception(e); 121 var msg = "Selenium failure. Please report to selenium-dev@openqa.org, with error details from the log window."; 122 if (e.message) { 123 msg += " The error message is: " + e.message; 124 } 125 this.commandError(msg); 126 } else { 127 LOG.error(e.message); 128 this.commandError(e.message); 129 } 130 }, 131 132 continueTestWhenConditionIsTrue: function () { 133 /** 134 * Busy wait for waitForCondition() to become true, and then carry 135 * on with test. Fail the current test if there's a timeout or an 136 * exception. 137 */ 138 LOG.debug("currentTest.continueTestWhenConditionIsTrue()"); 139 selenium.browserbot.runScheduledPollers(); 140 try { 141 if (this.waitForCondition == null || this.waitForCondition()) { 142 LOG.debug("condition satisfied; let's continueTest()"); 143 this.waitForCondition = null; 144 this.continueTest(); 145 } else { 146 LOG.debug("waitForCondition was false; keep waiting!"); 147 window.setTimeout(this.continueTestWhenConditionIsTrue.bind(this), 100); 148 } 149 } catch (e) { 150 var lastResult = {}; 151 lastResult.failed = true; 152 lastResult.failureMessage = e.message; 153 this.commandComplete(lastResult); 154 this.testComplete(); 155 } 156 }, 157 158 pause : function() {}, 159 nextCommand : function() {}, 160 commandStarted : function() {}, 161 commandComplete : function() {}, 162 commandError : function() {}, 163 testComplete : function() {}, 164 165 getCommandInterval : function() { 166 return 0; 167 } 168 169 } 170 171 function decorateFunctionWithTimeout(f, timeout) { 172 if (f == null) { 173 return null; 174 } 175 if (isNaN(timeout)) { 176 throw new SeleniumError("Timeout is not a number: " + timeout); 177 } 178 var now = new Date().getTime(); 179 var timeoutTime = now + timeout; 180 return function() { 181 if (new Date().getTime() > timeoutTime) { 182 throw new SeleniumError("Timed out after " + timeout + "ms"); 183 } 184 return f(); 185 }; 186 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |