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.
how to store/update value from field to excelsheet
Need update query for this code:-
//Get DB instance
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:doadd","","");
//run DB
$rs = db.select("select * from [Sheet1$]");
for (var $i=0; $i<3; $i++)
{
var $user = $rs[$i][0];
var $pass = $rs[$i][1];
login($user, $pass);
var $Q = $rs[$i][2];
var $Q1 = $rs[$i][3];
var $Q2 = $rs[$i][4];
var $total= $rs[$i][5];
doAdd($Q,$Q1,$Q2,$total);
try
{
_click(_button("Logout"));
}
catch(e)
{
_log("Message", "failure");
}
}
function login($user, $password)
{
_setValue(_textbox("user"), $user);
_setValue(_password("password"), $password);
_click(_submit("Login"));
}
function doAdd($q,$q1,$q2,$total)
{
_setValue(_textbox("q"), $q);
_setValue(_textbox("q[1]"), $q1);
_setValue(_textbox("q[2]"), $q2);
_click(_button("Add"));
_assertEqual($total, _textbox("total").value)
//run update
db.update("update [Sheet1$] set BOOK4 = $total");
}
if we are going to add 3 books in our user application,when we added 3 book quantity the total amount will be stored in total field.
next step,already stored total amount value should get update in excelsheet with using update query.
//Get DB instance
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:doadd","","");
//run DB
$rs = db.select("select * from [Sheet1$]");
for (var $i=0; $i<3; $i++)
{
var $user = $rs[$i][0];
var $pass = $rs[$i][1];
login($user, $pass);
var $Q = $rs[$i][2];
var $Q1 = $rs[$i][3];
var $Q2 = $rs[$i][4];
var $total= $rs[$i][5];
doAdd($Q,$Q1,$Q2,$total);
try
{
_click(_button("Logout"));
}
catch(e)
{
_log("Message", "failure");
}
}
function login($user, $password)
{
_setValue(_textbox("user"), $user);
_setValue(_password("password"), $password);
_click(_submit("Login"));
}
function doAdd($q,$q1,$q2,$total)
{
_setValue(_textbox("q"), $q);
_setValue(_textbox("q[1]"), $q1);
_setValue(_textbox("q[2]"), $q2);
_click(_button("Add"));
_assertEqual($total, _textbox("total").value)
//run update
db.update("update [Sheet1$] set BOOK4 = $total");
}
if we are going to add 3 books in our user application,when we added 3 book quantity the total amount will be stored in total field.
next step,already stored total amount value should get update in excelsheet with using update query.
Comments
Have you followed the same syntax specified in the following link,
http://sahi.co.in/w/working-with-excel-sheets
to access excel file. Check with an alert API to ensure you are able to retreive the data from excel file.
If so, when you are trying to update, there might me some error displayed on the Sahi console. Can you post that error?
Regards,
Theeran.
Starting script
_setValue(_textbox("user"), "test"); at Feb 21, 2012 2:42:34 PM
_setValue(_password("password"), "secret"); at Feb 21, 2012 2:42:34 PM
_click(_submit("Login")); at Feb 21, 2012 2:42:35 PM
_setValue(_textbox("q"), "1.0"); at Feb 21, 2012 2:42:35 PM
_setValue(_textbox("q[1]"), "1.0"); at Feb 21, 2012 2:42:35 PM
_setValue(_textbox("q[2]"), "1.0"); at Feb 21, 2012 2:42:36 PM
_click(_button("Add")); at Feb 21, 2012 2:42:36 PM
_assertEqual("null", _textbox("total").value)
Assertion Failed.
Expected:[null]
Actual:[850]
at doAdd (scripts/adddata.sah:42) at Feb 21, 2012 2:42:46 PM
_click(_button("Logout")); at Feb 21, 2012 2:42:48 PM
ERROR
TypeError: Cannot read property "0" from undefined at Feb 21, 2012 2:42:48 PM
Stopping script
It seems like the $total value is being not getting populated.
Can you post the script and error displayed on the console, not on the controller.
Regards,
Theeran.
Not in view logs, but in Sahi console.
When you start Sahi by doubleclicking on the Sahi shortcut, Sahi console opensup before sahi dashboard.
Please post the contents of that console, when you run the script.
Regards,
Theeran.