Search code examples
javamavensahi

java.lang.NullPointerException at net.sf.sahi.config.Configuration.getUserProperty


Here is my code. Cant figure out why i am getting the exception.

import net.sf.sahi.client.Browser;
import org.testng.Assert;
import org.testng.annotations.Test;


public class browser {


@Test
public void function2(){
    System.out.println("Starting");
    String browserName = "firefox"; // default values are "ie", "firefox", "safari", "chrome", "opera" - specified in userdata/config/browser_types.xml
    Browser browser = new Browser(browserName);
    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();
    Assert.assertTrue(browser.textbox("req_username").exists());

    browser.close();

    System.out.println("Ending");
}
}


 import org.testng.annotations.Test;

 public class trial {

 @Test
 public void function2(){
    browser.function1();
   }
 }

My pom.xml looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>rashmi</groupId>
<artifactId>sahi</artifactId>
<version>1.0-SNAPSHOT</version>


    <repositories>
        <repository>
            <id>clojars</id>
            <name>Clojars Repository</name>
            <url>http://clojars.org/repo</url>
        </repository>
    </repositories>
    <dependencies>

        <dependency>
            <groupId>sahi</groupId>
            <artifactId>sahi</artifactId>
            <version>3.5</version>
        </dependency>

        <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.8</version>
    </dependency>
</dependencies>

</project>

When I right click on my test and run it the exception I am getting is as follows:

  java.lang.NullPointerException
          at net.sf.sahi.config.Configuration.getUserProperty(Configuration.java:694)
at net.sf.sahi.config.Configuration.getCommonDomain(Configuration.java:780)
at net.sf.sahi.client.Browser.openURL(Browser.java:265)
at net.sf.sahi.client.Browser.open(Browser.java:241)
at browser.function1(browser.java:15)
at trial.function2(trial.java:12)

Can somebody please help me figure out why I am getting the exception?


Solution

  • As the javadoc of Browser shows, the following should be done first, before open.

    String sahiBasePath = "D:\\path\\to\\sahi_dir";
    Sting userDataDirectory = "D:\\path\\to\\userdata_dir";
    
    net.sf.sahi.config.Configuration.initJava(sahiBasePath, userDataDirectory);