18 January 2026:


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 testing

shashishashi Members
edited November -1 in Sahi - Open Source
Hi all,
i am doing database testing using sahi tool. it is showing failure. i am not able to rectify this problem. i have written the code to connect to database is:

var db = _getDB("com.mysql.jdbc.Drive",
"jdbc:mysql://localhost:3306/demo",
"root", "!root");
var $rs = db.select("select * from test");

i am working on ubuntu and browser is firefox. i am using mysql databse.
i have added the .jar file in start_sahi.sh file.
it is like export SAHI_EXT_CLASS_PATH=/home/Desktop/mysql-connector-java-5.0.4-bin.jar;
but i am not able to execute it successfully.

Comments

  • narayannarayan Administrators
    Check the Sahi console (shell from where you ran start_sahi.sh). It will show you the error. (In this case you have used Drive instead of Driver)

    Regards,
    Narayan
  • shashishashi Members
    Hi Narayan,
    i wrote "drive" by mistake. i changed this, but still i am not able to run. i tell u, i have added mysql connector .jar file path in start_sahi.sh file. This file comes in sahi/userdata/bin folder.


    Here i have posted a small scenario login and logout .

    function checkDiscount()
    {

    _setValue(_textbox("user_name"), "shasi");
    _setValue(_password("user_password"), "!shasi");
    _click(_imageSubmitButton("Login [Alt+L]"));
    _click(_link("Marketing"));

    _click(_link("Accounts"));
    _click(_image("Create Account..."));
    _setValue(_textbox("accountname"), "raj");
    _click(_span("admin chenna gyan kapil shasi standarduser"));
    _setSelected(_select("assigned_user_id"), "admin");
    _setValue(_textbox("accountname"), "raj1");
    _click(_button(" Save "));
    _click(_link("Sign Out"));
    var db = _getDB("com.mysql.jdbc.Driver",
    "jdbc:mysql://192.168.1.83:3306/demo",
    "root", "!root");
    var $rs = db.select("select * from test");

    }
    checkDiscount();



    and second one is without function

    _setValue(_textbox("user_name"), "chenna");
    _setValue(_password("user_password"), "!chenna");
    _click(_imageSubmitButton("Login [Alt+L]"));
    _click(_link("Marketing"));
    _click(_link("Sign Out"));
    var db = _getDB("com.mysql.jdbc.Driver",
    "jdbc:mysql://localhost/demo",
    "root", "!root");
    var $rs = db.select("select * from test");


    In both cases, it is executing till sign out operation after that it is showing stopped playback failure. not able to run var db........
  • narayannarayan Administrators
    You will have to post the errors visible on the Sahi console, and the failure message in your logs.

    A friendly suggestion: when you post on public forums, people spend time on your problem to help you (I just did). If you make mistakes or provide incorrect/incomplete information, you are essentially turning away people from helping you because they feel they have wasted time in trying to help you. Please do be more complete in the future.

    Regards,
    Narayan
  • shashishashi Members
    Hi narayan,
    Sorry for the mistake done, will keep that in mind.Thank you for your valuable advice.

    This is the error, i am getting in console

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at net.sf.sahi.util.ClassLoadHelper.getClass(ClassLoadHelper.java:24)
    at net.sf.sahi.plugin.DBClient.getResult(DBClient.java:95)
    at net.sf.sahi.plugin.DBClient.select(DBClient.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
    at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:86)
    at org.mozilla.javascript.gen.c1._c56(<cmd>:462)
    at org.mozilla.javascript.gen.c1.call(<cmd>)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
    at org.mozilla.javascript.gen.c2._c1(<cmd>:21)
    at org.mozilla.javascript.gen.c2.call(<cmd>)
    at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
    at org.mozilla.javascript.gen.c2._c0(<cmd>:24)
    at org.mozilla.javascript.gen.c2.call(<cmd>)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
    at org.mozilla.javascript.gen.c2.call(<cmd>)
    at org.mozilla.javascript.gen.c2.exec(<cmd>)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1088)
    at net.sf.sahi.rhino.RhinoScriptRunner.run(RhinoScriptRunner.java:92)
    at java.lang.Thread.run(Thread.java:636)

    And this is the error message showing in log file.

    Starting script
    _setValue(_textbox("user_name"), "chenna"); at 5 Jun, 2010 1:06:25 PM
    _setValue(_password("user_password"), "!chenna"); at 5 Jun, 2010 1:06:25 PM
    _click(_imageSubmitButton("Login [Alt+L]")); at 5 Jun, 2010 1:06:25 PM
    _click(_link("Marketing")); at 5 Jun, 2010 1:06:27 PM
    _click(_link("Accounts")); at 5 Jun, 2010 1:06:29 PM
    _click(_image("Create Account...")); at 5 Jun, 2010 1:06:30 PM
    _setValue(_textbox("accountname"), "raj"); at 5 Jun, 2010 1:06:32 PM
    _click(_span("admin chenna gyan kapil shasi standarduser")); at 5 Jun, 2010 1:06:32 PM
    _setSelected(_select("assigned_user_id"), "admin"); at 5 Jun, 2010 1:06:32 PM
    _setValue(_textbox("accountname"), "raj1"); at 5 Jun, 2010 1:06:32 PM
    _click(_button(" Save ")); at 5 Jun, 2010 1:06:32 PM
    _click(_link("Sign Out")); at 5 Jun, 2010 1:06:33 PM
    JSERROR
    SyntaxError: syntax error at 5 Jun, 2010 1:06:33 PM
    Stopping script
  • narayannarayan Administrators
    Hi Shashi,

    The problem still looks like a classpath issue. I can only think of a couple of reasons:
    1) The file is not at /home/Desktop/mysql-connector-java-5.0.4-bin.jar
    2) The file is there but is corrupt

    Can you try directly modifying sahi/bin/sahi.sh and change the last line from

    java -classpath $SAHI_EXT_CLASS_PATH:$SAHI_CLASS_PATH net.sf.sahi.Proxy "$SAHI_HOME" "$SAHI_USERDATA_DIR_TMP"

    to

    java -classpath /home/Desktop/mysql-connector-java-5.0.4-bin.jar:$SAHI_CLASS_PATH net.sf.sahi.Proxy "$SAHI_HOME" "$SAHI_USERDATA_DIR_TMP"

    and then check again?

    Regards,
    Narayan
  • shashishashi Members
    Hi Narayan,
    Thanks for your support. Now, it is working fine.

    Thank you
This discussion has been closed.