Top Rounds
|
  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
  13. Sahi Pro

Sahi Java Driver ·

The Sahi Java Driver can be used to write Java unit tests and functional tests for web applications.

The Sahi Java Driver is bundled with Sahi’s releases and has been available since 2nd Sep 2009. We are thankful to ThoughtWorks for partially funding its development.

A brief example on the usage is provided below:

.
  import net.sf.sahi.client.Browser;
  import net.sf.sahi.config.Configuration;

  public class SahiDriverDemo {
    public static void main(String[] args) {
      String sahiBase = "../"; // where Sahi is installed or unzipped
      String userDataDirectory = "../userdata"; //path to the userdata directory
      Configuration.initJava(sahiBase, userDataDirectory); // Sets up configuration for proxy. Sets Controller to java mode.

      String browserPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
      String browserProcessName = "firefox.exe";
      String browserOption = "-profile $userDir/browser/ff/profiles/sahi0 -no-remote";

  // UNCOMMENT for your preferred browser.    

  //  String browserPath = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
  //  String browserProcessName = "iexplore.exe";
  //  String browserOption = "-noframemerging -extoff"; 
  // Set browserOption to "-noframemerging -extoff" for IE 8, "" for IE 7

  //  String browserPath = "C:\\Documents and Settings\\Narayan Raman\\Local Settings" + 
                      "\\Application Data\\Google\\Chrome\\Application\\chrome.exe";
  //  String browserProcessName = "chrome.exe";
  //  String browserOption = 
  //           "--user-data-dir=$userDir\\browser\\chrome\\profiles\\sahi$threadNo" + 
  //           " --proxy-server=localhost:9999 --disable-popup-blocking";    

  //  String browserPath = "C:\\Program Files\\Safari\\Safari.exe";
  //  String browserProcessName = "Safari.exe";
  //  String browserOption = "";            

      // Create a browser and open it
      Browser browser = new Browser(browserPath, browserProcessName, browserOption);    
      browser.open();

      browser.navigateTo("http://www.google.com");
      browser.textbox("q").setValue("sahi forums");
      browser.submit("Google Search").click();
      browser.link("Sahi - Web Automation and Test Tool").click();    
      browser.link("Login").click();
      System.out.println("Check: " + browser.textbox("req_username").exists());

      // close the browser
      browser.close();

    }  

  }

There is a sample Eclipse project available in sahi/sample_java_project. One needs to use the correct path for sahi.jar (or copy it into sahi/sample_java_project/lib from sahi/lib). More detailed examples are available in DriverClientTest.java which is in sahi/sample_java_project

Full documentation is available as Javadocs

Make sure that the proxy settings are properly configured on the browser (not needed for firefox) and that the Sahi proxy is running. Have a look at Using Sahi for details on configuring the browser and starting the proxy.

Recording Java code

  1. Open sahi/config/sahi.properties and set controller.mode=java
  2. Restart Sahi
  3. Open a fresh browser with the proxy configured and navigate to any website.
  4. Press CTRL-ALT and DblClick on the page to bring up the Sahi Java Controller.
  5. Click on the record button and start performing actions on the browser. Steps will be visible in the “Recorded Steps” section.
  6. Copy the code from the Sahi console and paste it into your class.



---


Top Rounds