Friday, February 29, 2008

Gracefully exiting on a validation error on page

There are often times when there is a validation error on the page and the buttons expected oinideal scenario dont appear. In such cases, the script continues to execute though - expecting the elements in future lines of the script to be present, when they are actually not since the application has stopped due to the Validation error.

At times, this causes an issue too, coz the script ends up 'clicking' an element that it should not have (for eg. a submit button that should have been clicked upon the scenario being successful will still get clicked even though the expected result wasnt encountered - leading to different flow being executed).

So to avoid such things from happening, I wrote up a simple subroutine that I added at the start of the script which would "get_body_text()" and then verify that a text 'validation error' was not present anywhere on the page. If found, exit. No more steps to be executed.

##########################
sub data_extract
{
my $text=0;
$text = $sel->get_body_text();
if ($text =~ m/$_[0]/){
print "there is a validation error on page\n";
$sel->select_frame_ok("topframe");
$sel->click_ok("link=Logout");
$sel->stop;
exit;
}
}
##########################

-V

No comments: