Using Selenium Remote Control
by Dave
Bauer
To use Selenium Remote Control to run browser-based tested from
acs-automated-testing first install Selenium Remote
Control. Download
Selenium RC. This requires a working Java
configuration. See Selenium
RC Documentation and specifically Selenium
RC Installation.
You can record tests to Tcl code that will run in
acs-automated-testing by adding the a Tcl-RC mode in Selenium-IDE.
Open up Firefox, click on Tools, select Selenium IDE, select
Options, then Options again. Click on the formats tab. Click add.
Name the format "Tcl-Rc". Paste the following code in the large
box.
/*
* Format for Selenium Remote Control Python client.
*/
load('remoteControl.js');
this.name = "tcl-rc";
function testMethodName(testName) {
return "test_" + underscore(testName);
}
notOperator = function() {
return "! ";
}
tclString = function(value) {
value = value.replace(/\\/g, '\\\\');
value = value.replace(/\"/g, '\\"');
value = value.replace(/\r/g, '\\r');
value = value.replace(/\n/g, '\\n');
value = value.replace(/\{/g, '\\{');
value = value.replace(/\}/g, '\\}');
value = value.replace(/\[/g, '\\[');
value = value.replace(/\]/g, '\\]');
value = value.replace(/\$/g, '\\$');
var unicode = false;
for (var i = 0; i < value.length; i++) {
if (value.charCodeAt(i) >= 128) {
unicode = true;
}
}
return (unicode ? 'u' : '') + '"' + value + '"';
}
function assertTrue(expression) {
return "aa_true " + tclString(expression.toString()) + " [expr {![catch {" + expression.toString() + "} errmsg]}]";
}
function assertFalse(expression) {
return "aa_false " + tclString(expression.toString()) + " [expr {![catch {" + expression.toString() + "} errmsg]}]";
}
function verify(statement) {
return statement;
}
function verifyTrue(expression) {
return verify(assertTrue(expression));
}
function verifyFalse(expression) {
return verify(assertFalse(expression));
}
function joinExpression(expression) {
return "join " + expression.toString();
}
function assignToVariable(type, variable, expression) {
return "set " + underscore(variable) + " [" + expression.toString() + "]";
}
function waitFor(expression) {
return "for {set i 0} {i < " + expression.toString() + "} {incr i} {\n"
+ "if {" + expression.toString() + "} {break}\n"
+ "after 1000\n"
+ "}\n"
+ "if {$i == 60} {error \"time out\"}";
}
function assertOrVerifyFailure(line, isAssert) {
return "" + line + "} errmsg]} {error \"expected failure\"}";
}
Equals.prototype.toString = function() {
return this.e1.toString() + " eq " + this.e2.toString();
}
Equals.prototype.assert = function() {
return 'aa_equal ' + string(this.e2.toString() + this.e1.toString()) + ' ' + this.e1.toString() + ' [' + this.e2.toString() +']';
}
Equals.prototype.verify = function() {
return verify(this.assert());
}
NotEquals.prototype.toString = function() {
return this.e1.toString() + " ne " + this.e2.toString();
}
NotEquals.prototype.assert = function() {
return "aa_true " + tclString(this.e1.toString() + " ne " + this.e2.toString()) + " [expr {" + this.e1.toString() + " ne " + this.e2.toString() + "}]";
}
NotEquals.prototype.verify = function() {
return verify(this.assert());
}
RegexpMatch.prototype.toString = function() {
var str = this.pattern;
if (str.match(/\"/) || str.match(/\n/)) {
str = str.replace(/\\/g, "\\\\");
str = str.replace(/\"/g, '\\"');
str = str.replace(/\n/g, '\\n');
return '"' + str + '"';
} else {
str = 'r"' + str + '"';
}
return "re.search(" + str + ", " + this.expression + ")";
}
function pause(milliseconds) {
return "after " + milliseconds;
}
function echo(message) {
return "aa_log " + xlateArgument(message);
}
function statement(expression) {
return expression.toString();
}
function array(value) {
var str = '[lst ';
for (var i = 0; i < value.length; i++) {
str += string(value[i]);
if (i < value.length - 1) str += " ";
}
str += ']';
return str;
}
function nonBreakingSpace() {
return "u\"\\u00a0\"";
}
CallSelenium.prototype.toString = function() {
var result = '';
if (this.negative) {
result += '! ';
}
if (options.receiver) {
result += options.receiver + ' ';
}
result += this.message + ' ';
for (var i = 0; i < this.args.length; i++) {
result += this.args[i];
if (i < this.args.length - 1) {
result += ' ';
}
}
return result;
}
function formatComment(comment) {
return comment.comment.replace(/.+/mg, function(str) {
return "# " + str;
});
}
this.options = {
header:'',
footer:''
};
this.configForm =
'<description>Variable for Selenium instance</description>' +
'<description>Header</description>' +
'<textbox id="options_header" multiline="true" flex="1" rows="4"/>' +
'<description>Footer</description>' +
'<textbox id="options_footer" multiline="true" flex="1" rows="4"/>';
</programlisting>
You may also refer to
the Selenese
Commands Documentation which may give some hints to
writing tests.