summaryrefslogtreecommitdiff
path: root/tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js
diff options
context:
space:
mode:
authorxue <>2006-09-30 18:40:40 +0000
committerxue <>2006-09-30 18:40:40 +0000
commit1c32172efb18e8d08ea483e2460813670ebfe1a5 (patch)
tree8420f9e53eaba35d7b4822fac823197254f0d131 /tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js
parent6b1d87352911e43672b46b7a65a3c90dd8e5b8b1 (diff)
merge from 3.0 branch till 1451.
Diffstat (limited to 'tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js')
-rw-r--r--tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js271
1 files changed, 131 insertions, 140 deletions
diff --git a/tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js b/tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js
index ee01ea76..c11a80ad 100644
--- a/tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js
+++ b/tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js
@@ -15,38 +15,58 @@
*
*/
function CommandHandlerFactory() {
- this.actions = {};
- this.asserts = {};
- this.accessors = {};
var self = this;
+ this.handlers = {};
+
this.registerAction = function(name, action, wait, dontCheckAlertsAndConfirms) {
var handler = new ActionHandler(action, wait, dontCheckAlertsAndConfirms);
- this.actions[name] = handler;
+ this.handlers[name] = handler;
};
this.registerAccessor = function(name, accessor) {
var handler = new AccessorHandler(accessor);
- this.accessors[name] = handler;
+ this.handlers[name] = handler;
};
this.registerAssert = function(name, assertion, haltOnFailure) {
var handler = new AssertHandler(assertion, haltOnFailure);
- this.asserts[name] = handler;
+ this.handlers[name] = handler;
};
-
+
this.getCommandHandler = function(name) {
- return this.actions[name] || this.accessors[name] || this.asserts[name] || null;
+ return this.handlers[name] || null; // todo: why null, and not undefined?
};
- this.registerAll = function(commandObject) {
- registerAllAccessors(commandObject);
- registerAllActions(commandObject);
- registerAllAsserts(commandObject);
+ // Methods of the form getFoo(target) result in commands:
+ // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
+ // storeFoo, waitForFoo, and waitForNotFoo.
+ var _registerAllAccessors = function(commandObject) {
+ for (var functionName in commandObject) {
+ var matchForGetter = /^get([A-Z].+)$/.exec(functionName);
+ if (matchForGetter != null) {
+ var accessor = commandObject[functionName];
+ var baseName = matchForGetter[1];
+ self.registerAccessor(functionName, accessor);
+ self.registerAssertionsBasedOnAccessor(accessor, baseName);
+ self.registerStoreCommandBasedOnAccessor(accessor, baseName);
+ self.registerWaitForCommandsBasedOnAccessor(accessor, baseName);
+ }
+ var matchForIs = /^is([A-Z].+)$/.exec(functionName);
+ if (matchForIs != null) {
+ var accessor = commandObject[functionName];
+ var baseName = matchForIs[1];
+ var predicate = self.createPredicateFromBooleanAccessor(accessor);
+ self.registerAccessor(functionName, accessor);
+ self.registerAssertionsBasedOnAccessor(accessor, baseName, predicate);
+ self.registerStoreCommandBasedOnAccessor(accessor, baseName);
+ self.registerWaitForCommandsBasedOnAccessor(accessor, baseName, predicate);
+ }
+ }
};
- var registerAllActions = function(commandObject) {
+ var _registerAllActions = function(commandObject) {
for (var functionName in commandObject) {
var result = /^do([A-Z].+)$/.exec(functionName);
if (result != null) {
@@ -63,8 +83,7 @@ function CommandHandlerFactory() {
}
};
-
- var registerAllAsserts = function(commandObject) {
+ var _registerAllAsserts = function(commandObject) {
for (var functionName in commandObject) {
var result = /^assert([A-Z].+)$/.exec(functionName);
if (result != null) {
@@ -81,7 +100,12 @@ function CommandHandlerFactory() {
}
};
-
+ this.registerAll = function(commandObject) {
+ _registerAllAccessors(commandObject);
+ _registerAllActions(commandObject);
+ _registerAllAsserts(commandObject);
+ };
+
// Given an accessor function getBlah(target),
// return a "predicate" equivalient to isBlah(target, value) that
// is true when the value returned by the accessor matches the specified value.
@@ -95,7 +119,7 @@ function CommandHandlerFactory() {
}
};
};
-
+
// Given a (no-arg) accessor function getBlah(),
// return a "predicate" equivalient to isBlah(value) that
// is true when the value returned by the accessor matches the specified value.
@@ -109,20 +133,20 @@ function CommandHandlerFactory() {
}
};
};
-
+
// Given a boolean accessor function isBlah(),
// return a "predicate" equivalient to isBlah() that
// returns an appropriate PredicateResult value.
this.createPredicateFromBooleanAccessor = function(accessor) {
return function() {
- var accessorResult;
- if (arguments.length > 2) throw new SeleniumError("Too many arguments! " + arguments.length);
- if (arguments.length == 2) {
- accessorResult = accessor.call(this, arguments[0], arguments[1]);
+ var accessorResult;
+ if (arguments.length > 2) throw new SeleniumError("Too many arguments! " + arguments.length);
+ if (arguments.length == 2) {
+ accessorResult = accessor.call(this, arguments[0], arguments[1]);
} else if (arguments.length == 1) {
- accessorResult = accessor.call(this, arguments[0]);
+ accessorResult = accessor.call(this, arguments[0]);
} else {
- accessorResult = accessor.call(this);
+ accessorResult = accessor.call(this);
}
if (accessorResult) {
return new PredicateResult(true, "true");
@@ -131,17 +155,17 @@ function CommandHandlerFactory() {
}
};
};
-
+
// Given an accessor fuction getBlah([target]) (target is optional)
// return a predicate equivalent to isBlah([target,] value) that
// is true when the value returned by the accessor matches the specified value.
this.createPredicateFromAccessor = function(accessor) {
- if (accessor.length == 0) {
+ if (accessor.length == 0) {
return self.createPredicateFromNoArgAccessor(accessor);
}
return self.createPredicateFromSingleArgAccessor(accessor);
};
-
+
// Given a predicate, return the negation of that predicate.
// Leaves the message unchanged.
// Used to create assertNot, verifyNot, and waitForNot commands.
@@ -152,124 +176,90 @@ function CommandHandlerFactory() {
return result;
};
};
-
+
// Convert an isBlahBlah(target, value) function into an assertBlahBlah(target, value) function.
this.createAssertionFromPredicate = function(predicate) {
- return function(target, value) {
- var result = predicate.call(this, target, value);
- if (!result.isTrue) {
- Assert.fail(result.message);
- }
- };
+ return function(target, value) {
+ var result = predicate.call(this, target, value);
+ if (!result.isTrue) {
+ Assert.fail(result.message);
+ }
+ };
};
-
+
+
+ var _negtiveName = function(baseName) {
+ var matchResult = /^(.*)Present$/.exec(baseName);
+ if (matchResult != null) {
+ return matchResult[1] + "NotPresent";
+ }
+ return "Not" + baseName;
+ };
+
// Register an assertion, a verification, a negative assertion,
// and a negative verification based on the specified accessor.
this.registerAssertionsBasedOnAccessor = function(accessor, baseName, predicate) {
- if (predicate==null) {
+ if (predicate == null) {
predicate = self.createPredicateFromAccessor(accessor);
}
var assertion = self.createAssertionFromPredicate(predicate);
- // Register an assert with the "assert" prefix, and halt on failure.
self.registerAssert("assert" + baseName, assertion, true);
- // Register a verify with the "verify" prefix, and do not halt on failure.
self.registerAssert("verify" + baseName, assertion, false);
-
+
var invertedPredicate = self.invertPredicate(predicate);
var negativeAssertion = self.createAssertionFromPredicate(invertedPredicate);
-
- var result = /^(.*)Present$/.exec(baseName);
- if (result==null) {
- // Register an assertNot with the "assertNot" prefix, and halt on failure.
- self.registerAssert("assertNot"+baseName, negativeAssertion, true);
- // Register a verifyNot with the "verifyNot" prefix, and do not halt on failure.
- self.registerAssert("verifyNot"+baseName, negativeAssertion, false);
- }
- else {
- var invertedBaseName = result[1] + "NotPresent";
-
- // Register an assertNot ending w/ "NotPresent", and halt on failure.
- self.registerAssert("assert"+invertedBaseName, negativeAssertion, true);
- // Register an assertNot ending w/ "NotPresent", and do not halt on failure.
- self.registerAssert("verify"+invertedBaseName, negativeAssertion, false);
- }
+ self.registerAssert("assert" + _negtiveName(baseName), negativeAssertion, true);
+ self.registerAssert("verify" + _negtiveName(baseName), negativeAssertion, false);
};
-
-
+
// Convert an isBlahBlah(target, value) function into a waitForBlahBlah(target, value) function.
this.createWaitForActionFromPredicate = function(predicate) {
- var action = function(target, value) {
- var seleniumApi = this;
- testLoop.waitForCondition = function () {
- try {
- return predicate.call(seleniumApi, target, value).isTrue;
- } catch (e) {
- // Treat exceptions as meaning the condition is not yet met.
- // Useful, for example, for waitForValue when the element has
- // not even been created yet.
- // TODO: possibly should rethrow some types of exception.
- return false;
- }
- };
- };
- return action;
+ return function(target, value) {
+ var seleniumApi = this;
+ return function () {
+ try {
+ return predicate.call(seleniumApi, target, value).isTrue;
+ } catch (e) {
+ // Treat exceptions as meaning the condition is not yet met.
+ // Useful, for example, for waitForValue when the element has
+ // not even been created yet.
+ // TODO: possibly should rethrow some types of exception.
+ return false;
+ }
+ };
+ };
};
-
+
// Register a waitForBlahBlah and waitForNotBlahBlah based on the specified accessor.
this.registerWaitForCommandsBasedOnAccessor = function(accessor, baseName, predicate) {
if (predicate==null) {
predicate = self.createPredicateFromAccessor(accessor);
}
var waitForAction = self.createWaitForActionFromPredicate(predicate);
- self.registerAction("waitFor"+baseName, waitForAction, false, true);
+ self.registerAction("waitFor"+baseName, waitForAction, false, true);
var invertedPredicate = self.invertPredicate(predicate);
var waitForNotAction = self.createWaitForActionFromPredicate(invertedPredicate);
- self.registerAction("waitForNot"+baseName, waitForNotAction, false, true);
- }
-
- // Register a storeBlahBlah based on the specified accessor.
+ self.registerAction("waitFor"+_negtiveName(baseName), waitForNotAction, false, true);
+ //TODO decide remove "waitForNot.*Present" action name or not
+ //for the back compatiblity issues we still make waitForNot.*Present availble
+ self.registerAction("waitForNot"+baseName, waitForNotAction, false, true);
+ }
+
+ // Register a storeBlahBlah based on the specified accessor.
this.registerStoreCommandBasedOnAccessor = function(accessor, baseName) {
var action;
if (accessor.length == 1) {
- action = function(target, varName) {
- storedVars[varName] = accessor.call(this, target);
- };
- } else {
- action = function(varName) {
- storedVars[varName] = accessor.call(this);
- };
- }
- self.registerAction("store"+baseName, action, false, accessor.dontCheckAlertsAndConfirms);
- };
-
- // Methods of the form getFoo(target) result in commands:
- // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
- // storeFoo, waitForFoo, and waitForNotFoo.
- var registerAllAccessors = function(commandObject) {
- for (var functionName in commandObject) {
- var match = /^get([A-Z].+)$/.exec(functionName);
- if (match != null) {
- var accessor = commandObject[functionName];
- var baseName = match[1];
- self.registerAccessor(functionName, accessor);
- self.registerAssertionsBasedOnAccessor(accessor, baseName);
- self.registerStoreCommandBasedOnAccessor(accessor, baseName);
- self.registerWaitForCommandsBasedOnAccessor(accessor, baseName);
- }
- var match = /^is([A-Z].+)$/.exec(functionName);
- if (match != null) {
- var accessor = commandObject[functionName];
- var baseName = match[1];
- var predicate = self.createPredicateFromBooleanAccessor(accessor);
- self.registerAccessor(functionName, accessor);
- self.registerAssertionsBasedOnAccessor(accessor, baseName, predicate);
- self.registerStoreCommandBasedOnAccessor(accessor, baseName);
- self.registerWaitForCommandsBasedOnAccessor(accessor, baseName, predicate);
- }
+ action = function(target, varName) {
+ storedVars[varName] = accessor.call(this, target);
+ };
+ } else {
+ action = function(varName) {
+ storedVars[varName] = accessor.call(this);
+ };
}
+ self.registerAction("store"+baseName, action, false, accessor.dontCheckAlertsAndConfirms);
};
-
-
+
}
function PredicateResult(isTrue, message) {
@@ -301,36 +291,34 @@ function ActionHandler(action, wait, dontCheckAlerts) {
ActionHandler.prototype = new CommandHandler;
ActionHandler.prototype.execute = function(seleniumApi, command) {
if (this.checkAlerts && (null==/(Alert|Confirmation)(Not)?Present/.exec(command.command))) {
- this.checkForAlerts(seleniumApi);
+ seleniumApi.ensureNoUnhandledPopups();
}
- var processState = this.executor.call(seleniumApi, command.target, command.value);
+ var terminationCondition = this.executor.call(seleniumApi, command.target, command.value);
// If the handler didn't return a wait flag, check to see if the
// handler was registered with the wait flag.
- if (processState == undefined && this.wait) {
- processState = SELENIUM_PROCESS_WAIT;
- }
- return new CommandResult(processState);
-};
-ActionHandler.prototype.checkForAlerts = function(seleniumApi) {
- if ( seleniumApi.browserbot.hasAlerts() ) {
- throw new SeleniumError("There was an unexpected Alert! [" + seleniumApi.browserbot.getNextAlert() + "]");
- }
- if ( seleniumApi.browserbot.hasConfirmations() ) {
- throw new SeleniumError("There was an unexpected Confirmation! [" + seleniumApi.browserbot.getNextConfirmation() + "]");
+ if (terminationCondition == undefined && this.wait) {
+ terminationCondition = seleniumApi.makePageLoadCondition();
}
+ return new ActionResult(terminationCondition);
};
+function ActionResult(terminationCondition) {
+ this.terminationCondition = terminationCondition;
+}
+
function AccessorHandler(accessor) {
CommandHandler.call(this, "accessor", true, accessor);
}
AccessorHandler.prototype = new CommandHandler;
AccessorHandler.prototype.execute = function(seleniumApi, command) {
var returnValue = this.executor.call(seleniumApi, command.target, command.value);
- var result = new CommandResult();
- result.result = returnValue;
- return result;
+ return new AccessorResult(returnValue);
};
+function AccessorResult(result) {
+ this.result = result;
+}
+
/**
* Handler for assertions and verifications.
*/
@@ -339,10 +327,9 @@ function AssertHandler(assertion, haltOnFailure) {
}
AssertHandler.prototype = new CommandHandler;
AssertHandler.prototype.execute = function(seleniumApi, command) {
- var result = new CommandResult();
+ var result = new AssertResult();
try {
this.executor.call(seleniumApi, command.target, command.value);
- result.passed = true;
} catch (e) {
// If this is not a AssertionFailedError, or we should haltOnFailure, rethrow.
if (!e.isAssertionFailedError) {
@@ -352,20 +339,24 @@ AssertHandler.prototype.execute = function(seleniumApi, command) {
var error = new SeleniumError(e.failureMessage);
throw error;
}
- result.failed = true;
- result.failureMessage = e.failureMessage;
+ result.setFailed(e.failureMessage);
}
return result;
};
-
-function CommandResult(processState) {
- this.processState = processState;
- this.result = null;
+function AssertResult() {
+ this.passed = true;
+}
+AssertResult.prototype.setFailed = function(message) {
+ this.passed = null;
+ this.failed = true;
+ this.failureMessage = message;
}
-function SeleniumCommand(command, target, value) {
+function SeleniumCommand(command, target, value, isBreakpoint) {
this.command = command;
this.target = target;
this.value = value;
+ this.isBreakpoint = isBreakpoint;
}
+