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.

Start sahi proxy (dashboard) from java environment

aak_polaak_pol Members
edited November -1 in Sahi - Open Source
We would like to start Sahi dashboard from within our Java code to integrate sahi with our existing test automation framework.

I found that I can call Dashboard.main() method from the Java code which will start the dashboard but it requires two arguments passed to it. These are "Sahi Home" and "Sahi User Data Dir".
Rather than using the whole directories, I want to know, which files are required to start the Sahi dashboard so that I can keep the Sahi folder to the minimum size.

So my question is-
What exact files and folders are required to start sahi dashboard using Dashboard.main(...) method.

Thanks,
Aakash

Comments

  • Hi aak_pol,

    Please look in to windows batch commands which starts Sahi,
    
    set SAHI_HOME=C:\user\sahi
    
    set SAHI_USERDATA_DIR_TMP =%SAHI_HOME%\userdata
    
    set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar;%SAHI_HOME%\extlib\db\h2.jar;%SAHI_HOME%\extlib\license\truelicense.jar;%SAHI_HOME%\extlib\license\truexml.jar;
    
    java -classpath %SAHI_CLASS_PATH% net.sf.sahi.ui.Dashboard "%SAHI_HOME%" "%SAHI_USERDATA_DIR_TMP%"
    

    In the above example, we are considering that Sahi is installed at "C:\user\sahi"

    Regards
    Sumitra
  • For the same purpose I am using this java code:
                Boolean vb = false;
                Configuration.initJava(Const.SAHI_BASE, Const.USER_DATA_DIRECTORY); 
                prx = new Proxy(9999);
                prx.start(true);
                int wait = 0;
                while((!vb)&& (wait<30)){
                  if(prx.isRunning()) {
                    vb = true;
                  }
                  else
                  {
                    wait++;
                    Thread.sleep(1000);
                  }
                }
                if(vb) {
                  System.out.println("Sahi is running");
                }
                else{
                  System.out.println("Sahi is NOT running, or it was manually started");
                }
    

    Apparently this starts the proxy for sahi, but I have a big problem. I cannot check if the proxy server is already started. isRunning() method returns false even if I see in the console "ERROR: Port 9999 is already being used".

    How can I bypass this? The easiest way would be that proxy. start() would return an int or boolean instead of void.

    Any suggestions would be appreciated.

    Thnak you
  • Hi john_qa,

    There are chances that there are other instance of Sahi running and which is using port 9999.

    So could you please close all instance of Sahi and check ?


    Regards
    Sumitra
  • john_qajohn_qa Members
    edited January 2012
    That is exactly the ideea. I know there are other instances, because that was the case I was trying to check.

    Basically I want my tests to start a proxy if another is not already started, or use the existing started proxy if exists. How can I check this?

    Is there a way to kill the existing proxy process? What is his name in tasklist?

    Thanks
  • Hi john_qa,

    Have a look at :

    http://sahi.co.in/java/javadocs/net/sf/sahi/Proxy.html

    http://sahi.co.in/forums/viewtopic.php?id=3126

    Let me know if this solves your issue.

    Regards
    Sumitra
  • Hi,

    Thank you for the answers.

    The good news is that is OK to use a bat file to stop the already running proxy, but I find this a little awkward and not very elegant.

    The bad news is that proxy.stop() doesn't work for an existing running proxy.

    Regards
Sign In or Register to comment.