<?xml version='1.0' ?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [ 
]>

<sect1 id="selenium">
  <title>Using Selenium Remote Control</title>
  <authorblurb>
    <para>by <ulink url="mailto:dave@solutiongrove.com">Dave
    Bauer</ulink></para>
  </authorblurb>
  <para>
    To use Selenium Remote Control to run browser-based tested from
    acs-automated-testing first install Selenium Remote
    Control. <ulink url="http://seleniumhq.org/download/">Download
      Selenium RC</ulink>. This requires a working Java
    configuration. See <ulink url="http://seleniumhq.org/docs/05_selenium_rc.html">Selenium
      RC Documentation</ulink> and specifically <ulink url="
                                                            http://seleniumhq.org/docs/05_selenium_rc.html#installation">Selenium
      RC Installation</ulink>.
  </para>
  <para>
  You can record tests to Tcl code that will run in
  acs-automated-testing by adding the a Tcl-RC mode in Selenium-IDE.
</para>
<para>
  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.
  <programlisting>
/*
 * Format for Selenium Remote Control Python client.
 */

load('remoteControl.js');

this.name = &quot;tcl-rc&quot;;

function testMethodName(testName) {
	return &quot;test_&quot; + underscore(testName);
}

notOperator = function() {
	return &quot;! &quot;;
}

tclString = function(value) {
	value = value.replace(/\\/g, '\\\\');
	value = value.replace(/\&quot;/g, '\\&quot;');
	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 &lt; value.length; i++) {
		if (value.charCodeAt(i) &gt;= 128) {
			unicode = true;
		}
	}
	return (unicode ? 'u' : '') + '&quot;' + value + '&quot;';
}

function assertTrue(expression) {
	return &quot;aa_true &quot; + tclString(expression.toString()) + &quot; [expr {![catch {&quot; + expression.toString() + &quot;} errmsg]}]&quot;;
}

function assertFalse(expression) {
	return &quot;aa_false &quot; + tclString(expression.toString()) + &quot; [expr {![catch {&quot; + expression.toString() + &quot;} errmsg]}]&quot;;
}

function verify(statement) {
        return statement;
}

function verifyTrue(expression) {
	return verify(assertTrue(expression));
}

function verifyFalse(expression) {
	return verify(assertFalse(expression));
}

function joinExpression(expression) {
    return &quot;join &quot; + expression.toString();
}

function assignToVariable(type, variable, expression) {
	return &quot;set &quot; + underscore(variable) + &quot; [&quot; + expression.toString() + &quot;]&quot;;
}

function waitFor(expression) {
    return &quot;for {set i 0} {i &lt; &quot; + expression.toString() + &quot;} {incr i} {\n&quot;
        + &quot;if {&quot; + expression.toString() + &quot;} {break}\n&quot;
        + &quot;after 1000\n&quot;
        + &quot;}\n&quot;
        + &quot;if {$i == 60} {error \&quot;time out\&quot;}&quot;;
}

function assertOrVerifyFailure(line, isAssert) {
    return &quot;&quot; + line + &quot;} errmsg]} {error \&quot;expected failure\&quot;}&quot;;
}

Equals.prototype.toString = function() {
	return this.e1.toString() + &quot; eq &quot; + 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() + &quot; ne &quot; + this.e2.toString();
}

NotEquals.prototype.assert = function() {
	return &quot;aa_true &quot; + tclString(this.e1.toString() + &quot; ne &quot; + this.e2.toString()) + &quot; [expr {&quot; + this.e1.toString() + &quot; ne &quot; + this.e2.toString() + &quot;}]&quot;;
}

NotEquals.prototype.verify = function() {
	return verify(this.assert());
}

RegexpMatch.prototype.toString = function() {
	var str = this.pattern;
	if (str.match(/\&quot;/) || str.match(/\n/)) {
		str = str.replace(/\\/g, &quot;\\\\&quot;);
		str = str.replace(/\&quot;/g, '\\&quot;');
		str = str.replace(/\n/g, '\\n');
		return '&quot;' + str + '&quot;';
	} else {
		str = 'r&quot;' + str + '&quot;';
	}
	return &quot;re.search(&quot; + str + &quot;, &quot; + this.expression + &quot;)&quot;;
}

function pause(milliseconds) {
	return &quot;after &quot; + milliseconds;
}

function echo(message) {
        return &quot;aa_log &quot; + xlateArgument(message);
}

function statement(expression) {
	return expression.toString();
}

function array(value) {
	var str = '[lst ';
	for (var i = 0; i &lt; value.length; i++) {
		str += string(value[i]);
		if (i &lt; value.length - 1) str += &quot; &quot;;
	}
	str += ']';
	return str;
}

function nonBreakingSpace() {
    return &quot;u\&quot;\\u00a0\&quot;&quot;;
}

CallSelenium.prototype.toString = function() {
	var result = '';
	if (this.negative) {
		result += '! ';
	}
	if (options.receiver) {
		result += options.receiver + ' ';
	}
	result += this.message + ' ';
	for (var i = 0; i &lt; this.args.length; i++) {
		result += this.args[i];
		if (i &lt; this.args.length - 1) {
			result += ' ';
		}
	}
	return result;
}

function formatComment(comment) {
	return comment.comment.replace(/.+/mg, function(str) {
			return &quot;# &quot; + str;
		});
}

this.options = {
	header:'',
	footer:''
};


this.configForm =
	'&lt;description&gt;Variable for Selenium instance&lt;/description&gt;' +
	'&lt;description&gt;Header&lt;/description&gt;' +
	'&lt;textbox id=&quot;options_header&quot; multiline=&quot;true&quot; flex=&quot;1&quot; rows=&quot;4&quot;/&gt;' +
	'&lt;description&gt;Footer&lt;/description&gt;' +
	'&lt;textbox id=&quot;options_footer&quot; multiline=&quot;true&quot; flex=&quot;1&quot; rows=&quot;4&quot;/&gt;';
      </programlisting>
    </para>
    <para>
      You may also refer to
      the <ulink url="http://seleniumhq.org/docs/04_selenese_commands.html">Selenese
      Commands Documentation</ulink> which may give some hints to
      writing tests.
    </para>
</sect1>
