Update of /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest/Plugin
In directory usw-pr-cvs1:/tmp/cvs-serv11197/lib/HTTP/WebTest/Plugin
Modified Files:
Click.pm
Log Message:
Added 'click_button' parameter implementation
Index: Click.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest/Plugin/Click.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Click.pm 24 Mar 2002 11:02:26 -0000 1.2
--- Click.pm 27 Apr 2002 21:17:50 -0000 1.3
***************
*** 58,73 ****
# get various params we handle
! my $button = $self->test_param('click_button');
! my $link = $self->test_param('click_link');
! if(defined $link) {
my $link = $self->find_link(response => $response,
! pattern => $link);
$request->uri($link) if defined $link;
! } elsif(defined $button) {
! my $base = $self->find_base($request);
! # find form and button name
! my($form, $name) = $self->find_form();
}
}
--- 58,76 ----
# get various params we handle
! my $click_button = $self->test_param('click_button');
! my $click_link = $self->test_param('click_link');
! if(defined $click_link) {
! # find matching link
my $link = $self->find_link(response => $response,
! pattern => $click_link);
$request->uri($link) if defined $link;
! } elsif(defined $click_button) {
! # find action which corresponds to requested submit button
! my $action = $self->find_form(response => $response,
! pattern => $click_button);
!
! $request->uri($action) if defined $action;
}
}
***************
*** 80,84 ****
my $content = $response->content;
! # look for base tag inside head tag
my $parser = HTML::TokeParser->new(\$content);
my $token = $parser->get_tag('head');
--- 83,87 ----
my $content = $response->content;
! # look for base tag inside of head tag
my $parser = HTML::TokeParser->new(\$content);
my $token = $parser->get_tag('head');
***************
*** 119,126 ****
# we haven't found anything
! return undef unless defined $link;
# return link
return URI->new_abs($link, $base);
}
--- 122,176 ----
# we haven't found anything
! return unless defined $link;
# return link
return URI->new_abs($link, $base);
+ }
+
+ sub find_form {
+ my $self = shift;
+ my %param = @_;
+
+ my $response = $param{response};
+ my $pattern = $param{pattern};
+
+ my $base = $self->find_base($response);
+ my $content = $response->content;
+
+ # look for form
+ my $parser = HTML::TokeParser->new(\$content);
+ my $uri = undef;
+ FORM:
+ while(my $token = $parser->get_tag('form')) {
+ # get action from form tag param
+ my $action = $token->[1]{action} || $base;
+
+ # find matching submit button or end of form
+ while(my $token = $parser->get_tag('input', '/form')) {
+ my $tag = $token->[0];
+
+ if($tag eq '/form') {
+ # end of form: let's look for another form
+ next FORM;
+ }
+
+ # check if right input control is found
+ my $type = $token->[1]{type} || 'text';
+ my $name = $token->[1]{name} || '';
+ my $value = $token->[1]{value} || '';
+ next if $type !~ /^submit$/i;
+ next if $name !~ /$pattern/i and $value !~ /$pattern/i;
+
+ # stop searching
+ $uri = $action;
+ last FORM;
+ }
+ }
+
+ # we haven't found anything
+ return unless defined $uri;
+
+ # return method and link
+ return URI->new_abs($uri, $base);
}
|