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.

_execute with batch files

DonnaMooresDonnaMoores Members
edited November -1 in Sahi - Open Source
I am using a batch file to reset my test data back to its initial state.
This is file resetDataThinning.bat:

C:\\Progra~1\\Java\\jdk1.6.0_04\\bin\\javac ClearDatabase.java
C:\\Progra~1\\Java\\jdk1.6.0_04\\bin\\java -cp .;C:\\Progra~1\\sahi\\lib\\jtds\\jtds-1.2.2.jar ClearDatabase 5
I then have a script set up with the following
_execute("resetDataThinning.bat");
If I run the batch file as a standalone batch file the values are reset successfully.

If I then run the sahi script from the same location as the batch file, nothing happens.

Any suggsestions?

Thank you
Donna

Comments

  • It looks like the _execute() method wants two parameters.

    Here's the _excute() code:

    Sahi.prototype._execute = function (command, sync) {
    var is_sync = sync ? "true" : "false";
    var status = this._callServer("CommandInvoker_execute", "command=" + encodeURIComponent(command) + "&sync=" + is_sync);
    if ("success" != status) {
    throw new Error("Execute Command Failed!");
    }
    }
  • Ya..it takes two parameters:
    here is the example from list of sahi API:

    Syntax:
    _execute(command, isSynchronous)

    The parameters are:

    command: command to be executed
    isSynchronous: true or false.
    Set this to true if you want the script to wait till the process returns. Setting this to false will execute the command in a thread and continue.
    Example:
    _execute("loadFromDB.bat");

    So, as per the example, the second parameter is optional...
    But do give it a try using the second parameter...
  • I have changed my script to be
    _execute("resetDataThinning.bat", "true");
    
    And the error message I get is:
    _execute("resetDataThinning.bat", "true"); Error: Execute Command Failed!
    No trace available
    Cheers
    Donna
  • I have resolved my problems, and enclosed my solution below:

    I script my batch files into two.

    Compile.bat
    cd C:\\Users\\MooresD\\SENTRAWEB\\Latest_Sources\\SentraWebSolution\\SentraResourcesForUnitTesting\\SahiTests\\
    C:\\Progra~1\\Java\\jdk1.6.0_04\\bin\\javac ClearDatabase.java
    C:\\Progra~1\\Java\\jdk1.6.0_04\\bin\\java -cp .;C:\\Progra~1\\sahi\\lib\\jtds\\jtds-1.2.2.jar ClearDatabase 5
    
    Run.bat
    cd C:\\Users\\MooresD\\SENTRAWEB\\Latest_Sources\\SentraWebSolution\\SentraResourcesForUnitTesting\\SahiTests\\
    C:\\Progra~1\\Java\\jdk1.6.0_04\\bin\\java -cp .;C:\\Progra~1\\sahi\\lib\\jtds\\jtds-1.2.2.jar ClearDatabase 5
    
    And my script looked like
    _execute("C:\\Users\\MooresD\\SENTRAWEB\\Latest_Sources\\SentraWebSolution\\SentraResourcesForUnitTesting\\SahiTests\\resetDataThinning_compile.bat", "true");
    _execute("C:\\Users\\MooresD\\SENTRAWEB\\Latest_Sources\\SentraWebSolution\\SentraResourcesForUnitTesting\\SahiTests\\resetDataThinning_run.bat", "true");
    
    This does the job for me, but if anyone knows of any neater solutions then I am more than willing to give them ago... or even explain why this solution works, but my original posting didnt work.

    Cheers
    Donna
Sign In or Register to comment.