18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
problem with catch block execution
My code snippet looks as follows:
function searchForAirFlightFare($departure,$arrival,$departDate)
{
_stopOnError();
try
{
_setValue(_textbox("DlgAirSearchEntriesForm:tblOriginDestination:0:txtDepartLocationCode"), $departure);
_setValue(_textbox("DlgAirSearchEntriesForm:tblOriginDestination:0:txtArrivalLocationCode"), $arrival);
// _setValue(_textbox("DlgAirSearchEntriesForm:tblOriginDestination:0:txtDepartDate"), $departDate);
_click(_submit("Fare Search"));
} catch (e)
{
_logException(e);
_click(_submit("Clear Search"));
}
_continueOnError();
}
searchForAirFlightFare("HYD", "FRA", "08/31/2009");
I have 3 mandatory fileds----as you see in the code the 3rd _setValue(...) is commented , so in this case when "Fare Search" button is clicked ,application throws an exception for missing mandatory filed.So I have written a Catch block for that.
But when I execute this script in Sahi Controller,catch block is not executed .It clicks Fare Search and stops the script with success.
Hope you help me doing this Try-Catch.
function searchForAirFlightFare($departure,$arrival,$departDate)
{
_stopOnError();
try
{
_setValue(_textbox("DlgAirSearchEntriesForm:tblOriginDestination:0:txtDepartLocationCode"), $departure);
_setValue(_textbox("DlgAirSearchEntriesForm:tblOriginDestination:0:txtArrivalLocationCode"), $arrival);
// _setValue(_textbox("DlgAirSearchEntriesForm:tblOriginDestination:0:txtDepartDate"), $departDate);
_click(_submit("Fare Search"));
} catch (e)
{
_logException(e);
_click(_submit("Clear Search"));
}
_continueOnError();
}
searchForAirFlightFare("HYD", "FRA", "08/31/2009");
I have 3 mandatory fileds----as you see in the code the 3rd _setValue(...) is commented , so in this case when "Fare Search" button is clicked ,application throws an exception for missing mandatory filed.So I have written a Catch block for that.
But when I execute this script in Sahi Controller,catch block is not executed .It clicks Fare Search and stops the script with success.
Hope you help me doing this Try-Catch.
Comments
Exceptions thrown by an application's logic will not be caught by Sahi's try catch.
Sahi's try catch will kick in if the step _click(_submit("Fare Search")); actually threw an exception, which would happen if there was no submit button called "Fare Search" and we were trying to click it.
In your case, you should just do something like this:
http://sahi.co.in/forums/viewtopic.php?id=1004
which explains that if there is some exception is thrown in "try" block it should catch it and execute "catch" block.
How far your forum solution is applicable for my code?
So, can you please listout under which conditions or situations Sahi is able to catch Exception and execute the catch block????
URGENT Please.
As far as Sahi is concerned, an error message shown by an application is valid behaviour. It does not qualify as a runtime exception of Javascript. You will easily be able to find valid cases of javascript exceptions on the net (Sorry, but I am unable to explain that well enough, so I am pointing you to the internet.)
Regards,
Narayan