Re: [Http-webtest-general] Hidden Parameters and Premature Exits
Brought to you by:
m_ilya,
richardanderson
From: Ilya M. <il...@ip...> - 2003-09-11 08:34:17
|
>>>>> "MM" == Mark Mertel <mm...@ol...> writes: MM> Ilya, MM> I'm a new user of your testing module and have a couple of questions. MM> First off, I'm wondering when you are going to include the hidden MM> parameter request- where we are able to take all of these hidden MM> variables out of the response and pass them as params to the next test. There was posted in this mailling list a plugin (see mailing list archives - http://xrl.us/s2b) which allows to do this. I had plans to implement such functionality in Click plugin but so far I had no time. Hmm, I've just noticed that SF's mailing list archives do not show attachments. So I'm reposting source code of the plugin which adds support for hidden fields inlined in this email. See past my signature. MM> And secondly, if I chain several click_button tests together and an MM> early one fails I'm getting a quirky error: MM> HTTP::WebTest: request uri is not set at MM> /usr/lib/perl5/site_perl/5.6.1/HTTP/WebTest/API.pm line 567. MM> Is there a better to report a failed test ? I'll take a look on this issue. There are some cases when HTTP::WebTest's error reporting is quite clumsy. -- Ilya Martynov, il...@ip... CTO IPonWEB (UK) Ltd Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net Personal website - http://martynov.org # $Id$ package HTTP::WebTest::Plugin::StickyHidden; =head1 NAME HTTP::WebTest::Plugin::StickyHidden - get hash of hidden variable(s) from previous test and use it as param =head1 SYNOPSIS plugins = ( ::StickyHidden ) test_name = Some test url = url of form with hidden vars end_test test_name = Another test sticky_hidden = yes|no param = (extra_param => value) url = some url end_test =head1 DESCRIPTION This plugin get hash of hidden variable from previous test and use it as param =cut use strict; use HTML::TokeParser; use base qw(HTTP::WebTest::Plugin); =head1 TEST PARAMETERS =for pod_merge copy params =head2 sticky_hidden Whether to stick to hash of hidden variable(s) =head3 Default value C<no>. =cut sub param_types { return q(sticky_hidden yesno params hashlist ); } sub prepare_request { # get webtest object my $self = shift; $self->validate_params(qw(sticky_hidden params)); # get current request object my $request = $self->webtest->current_request; # get number of previous test if any my $prev_test_num = $self->webtest->current_test_num - 1; return if $prev_test_num < 0; # get previous response object my $response = $self->webtest->tests->[$prev_test_num]->response; # no response - nothing to do return unless defined $response; # do nothing unless it is HTML return unless $response->content_type eq 'text/html'; # get various params we handle my $sticky_hidden = $self->test_param('sticky_hidden'); return unless defined($sticky_hidden); return unless $sticky_hidden eq 'yes'; my $params = $self->test_param('params'); my $content = $response->content; # look for hiddn tag my %hidden_var = (); my $parser = HTML::TokeParser->new(\$content); while(my $token = $parser->get_tag('input')) { my $type = $token->[1]{type}; next unless defined $type; next unless $type =~ /hidden/i; my $name = $token->[1]{name}; next unless defined $name; my $value = $token->[1]{value}; next unless defined $value; $hidden_var{$name} = $value; } if(defined $params) { my %params = ref($params) eq 'ARRAY' ? @$params : %$params; for my $key (keys(%params)) { $hidden_var{$key} = $params{$key}; } } my @hidden_var = %hidden_var; $request->params(\@hidden_var); return []; } =head1 COPYRIGHT Copyright (c) 2003 Naoki Shima. All rights reserved. Copyright (c) 2001-2003 Ilya Martynov. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L<HTTP::WebTest::API|HTTP::WebTest::API> L<HTTP::WebTest::Plugin|HTTP::WebTest::Plugin> L<HTTP::WebTest::Plugins|HTTP::WebTest::Plugins> =cut 1; |