HTTP::WebTest::Plugin::Sticky - Propagate hidden and text form fields


HTTP-WebTest-Plugin-Sticky documentation Contained in the HTTP-WebTest-Plugin-Sticky distribution.

Index


Code Index:

NAME

Top

HTTP::WebTest::Plugin::Sticky - Propagate hidden and text form fields

VERSION

Top

Version 0.02

SYNOPSIS

Top

    plugins = ( ::Sticky )

    test_name = Some test
        sticky = yes
        click_button = Next
        params = (
                name => 'This is a new text field'
        )
    end_test

DESCRIPTION

Top

This plugin for the HTTP::WebTest module let you post a form that includes all the inputs from the page, including hidden ones.

Also you can add new inputs using the "params" hash.

In case of inputs of type "checkbox", they are included only if they have the "checked" property. In other case, you must set it on purpose using the normal "params" hash.

TEST PARAMETERS

Top

sticky

Allow/disallows the fields propagation. Values allowed: yes / no.

AUTHOR

Top

Hugo Salgado H., <huguei at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-http-webtest-plugin-sticky at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-WebTest-Plugin-Sticky. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc HTTP::WebTest::Plugin::Sticky

You can also look for general information at:

    perldoc HTTP::WebTest

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/HTTP-WebTest-Plugin-Sticky

* CPAN Ratings

http://cpanratings.perl.org/d/HTTP-WebTest-Plugin-Sticky

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-WebTest-Plugin-Sticky

* Search CPAN

http://search.cpan.org/dist/HTTP-WebTest-Plugin-Sticky

ACKNOWLEDGEMENTS

Top

The code was based in a lost posting on the webtest mailing list. Thanks to whoever was responsible for that.

COPYRIGHT & LICENSE

Top

SEE ALSO

Top

HTTP::WebTest

HTTP::WebTest::API (HTTP::WebTest::API)

HTTP::WebTest::Plugin


HTTP-WebTest-Plugin-Sticky documentation Contained in the HTTP-WebTest-Plugin-Sticky distribution.
package HTTP::WebTest::Plugin::Sticky;

use warnings;
use strict;

our $VERSION = '0.02';


use HTML::TokeParser;

use base qw(HTTP::WebTest::Plugin);

sub param_types {
    return 'sticky yesno
                        params hashlist';
}

sub prepare_request {
    my $self = shift;
    $self->validate_params(qw(sticky params));

    my $request = $self->webtest->current_request;

    my $prev_test_num = $self->webtest->current_test_num - 1;
    return if $prev_test_num < 0;

    my $response = $self->webtest->tests->[$prev_test_num]->response;

    return unless defined $response;

    return unless $response->content_type eq 'text/html';

    my $sticky = $self->test_param('sticky');

    return unless defined($sticky);
    return unless $sticky eq 'yes';

    my $params = $self->test_param('params');

    my $content = $response->content;

    my %inputs = ();
    my $parser = HTML::TokeParser->new(\$content);
    while(my $token = $parser->get_tag('input')) {
        my $type  = $token->[1]{type};
        next unless defined $type;
        my $name  = $token->[1]{name};
        next unless defined $name;
        my $value = $token->[1]{value};
        next unless defined $value;

        next if (lc($type) eq 'checkbox') and  not defined($token->[1]{checked});

        $inputs{$name} = $value;
    }
    if(defined $params) {
        my %params = ref($params) eq "ARRAY" ? @$params : %$params;
        for my $key (keys(%params)) {
            $inputs{$key} = $params{$key};
        }
    }
    my @inputs = %inputs;
    $request->params(\@inputs);
    return [];
}




1; # End of HTTP::WebTest::Plugin::Sticky