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.

Running scripts in loop

aakash_1983aakash_1983 Members
edited November -1 in Sahi - Open Source
Hi All,

I have 2 scripts and i want them to run them in a do while loop.
i want to close the browser after the execution of each script,i have set the threads as 1 in the testrunner,sah file.I have created a suite and called these scripts in the suite as below :

Test1.sah
Test2.sah

Now the scripts are running by the suite and after execution of each script the browser is getting closed.

The peoblem is it all of the scripts running one time only.I want them to run in a do wile loop one by one .

I have tried creating a script where i have included these 2 scripts but in that case theese scripts runs one by one within the same browser however i want to close the browser after the completion of each script execution.



Please help.

Thanks and Regards,
Aakash

Comments

  • Adding few more points

    1I tried writing do while loop within the suite file but its not working ,while running the code is considered as scripts by executer.I can see the ecexuter putting the loop statements in the browser it self.it seems its not supported.

    Is it?

    2.Can we call the .sah file from external programs like java or vb?

    Please help.

    Thanks and Regards,
    Aakash
  • Hi,

    What is your operating system? Windows?
    If you're on Windows you can use to make this task batch. I made a small script. Create a batch file with this code and you execute a cycle.

    the code:

    Arr_echo off
    set contador=0
    :bucle
    if %contador% LSS 2 (
    set /a contador=%contador%+1
    cd /
    cd sahi\userdata\bin\
    Start /I /MIN start_dashboard.bat
    choice /c a /d a /t 2 /n
    Start /I /MIN testrunner start.sah page chrome
    ping -n 60 localhost
    TASKKILL /F /IM java.exe /T
    goto :bucle
    )
    exit


    - First declare a counter (set counter = 0).
    - The if executes instructions until the counter is less than 2 (if% count% LSS 2).
    - Increase in counter (set / a counter =% counter% +1).
    - Runs sahi and runs the script with TestRunner.


    cd /
    cd sahi\userdata\bin\
    Start /I /MIN start_dashboard.bat
    choice /c a /d a /t 2 /n //wait 2 seconds
    Start /I /MIN testrunner start.sah home_page chrome

    - The ping is just a trick to wait 60 seconds :) (ping -n 60 localhost).
    - The task kill taskkill of java and closes sahi (TASKKILL /F /IM java.exe /T).
    - Then run the goto that goes up the back pointer and executes all instructions. (goto :bucle )


    My sahi path is C:sahi
    My name scritp is start.sah. replace the name of your script

    good luck :)
  • Hi facilos,

    Thanks for your reply.

    My OS is ubuntu is it possible to do that on Ubuntu?



    Please help.

    Thanks and Regards,
    Aakash
  • Sure,

    just write a shell script with the same logic...

    you could also use ant in a do while loop. In your Sahi installation shoudld be some sort of example.xml where you can define suite executions.
    Its a little bit like the testrunner.sh and u call it with e.g. ant -t runfirefoxTests
Sign In or Register to comment.