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 running batch file multiple times on batch script fail

j.gendersj.genders Members
edited November -1 in Sahi - Open Source
Hi Guys,

I am using the _execute command to run a batch file which in turn runs a VBScript.

The VBScript returns an errorcode (using wscript.quit(100)).
the batch file then returns a failure to Sahi (i'm assuming as the sahi script fails when this errorcode is returned).

when the batch file returns an error, Sahi then tries to run the batch file several times.

the Vb Script opens my outlook inbox, checks for an email with a certain sender and subject, and returns 0 if the email exists and 100 if the email does not.
(basically, I want it to fail if the email is not in my inbox.

I only want the batch file to be called once, and sahi to fail when the batch file returns and error code of 100.

Any ideas?

Code below (note I have removed personal information):
SAHI:====================================================
_navigateTo("myWebsite.com");
_click(_link("Reset Password"));

_setValue(_textbox("username"), "Username");
_setValue(_textbox("emailAddress"), "myEmailAddress.FakeForumEmail");

_click(_submit("Reset Password"));

_assertExists(_div("Your password has been reset and emailed to the email address you provided"));

//wait 8 seconds for email then run VB Script to check inbox for the email
_wait(8000);

_log(_execute("C:\\testData\\sahiScripts\\runVbs.bat", true));

Batch File (runVbs.bat):===================================
cd\
windows\System32\wscript.exe C:\testData\sahiScripts\checkEmail.vbs

VBScript(checkEmail.vbs):================================================

Dim myOlApp
set myOlApp = GetObject(,"OUTLOOK.APPLICATION")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myfolders = myNameSpace.Folders
dim n
n = 1
dim noEmail
noEmail = false
Do Until myfolders.Item(n) = "Mailbox - My Name"
    n = n + 1
Loop
Set myMailbox = myfolders.Item(n)
Set myInbox = myMailbox.Folders("Inbox")
n = 1
Do Until myInbox.Items(n).SenderName = "SenderName" and myInbox.Items(n).subject = "Password Reset"
    n = n + 1
       'only check first 50 emails for now
    if n >= myInbox.items.count - 1 or n > 50 then 
        noEmail = true
        exit do
    end if
Loop
if noEmail then
    'msgbox("No Email")
    WScript.quit(100)
else
    'msgbox("Email Found")
    WScript.quit(0)
end if

Comments

  • _dkulkarni_dkulkarni Members
    edited June 2011
    Hi j.genders,

    Please check if you find any errors on the Sahi console and make sure that the path to the batch file or the vb script is correct.

    Once done, you can start logging your results. Here are the changes you need to make.

    vbs.bat
    Here, errorlevel will have the value of the error code returned by the VB Script.
    @ECHO OFF
    C:\Windows\system32\wscript.exe C:\testData\sahiScripts\checkEmail.vbs
    echo %errorlevel%
    


    Also, add this to your Sahi Script to redirect the output of the batch file and then read contents from it. Check if this solves your problem.
    $userDir = _userDataDir();
    var $tempFile= new java.io.File($userDir, "temp.txt");
    _execute("C:\\testData\\sahiScripts\\runVbs.bat >>" + $tempFile);
    _wait(1000);
    var $contents = _readFile($tempFile);
    var $output = $contents.replace(/\r\n/g, '');
    _assertNotEqual($output,100);
    _deleteFile($tempFile);
    

    Regards,
    dkulkarni
Sign In or Register to comment.