/*
* Format for Selenium Remote Control ABAP client.
*/
load('remoteControl.js');
this.name = "abap-rc";
function testMethodName(testName) {
return "test_" + testName;
}
notOperator = function() {
return "not ";
}
string = 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, '\'\'');
return '\'' + value + '\'';
}
function assertTrue(expression) {
return "lv_act = " + expression.toString() + ".\n" +
"if lv_act <> 'X'.\n" +
" cl_aunit_assert=>fail( ).\n" +
"endif.";
}
function assertFalse(expression) {
return "self.failIf(" + expression.toString() + ")";
}
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 variable + " = " + expression.toString();
}
function waitFor(expression) {
return "for i in range(60):\n" +
indents(1) + "try:\n" +
indents(2) + "if " + expression.toString() + ": break\n" +
indents(1) + "except: pass\n" +
indents(1) + 'time.sleep(1)\n' +
'else: self.fail("time out")';
}
function assertOrVerifyFailure(line, isAssert) {
return "try: " + line + "\n" +
"except: pass\n" +
'else: self.fail("expected failure")';
}
Equals.prototype.toString = function() {
return this.e1.toString() + " == " + this.e2.toString();
}
Equals.prototype.assert = function() {
return "\" This assignment is needed for assertions which return a value only WebAS ABAP > 7.01 allow method chaining\n" +
"lv_act = " + this.e2.toString() + ".\n" +
"cl_aunit_assert=>assert_equals( exp = " + this.e1.toString() + " act = lv_act ).";
}
Equals.prototype.verify = function() {
return verify(this.assert());
}
NotEquals.prototype.toString = function() {
return this.e1.toString() + " != " + this.e2.toString();
}
NotEquals.prototype.assert = function() {
return "self.assertNotEqual(" + this.e1.toString() + ", " + 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 "wait up to " + (parseInt(milliseconds) / 1000) + " seconds.";
}
function echo(message) {
return "write: / " + xlateArgument(message);
}
function statement(expression) {
return expression.toString() + '.';
}
function array(value) {
var str = 'DATA: lt_arr TYPE string_table.\n';
for (var i = 0; i < value.length; i++) {
str += 'APPEND ' + string(value[i]) + ' TO lt_arr';
if (i < value.length - 1) str += ".\n";
}
return str;
}
function nonBreakingSpace() {
return "u\"\\u00a0\"";
}
CallSelenium.prototype.toString = function() {
var result = '';
if (this.negative) {
result += 'not ';
}
if (options.receiver) {
result += options.receiver + '->';
}
result += this.message;
result += '( ';
for (var i = 0; i < this.args.length; i++) {
// Until I know how the parameter names can be dynamically added we have this dirty hack
if ( i == 0 && this.args.length == 2) {
result += 'locator = ';
}
if ( i == 1 ) {
result += ' value = ';
}
result += this.args[i];
if (i < this.args.length - 1) {
result += ' ';
}
}
result += ')';
return result;
}
function formatComment(comment) {
return comment.comment.replace(/.+/mg, function(str) {
return "* " + str;
});
}
this.options = {
receiver: "sc",
header:
'report z${className}.\n' +
'\n' +
'class z${className} definition for testing\n' +
' "#AU Risk_Level Harmless\n' +
' "#AU Duration Long\n' +
' .\n' +
' public section.\n' +
' protected section.\n' +
' private section.\n' +
' data:\n' +
' sc type ref to zcl_selenium_client. "#EC NOTEXT\n' +
' \n' +
' methods: setup.\n' +
' methods: teardown.\n' +
' methods: ${methodName} FOR TESTING.\n' +
' endclass.\n' +
' \n' +
' class z${className} implementation.\n' +
' method setup.\n' +
' TRY.\n' +
' create object sc\n' +
' exporting\n' +
' host = \'localhost\'\n' +
' browserstartcommand = \'*firefox\'\n' +
' browserurl = \'http://insert-host:andport/\'.\n' +
' sc->start( ).\n' +
' CATCH zcx_selenium_error INTO oref.\n' +
' error = oref->get_text( ).\n' +
' cl_aunit_assert=>fail( error ).\n' +
' ENDTRY.\n' +
' endmethod.\n' +
' \n' +
' method ${methodName}.\n' +
' DATA: lv_act TYPE string. " This variable is needed for assertions which return a value only WebAS ABAP > 7.01 allow method chaining\n' +
' TRY.\n',
footer:
' CATCH zcx_selenium_error INTO oref.\n' +
' error = oref->get_text( ).\n' +
' cl_aunit_assert=>fail( error ).\n' +
' ENDTRY.\n' +
' endmethod.\n' +
' method teardown.\n' +
' TRY.\n' +
' sc->stop( ).\n' +
' CATCH zcx_selenium_error INTO oref.\n' +
' error = oref->get_text( ).\n' +
' cl_aunit_assert=>fail( error ).\n' +
' ENDTRY.\n' +
' endmethod.\n' +
'endclass.\n',
indent: '4',
initialIndents: '2'
};
this.configForm =
'Variable for Selenium instance' +
'' +
'Header' +
'' +
'Footer' +
'' +
'Indent' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'';