| Share
  1. Explore
    Introduction, screen-shots, features, limitations
  2. Getting started
    Prerequisites, download, install, browser configuration, record, playback, view logs
  3. Sahi Scripting Basics - I
    Statements, variables, functions, conditions and looping, _include
  4. Sahi Scripting Basics - II
  5. Sahi APIs (built-in functions)
    1. Browser Accessor APIs
    2. Browser Action APIs
    3. Miscellaneous APIs
  6. Sahi Scripting - Calling Java
  7. Exception handling using try-catch
  8. Recovering without try-catch using _setRecovery
  9. Data Driven Testing
    _getDB, CSV Files, Excel, Databases
  10. Multithreaded Playback (Parallel execution)
    suites, commandline, ant
  11. Advanced techniques, tips and examples
    1. HTTPS/SSL Sites
    2. Configuring an External proxy
    3. Adding jars to Sahi's classpath
  12. Other language drivers Driving Sahi from Java, Ruby etc.
    1. Java
    2. Ruby

Adding jars to Sahi's classpath ·

While interacting with databases or while calling custom java code from Sahi scripts, the necessary classes or jars need to be added to Sahi’s classpath.

From command-line

If you are using start_sahi.bat, edit start_sahi.bat and modify

SET SAHI_EXT_CLASS_PATH=

to

SET SAHI_EXT_CLASS_PATH=path/to/your/jar


Example:

SET SAHI_EXT_CLASS_PATH=..\..\extlib\db\mysql-connector-java-5.0.4-bin.jar; SET SAHI_EXT_CLASS_PATH=%SAHI_EXT_CLASS_PATH%;C:\mypath\custom.jar

In the above example, we are adding 2 jars to the classpath. Note the following

  • mysql-connector-java-5.0.4-bin.jar is the mysql jdbc driver which has been copied to sahi/extlib/db directory. custom.jar is in C:\mypath.
  • You can keep your jar anywhere and use its absolute path or a path relative to where you start Sahi from.
  • SAHI_EXT_CLASS_PATH is where you add your database drivers.
  • On linux use : (colon) instead of ; (semi-colon) to separate jars in the classpath

From ant

If you are using ant, use:

<target name="startsahi" description="starts proxy">
  <java classname="net.sf.sahi.Proxy" fork="true">
    <classpath>
      <path path="classes"/>
      <pathelement location="extlib/rhino/js.jar"/>
      <pathelement location="extlib/apc/commons-codec-1.3.jar"/>
      <pathelement location="extlib/db/mysql-connector-java-5.0.4-bin.jar"/>
      <pathelement location="C:/mypath/custom.jar"/>
    </classpath>
    <arg value="." id="basePath"/>
    <arg value="./userdata/" id="userdataPath"/>
  </java>
</target>

Make sure to change the pathelement locations properly. (Relative to where you are running the target from.)




---