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.

Writing java code by using Proxy and TestRunner class

treetree Members
edited January 2013 in Sahi - Open Source
Hello, i want to use the java code to run the sahi proxy server and run the TestRunner
these code:
String sahiBasePath = "C:\\Users\\user\\sahi";
String userDataDirectory = "C:\\Users\\user\\sahi\\userdata";

net.sf.sahi.config.Configuration.initJava(sahiBasePath, userDataDirectory);

final Proxy proxy = new Proxy(Configuration.getPort());
currentInstance = proxy;
proxy.start(true);

String suiteName = "C:\\Users\\user\\sahi\\userdata\\scripts\\test.sah";
String browserType = "firefox";
String base_url = "http://demo.libreplan.org/libreplan/common/layout/login.zul";
String threads = "5";

TestRunner testRunner =
new TestRunner(suiteName, browserType, base_url, threads);

HashMap<String, Object> variableHashMap = new HashMap<String, Object>();
testRunner.setInitJS(variableHashMap);
String status = testRunner.execute();
but these error :

Exception in thread "main" 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.test.TestRunner.execute(TestRunner.java:328)
at net.sf.sahi.test.TestRunner.execute(TestRunner.java:310)
at test.testLauncher.main(testLauncher.java:41)


could you help me? thank you!!

Answers

  • treetree Members
    i add the one line code : Thread.sleep(300);
    like:
    proxy.start(true);
    Thread.sleep(300);
    ....

    its works!!
    but is the best solve?
Sign In or Register to comment.