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.
Excel Data Driven Test Aid
Hi,
I have been following posting up on source forge as well as in this forum, but cannot seem to piece all the instruction which are in several topics into one solution or followable instructions.
I have also checked the getdb info up on sahi's main website for some help, but failed to understand clearly.
So, I was wondering if it would be possible for anyone to help me out as I am having difficulties understanding/setting up a simple data driven test.
Questions I had:
Do I need to change or replace anything in bin/sahi.sh file?
Do I need to change or replace anything in bin/sahi.bat file?
I have downloaded the Excel JDBC driver and placed into my C:/driver directory,
and everytime try to make a reference to it form the sahi.bat file, upon execution the window closes or crashes.
This is my sahi.bat file contents which fails upon execution:
SET EXT_CLASS_PATH=C:/driver/JDBC30.jar
#SET EXT_CLASS_PATH=%EXT_CLASS_PATH%;..\extlib\db\mysql-connector-java-5.0.4-bin.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar;..\extlib\apc\commons-codec-1.3.jar
SET MOZ_NO_REMOTE=1
java -classpath ..lib/sahi.jar;C:/driver/JDBC30.jar; net.sf.sahi.Proxy
This is my working sahi.bat file:
SET EXT_CLASS_PATH=C:/driver/JDBC30.jar
#SET EXT_CLASS_PATH=%EXT_CLASS_PATH%;..\extlib\db\mysql-connector-java-5.0.4-bin.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar;..\extlib\apc\commons-codec-1.3.jar
SET MOZ_NO_REMOTE=1
java -classpath %EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.Proxy
With the working sahi.bat file i then try to execute this code:
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver
(*.xls)};DBQ=C:/data1.xls","","");
var $rs = db.select("select * from [Sheet1$]");
var $datap =($rs[$i]["datap"]);
len=100
for(var $i=0;$i<=1;$i++)
{
_setValue(_textbox("Box"), $datap);
But an error occurs in the log which is:
JSERROR TypeError: Cannot read property "datap" from undefined
Now, im thinking the excel file is not readable this is the way I have formatted it:
first row across is: datap , jake, smith, henry, mike, linda
Also a question as to how the excel file is suppose to be formatted, is the information read across or is it read going down in the column?
I cannot change the column or rows labels so I just place in my labels into the first availabel cell , is this right?
will sahi read "datap" from cell A1 and understand its the row label ?
PLease Help
thanks
I have been following posting up on source forge as well as in this forum, but cannot seem to piece all the instruction which are in several topics into one solution or followable instructions.
I have also checked the getdb info up on sahi's main website for some help, but failed to understand clearly.
So, I was wondering if it would be possible for anyone to help me out as I am having difficulties understanding/setting up a simple data driven test.
Questions I had:
Do I need to change or replace anything in bin/sahi.sh file?
Do I need to change or replace anything in bin/sahi.bat file?
I have downloaded the Excel JDBC driver and placed into my C:/driver directory,
and everytime try to make a reference to it form the sahi.bat file, upon execution the window closes or crashes.
This is my sahi.bat file contents which fails upon execution:
SET EXT_CLASS_PATH=C:/driver/JDBC30.jar
#SET EXT_CLASS_PATH=%EXT_CLASS_PATH%;..\extlib\db\mysql-connector-java-5.0.4-bin.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar;..\extlib\apc\commons-codec-1.3.jar
SET MOZ_NO_REMOTE=1
java -classpath ..lib/sahi.jar;C:/driver/JDBC30.jar; net.sf.sahi.Proxy
This is my working sahi.bat file:
SET EXT_CLASS_PATH=C:/driver/JDBC30.jar
#SET EXT_CLASS_PATH=%EXT_CLASS_PATH%;..\extlib\db\mysql-connector-java-5.0.4-bin.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar;..\extlib\apc\commons-codec-1.3.jar
SET MOZ_NO_REMOTE=1
java -classpath %EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.Proxy
With the working sahi.bat file i then try to execute this code:
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver
(*.xls)};DBQ=C:/data1.xls","","");
var $rs = db.select("select * from [Sheet1$]");
var $datap =($rs[$i]["datap"]);
len=100
for(var $i=0;$i<=1;$i++)
{
_setValue(_textbox("Box"), $datap);
But an error occurs in the log which is:
JSERROR TypeError: Cannot read property "datap" from undefined
Now, im thinking the excel file is not readable this is the way I have formatted it:
first row across is: datap , jake, smith, henry, mike, linda
Also a question as to how the excel file is suppose to be formatted, is the information read across or is it read going down in the column?
I cannot change the column or rows labels so I just place in my labels into the first availabel cell , is this right?
will sahi read "datap" from cell A1 and understand its the row label ?
PLease Help
thanks
Comments
I havnt worked with excel drivers but try changing code to this: Regards,
Pankaj.
PS: Try explicitly declaring the variables as arrays when thay are supposed to be arrays eg $datap in this case and declare it as two dimesnsional array just like $rs.
to your comment above: I do not know where to set the $i (index) , that is pretty much my script right there, well before all of the clicks and such.
after implementation of your suggestion i get the following error:
_setGlobal('\$rs', db.select("select * from [Sheet1$]")); ReferenceError: db is not defined
Just for test purposes try running this code: Regards,
Pankaj.
I see that you have removed the loop to iterate the many columsn of information,
with the suggested changes, it seems I am now getting the following error:
JSERROR unterminated string literal
nothing is highlighted red in the log though.
I think error in your code is around :-
var $datap $rs[$i]["datap"]); // IT SHOULD BE NAME OF THE HEADER IN YOUR EXCEL SHEET.
Lets discuss in this way, suppose your data is stored in your excel sheet "data1.xls" in this way
name|age|sex //This is the table header in ur excel sheet
jack|20|male
Now use code like:-
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=D:/sahi/scripts/test2.xls","","");
var $rs = db.select("select * from [Sheet1$]");
var $data1 =($rs[$i]["name"]); //name of the column
var $data2 =($rs[$i]["age"]); //name of the column
var $data3 =($rs[$i]["sex"]); //name of the column
hope it will help you. I am able to fetch the data using excel in the same fashion.
here is hte error :
_setValue(_textbox("Seed"), "software solution");// TypeError: el is null
here is my code so far:
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver
(*.xls)};DBQ=C:/data1.xls","","");
var $rs = db.select("select * from [Sheet1$]");
var $data1 =($rs[0]["name"]); //name of the column
_setValue(_textbox("Seed"), $rs[0]["name"]);
_click(_submit("Hit Me"));
_wait(3000);
It seems to be the "_setValue(_textbox("Seed"), $rs[0]["name"]);" line which is causing the problem
any suggestions?
thanks thakurpravin and pankaj.nith for putting up with me !
now one last thing to complete this would be to get it to iterate through the list of values in the excel sheet until it finishes
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=D:/sahi/scripts/test2.xls","","");
var $rs = db.select("select * from [Sheet1$]");
var $data1 =($rs[$i]["data1"]);
var $data2 =($rs[$i]["data2"]);
len=100
for(var $i=0;$i<1;$i++)
{
_setValue(_textbox("eventCode"), $data1);
_setValue(_textbox("externalEventCode"), $data2);
}
_debugToFile(($rs[$i]["data1"])++($rs[$i]["data2"])+, "D:\\values.csv");
Try to take help from script above, it will fetch all values available in excel sheet. Hope, it will help you.
But the the $i set in the for loop is not used anywhere in the loop itself. I think you will have to rectify the loop first.
thanks for the aid so far, the code below starts off at google.ca and at the end of it it is made sure it returns back to iterate again, but the iteration does not kick in using the second value from the excel sheet.
do you see anything in the below code that I may be missing?
thanks again !
_setGlobal('\$rs', db.select("select * from [Sheet1$]")); ReferenceError: db is not defined
thakurpravin - your code seems to be working correctly with the excel sheet, but not looping through to repeat test with the rest of the variables in the sheet.
so far the script:
thanks
Thanks guys !
below is the full working code: