[Http-webtest-general] A custom plug-in to mute "Bad URI" error
Brought to you by:
m_ilya,
richardanderson
From: I.K. <x1...@us...> - 2005-04-21 14:08:41
|
People: This is an excellent tool, but it has a bad habit of dying in a middle of a test sequence if a bad URI is encountered. It happens on line 567 of API.pm, I'm looking at r.1.29 of it. In my book, it's a bad thing - I'd rather have it to fail the test and continue with the program. Enclosed is the little module that does just that. To use it, you have to add it into the list, something like this: my %globalParams = ( relative_urls => "yes", plugins => [ "HTTP::WebTest::Plugin::Click", "MuteBadURI", ], timeout => $timeOut, default_report => "no", # etc.... ); my $webtest = new HTTP::WebTest; $webtest->run_tests(\@tests, \%globalParams); I think it's worth considering for the maintainers of the code to include such behavior as a run-time parameter on a more permanent basis. Thanks! Sincerely, Ivan K. -------------------- MuteBadURI.pm ------------------------------ # The problem is that HTTP::WebTest's API.pm module dies if an improper URI is passed along. This # happens quite often, especially if HTTP::WebTest::Plugin::Click module is used - when, for # example, no suitable URL or button is found in a result page to click on. The API's # run_test() method dies thus canceling the whole test sequence. # # This plug in fools API.pm by replacing it's bad URI marker with it's own and allowing all # subsequent tests in a chain to proceed and fail (that's a bad URI) peacefully. # package MuteBadURI; use strict; use URI; use base qw(HTTP::WebTest::Plugin); my $API_BAD_URI = "http://MISSING_HOSTNAME/"; my $MY_BAD_URI = "http://0.0.0.0/"; sub prepare_request { my $self = shift; if( $self->webtest->current_request and ($self->webtest->current_request->uri eq $API_BAD_URI) ) { $self->webtest->current_request->base_uri($MY_BAD_URI); } } 1; |