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.

connection refused issue while running sahi java code

nithinsn14nithinsn14 Members
edited January 2013 in Sahi - Open Source
i am getting connection refused error when i run below code . Please help me

Below is my code :

package xyz;
import net.sf.sahi.client.Browser;
import net.sf.sahi.config.Configuration;
public class Testsahi {
public static void main(String[] args) {
String sahiBase = "D:/workingspace/PC_product/sahi"; // where Sahi is unzipped
String userDataDirectory = "D:/workingspace/PC_product/sahi/userdata"; //path to the userdata directory
Configuration.initJava(sahiBase, userDataDirectory);
// Sets up configuration for proxy. Sets Controller to java mode.
String browserType = "firefox";
// Create a browser and open it
Browser browser = new Browser(browserType);
browser.open();
browser.navigateTo("http://www.google.com";);
browser.close();
}
}

Error:

Sahi properties file = D:\workingspace\PC_product\sahi\config\sahi.properties
Sahi user properties file = D:\workingspace\PC_product\sahi\userdata\config\userdata.properties
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at net.sf.sahi.util.Utils.readURL(Utils.java:129)
at net.sf.sahi.util.Utils.readURL(Utils.java:111)
at net.sf.sahi.client.Browser.execCommand(Browser.java:154)
at net.sf.sahi.client.Browser.openURL(Browser.java:266)
at net.sf.sahi.client.Browser.open(Browser.java:241)
at sdis.Testsahi.main(Testsahi.java:25)
java.lang.NullPointerException
at net.sf.sahi.util.Utils.readURL(Utils.java:137)
at net.sf.sahi.util.Utils.readURL(Utils.java:111)
at net.sf.sahi.client.Browser.execCommand(Browser.java:154)
at net.sf.sahi.client.Browser.openURL(Browser.java:266)
at net.sf.sahi.client.Browser.open(Browser.java:241)
at sdis.Testsahi.main(Testsahi.java:25)
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at net.sf.sahi.client.Browser.execCommand(Browser.java:154)
at net.sf.sahi.client.Browser.openURL(Browser.java:266)
at net.sf.sahi.client.Browser.open(Browser.java:241)
at sdis.Testsahi.main(Testsahi.java:25)

Answers

  • Pratyush_TytoPratyush_Tyto Members
    edited June 2013
    Hi Nithin,
    The Sahi proxy should be running on port 9999 before you run the Java code.
    ie. the dashboard should be launched before you run the code.

    Regards.
Sign In or Register to comment.