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.
Database troubles
Hi,
I am really struggling to access our database with sahi, and I really need to get some data driven testing done.
I've tried the examples I've found and cannot seem to get them working.
Just trying a simple database call to get a user Id. Sahi spits out an error but i think its because the result set if null so i guess its not connecting to the db???
Test:
var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/sahi_data", "sahi", "sahi");
var $rs = [];
_set($rs, db.select("select userId from users"));
_alert($rs[0][0]);
sahi.bat:
SET EXT_CLASS_PATH=..\extlib\db\mysql-connector-java-5.1.6-bin.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar
SET MOZ_NO_REMOTE=1
java -classpath %SAHI_CLASS_PATH%;%EXT_CLASS_PATH% net.sf.sahi.Proxy
Sahi (Build: 2008-08-31)
Output:
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
--Stopped Playback: FAILURE--
Error:
{sahi_paused=0, sahi_retries=0, this.ix=0, sahi_play=0, sahi_has_errors=0}
org.mozilla.javascript.EcmaError: TypeError: Cannot read property "0.0" from nul
l (<cmd>#274)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3226)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3216)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:323
2)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:32
51)
at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.jav
a:3264)
at org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java
:1283)
at org.mozilla.javascript.gen.c4._c0(<cmd>:274)
at org.mozilla.javascript.gen.c4.call(<cmd>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:3
37)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:275
5)
at org.mozilla.javascript.gen.c4.call(<cmd>)
at org.mozilla.javascript.gen.c4.exec(<cmd>)
at org.mozilla.javascript.Context.evaluateString(Context.java:1144)
at net.sf.sahi.rhino.ScriptRunner.run(ScriptRunner.java:52)
at java.lang.Thread.run(Unknown Source)
Thank
Andy
I am really struggling to access our database with sahi, and I really need to get some data driven testing done.
I've tried the examples I've found and cannot seem to get them working.
Just trying a simple database call to get a user Id. Sahi spits out an error but i think its because the result set if null so i guess its not connecting to the db???
Test:
var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/sahi_data", "sahi", "sahi");
var $rs = [];
_set($rs, db.select("select userId from users"));
_alert($rs[0][0]);
sahi.bat:
SET EXT_CLASS_PATH=..\extlib\db\mysql-connector-java-5.1.6-bin.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar
SET MOZ_NO_REMOTE=1
java -classpath %SAHI_CLASS_PATH%;%EXT_CLASS_PATH% net.sf.sahi.Proxy
Sahi (Build: 2008-08-31)
Output:
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
_setGlobal('\$rs', db.select("select userId from users"));
--Stopped Playback: FAILURE--
Error:
{sahi_paused=0, sahi_retries=0, this.ix=0, sahi_play=0, sahi_has_errors=0}
org.mozilla.javascript.EcmaError: TypeError: Cannot read property "0.0" from nul
l (<cmd>#274)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3226)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3216)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:323
2)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:32
51)
at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.jav
a:3264)
at org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java
:1283)
at org.mozilla.javascript.gen.c4._c0(<cmd>:274)
at org.mozilla.javascript.gen.c4.call(<cmd>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:3
37)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:275
5)
at org.mozilla.javascript.gen.c4.call(<cmd>)
at org.mozilla.javascript.gen.c4.exec(<cmd>)
at org.mozilla.javascript.Context.evaluateString(Context.java:1144)
at net.sf.sahi.rhino.ScriptRunner.run(ScriptRunner.java:52)
at java.lang.Thread.run(Unknown Source)
Thank
Andy
Comments
Try using this:: Also ensure that the paths are properly set.
Regards,
Pankaj.
No luck though, it must be the way I've defined the class path.
SET EXT_CLASS_PATH=..\extlib\db\mysql-connector-java.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar
SET MOZ_NO_REMOTE=1
java -classpath %SAHI_CLASS_PATH%;%EXT_CLASS_PATH% net.sf.sahi.Proxy
C:\Users\Andy Liddle\CTEProjects\CTE_Sahi\bin>java -classpath ..\lib\sahi.jar;..
\extlib\rhino\js.jar;..\extlib\db\mysql-connector-java.jar net.sf.sahi.Proxy
Try fiddling with the path...
I get an "undefined" in my alert box.
Try using
_alert($rs[0]["FIELDNAME"]); //whatever is the fieldname in your database table
instead of using the indexes.
Pankaj.
That actually worked.
Cheers