18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Can anyone please correct the error message indicated for the script given below.
Can anyone please correct the error message indicated for the script given below.
Start URL
========
http://sahi.co.in/demo/training/
ERROR MESSAGE
===============
ERROR
identifier is a reserved word at Oct 16, 2013 11:01:51 AM
public static String encode (String source) {
Script
=====
_setValue(_textbox("user"), "test");
_setValue(_password("password"), "secret");
_click(_submit("Login"));
_setValue(_textbox("q"), "2");
_setValue(_textbox("q[1]"), "1");
_setValue(_textbox("q[2]"), "1");
_click(_button("Add"));
_assertExists(_textbox("total"));
_assert(_isVisible(_textbox("total")));
_assertEqual("1150", _textbox("total").value);
_click(_button("Logout"));
// onScriptEnd is a callback called by Sahi when script finishes
function onScriptEnd(){
postTestuff("atest_id", _scriptStatus());
}
public static String encode (String source) {
BASE64Encoder enc = new sun.misc.BASE64Encoder();
return(enc.encode(source.getBytes()));
}
function postTestuff(test_id, status, comment,
tester_name, branch_name, lab_name){
try {
// comment this line later;
_sahi.print(status);
// Construct data
var data = "test_id=" + encodeURIComponent(test_id);
data += "&status=" + encodeURIComponent(status);
if (comment) data += "&comment=" + encodeURIComponent(comment);
if (tester_name) data += "&tester_name=" + encodeURIComponent(tester_name);
if (branch_name) data += "&branch_name=" + encodeURIComponent(branch_name);
if (lab_name) data += "&lab_name=" + encodeURIComponent(lab_name);
// Send data
var strUrl = "https://serviceX.testuff.com/api/v0/"
var url = new java.net.URL(strUrl);
var conn = url.openConnection();
var name = "testuff_login_email";
var password = "password";
conn.setRequestProperty ("Authorization", "Basic " + encode(name + ":" + password));
conn.setDoOutput(true);
conn.setDoInput(true);
var wr = new java.io.OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
// comment this line later;
_sahi.print(conn.getResponseCode());
conn.disconnect();
} catch (e) {
_sahi.print(e);
}
}
Error I am getting:
============
ERROR
identifier is a reserved word at Oct 16, 2013 11:01:51 AM
Start URL
========
http://sahi.co.in/demo/training/
ERROR MESSAGE
===============
ERROR
identifier is a reserved word at Oct 16, 2013 11:01:51 AM
public static String encode (String source) {
Script
=====
_setValue(_textbox("user"), "test");
_setValue(_password("password"), "secret");
_click(_submit("Login"));
_setValue(_textbox("q"), "2");
_setValue(_textbox("q[1]"), "1");
_setValue(_textbox("q[2]"), "1");
_click(_button("Add"));
_assertExists(_textbox("total"));
_assert(_isVisible(_textbox("total")));
_assertEqual("1150", _textbox("total").value);
_click(_button("Logout"));
// onScriptEnd is a callback called by Sahi when script finishes
function onScriptEnd(){
postTestuff("atest_id", _scriptStatus());
}
public static String encode (String source) {
BASE64Encoder enc = new sun.misc.BASE64Encoder();
return(enc.encode(source.getBytes()));
}
function postTestuff(test_id, status, comment,
tester_name, branch_name, lab_name){
try {
// comment this line later;
_sahi.print(status);
// Construct data
var data = "test_id=" + encodeURIComponent(test_id);
data += "&status=" + encodeURIComponent(status);
if (comment) data += "&comment=" + encodeURIComponent(comment);
if (tester_name) data += "&tester_name=" + encodeURIComponent(tester_name);
if (branch_name) data += "&branch_name=" + encodeURIComponent(branch_name);
if (lab_name) data += "&lab_name=" + encodeURIComponent(lab_name);
// Send data
var strUrl = "https://serviceX.testuff.com/api/v0/"
var url = new java.net.URL(strUrl);
var conn = url.openConnection();
var name = "testuff_login_email";
var password = "password";
conn.setRequestProperty ("Authorization", "Basic " + encode(name + ":" + password));
conn.setDoOutput(true);
conn.setDoInput(true);
var wr = new java.io.OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
// comment this line later;
_sahi.print(conn.getResponseCode());
conn.disconnect();
} catch (e) {
_sahi.print(e);
}
}
Error I am getting:
============
ERROR
identifier is a reserved word at Oct 16, 2013 11:01:51 AM
Answers
Please change the name of the function 'encode' to 'encoder' and try.
Regards.
I changed the name of the function from encode to encoder but still I am getting the same error.
I am following the following procedure.
1.Open Firefox browser from SAHI Dashboard.In the start url I gave
http://sahi.co.in/demo/training/
2.From the controller I entered testuff.sah and start url http://sahi.co.in/demo/training/
3.Then I clicked on Set.
4.Then I clicked on Play.
Regards
Uday
I am sorry I missed the issue last time. The sample code for testuff that you're using seems to be a problem as you're using Java syntax in the Sahi script (in the encode function). SahiScript wouldn't understand that.
Regards.
Thanks very much for your reply.
regards
Uday