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.
Catch statement is not executed when running data driven test
I've written two data driven test case using csv file. One for checking valid login and another or checking invlid login. If login is successful it will verify my account and logout. If an invalid login it will show and alert with close button.
Here is the TC for valid login
var $data = _readCSVFile("C:/sahi/projects/mundusync/docs/test_valid.csv");
for (var $i=0; $i<($data.length); $i++)
{
var $row = $data[$i];
try
{
_setValue(_textbox("uname"), $row[0]);
_setValue(_password("passwd"), $row[1]);
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
}
catch (e)
{
_click(_image("close1.png"));
_logException(e);
}
}
I have 3 values in csv file. 1st and 3rd are valid login(test should pass) and second is invlid login (test should fail). When i run the test it is executing properly. when the value of i=2 (Second row) it is not logging in, it closes the alert and continue executing the 3 row and the test completes success fully with failure status.
Here is the series of statements executed in play back window.
_setValue(_textbox("uname"), "valid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
_setValue(_textbox("uname"), "invalid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
_click(_image("close1.png"));
_setValue(_textbox("uname"), "valid2");
_setValue(_password("passwd"), "passwor");
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
--Stopped Playback: FAILURE--
The above TC is executed properly.
TC for invalid login
And now, i've written another test case to check invalid login. In the test case i'm doing the reverse action. Here is the test case.
var $data = _readCSVFile("C:/sahi/projects/mundusync/docs/test_invalid.csv");
for (var $i=0; $i<($data.length); $i++)
{
var $row = $data[$i];
try
{
_setValue(_textbox("uname"), $row[0]);
_setValue(_password("passwd"), $row[1]);
_click(_image("submit.png"));
_assertExists(_image("err.png"));
_click(_image("close1.png"));
}
catch (e)
{
_click(_link("Logout"));
_logException(e);
}
}
here I have 3 values in csv file. 1st and 3rd are invalid login (Test should be pass) and second is valid login (test should fail). When i run the test it is failing for the second value in the loop. But it is not logging out by clicking the logout link which is given in the catch statement. Because of that the third row is not executed properly. It is not able to enter the 3rd raw in the login and password field as it is not logged out. Here is the series of statements executed in playback.
_setValue(_textbox("uname"), "invalid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_image("err.png"));
_click(_image("close1.png"));
_setValue(_textbox("uname"), "valid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_image("err.png")); // Here the test failed, but the logut statement in catch block is not executed after this statement where as it did properly in the first test case which is the reverse scenario
_click(_image("close1.png"));
_setValue(_textbox("uname"), "invalid2"); //As logout was not done, it is not able to find the user name and password fields and not able to enter the 3rd row values
_click(_link("Logout")); //here the user action is occurred which had to be executed after executing the second row in the CSV file
--Stopped Playback: FAILURE--
Here, after executing the second raw, it is not executing the logout action.
The first (TC for valid login) and second (TC for invalid login) have the same structure. Please let me know why the second TC is not working and where should I make the change.
Thanks and Regards,
Anoop.
Here is the TC for valid login
var $data = _readCSVFile("C:/sahi/projects/mundusync/docs/test_valid.csv");
for (var $i=0; $i<($data.length); $i++)
{
var $row = $data[$i];
try
{
_setValue(_textbox("uname"), $row[0]);
_setValue(_password("passwd"), $row[1]);
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
}
catch (e)
{
_click(_image("close1.png"));
_logException(e);
}
}
I have 3 values in csv file. 1st and 3rd are valid login(test should pass) and second is invlid login (test should fail). When i run the test it is executing properly. when the value of i=2 (Second row) it is not logging in, it closes the alert and continue executing the 3 row and the test completes success fully with failure status.
Here is the series of statements executed in play back window.
_setValue(_textbox("uname"), "valid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
_setValue(_textbox("uname"), "invalid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
_click(_image("close1.png"));
_setValue(_textbox("uname"), "valid2");
_setValue(_password("passwd"), "passwor");
_click(_image("submit.png"));
_assertExists(_link("My account"));
_click(_link("Logout"));
--Stopped Playback: FAILURE--
The above TC is executed properly.
TC for invalid login
And now, i've written another test case to check invalid login. In the test case i'm doing the reverse action. Here is the test case.
var $data = _readCSVFile("C:/sahi/projects/mundusync/docs/test_invalid.csv");
for (var $i=0; $i<($data.length); $i++)
{
var $row = $data[$i];
try
{
_setValue(_textbox("uname"), $row[0]);
_setValue(_password("passwd"), $row[1]);
_click(_image("submit.png"));
_assertExists(_image("err.png"));
_click(_image("close1.png"));
}
catch (e)
{
_click(_link("Logout"));
_logException(e);
}
}
here I have 3 values in csv file. 1st and 3rd are invalid login (Test should be pass) and second is valid login (test should fail). When i run the test it is failing for the second value in the loop. But it is not logging out by clicking the logout link which is given in the catch statement. Because of that the third row is not executed properly. It is not able to enter the 3rd raw in the login and password field as it is not logged out. Here is the series of statements executed in playback.
_setValue(_textbox("uname"), "invalid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_image("err.png"));
_click(_image("close1.png"));
_setValue(_textbox("uname"), "valid1");
_setValue(_password("passwd"), "password");
_click(_image("submit.png"));
_assertExists(_image("err.png")); // Here the test failed, but the logut statement in catch block is not executed after this statement where as it did properly in the first test case which is the reverse scenario
_click(_image("close1.png"));
_setValue(_textbox("uname"), "invalid2"); //As logout was not done, it is not able to find the user name and password fields and not able to enter the 3rd row values
_click(_link("Logout")); //here the user action is occurred which had to be executed after executing the second row in the CSV file
--Stopped Playback: FAILURE--
Here, after executing the second raw, it is not executing the logout action.
The first (TC for valid login) and second (TC for invalid login) have the same structure. Please let me know why the second TC is not working and where should I make the change.
Thanks and Regards,
Anoop.