Test::HTML::Form - HTML Testing and Value Extracting
1.01
use Test::HTML::Form; my $filename = 't/form_with_errors.html'; my $response = $ua->request($request) # test functions title_matches($filename,'Foo Bar','title matches'); no_title($filename,'test site','no english title'); tag_matches($response, 'p', { class => 'formError', _content => 'There is an error in this form.' }, 'main error message appears as expected' ); no_tag($filename, 'p', { class => 'formError', _content => 'Error' }, 'no unexpected errors' ); text_matches($filename,'koncerty','found text : koncerty'); # check text found in file no_text($filename,'Concert','no text matching : Concert'); # check text found in file image_matches($filename,'/images/error.gif','matching image found image in HTML'); link_matches($filename,'/post/foo.html','Found link in HTML'); script_matches($response, qr/function someWidget/, 'found widget in JS'); form_field_value_matches($response,'category_id', 12345678, undef, 'category_id matches'); form_select_field_matches($filename,{ field_name => $field_name, selected => $field_value, form_name => $form_name}, $description); form_checkbox_field_matches($response,{ field_name => $field_name, selected => $field_value, form_name => $form_name}, $description); # Data extraction functions my $form_values = Test::HTML::Form->get_form_values({filename => $filename, form_name => 'form1'}); my $posting_id = Test::HTML::Form->extract_text({filename => 'publish.html', pattern => 'Reference :\s(\d+)'});
Test HTML pages and forms, and extract values.
Developed for and released with permission of Slando (http://www.slando.com)
All test functions will take either a filename or an HTTP::Response compatible object (i.e. any object with a content method)
Test that some HTML contains an img tag with a src attribute matching the link provided.
image_matches($filename,$image_source,'matching image found image in HTML');
Passes when at least one instance found, fails if no matches found.
Takes a list of arguments filename/response, string or quoted-regexp to match, and optional test comment/name
Test that some HTML doesn't contain any img tag with a src attribute matching the link provided.
no_image($response,$image_source,'no matching image found in HTML');
Passes when no matches found, fails if any matches found.
Test that some HTML contains a href tag with a src attribute matching the link provided.
link_matches($response,$link_destination,'Found link in HTML');
Test that some HTML does not contain a href tag with a src attribute matching the link provided.
link_matches($filename,$link_destination,'Link not in HTML');
Passes when if no matches found, fails when at least one instance found.
Test that some HTML contains a title tag with content matching the pattern/string provided.
title_matches($filename,'Foo bar home page','title matches');
Test that some HTML does not contain a title tag with content matching the pattern/string provided.
no_title($filename,'Foo bar home page','title matches');
Passes if no matches found, fails when at least one instance found.
Test that some HTML contains a tag with content or attributes matching the pattern/string provided.
tag_matches($filename,'a',{ href => $link },$name); # check matching tag found in file
Takes a list of arguments
Test that some HTML does not contain a tag with content or attributes matching the pattern/string provided.
no_tag($filename,'a',{ href => $link },$name); # check matching tag NOT found in file
Takes a list of arguments filename/response, hashref of attributes and strings or quoted-regexps to match, and optional test comment/name
Test that some HTML contains some content matching the pattern/string provided.
text_matches($filename,$text,$name); # check text found in file
Test that some HTML does not contain some content matching the pattern/string provided.
no_text($filename,$text,$name); # check text NOT found in file
Test that HTML script element contains text matcging that provided.
script_matches($response, qr/function someWidget/, 'found widget in JS');
Test that the HTML contains a form element with the value matching that provided.
form_field_value_matches($filename,$field_name, $field_value, $form_name, $description);
form_field_value_matches($filename,$field_name, qr/some pattern/, undef, 'test for foo in bar form field');
Takes a list of arguments : filename/response, string or quoted-regexp to match, optional form_name, and optional test comment/name
Field value argument can be a string (for exact matches) or a quoted regexp (for pattern matches)
Use form_select_field_matches for select elements.
Use form_checkbox_field_matches for checkbox elements
form_select_field_matches($filename,{ field_name => $field_name, selected => $field_value, form_name => $form_name}, $description);
Takes a mixed list/ hashref of arguments :
Selected field value can be string or quoted regexp
form_checkbox_field_matches($filename,{ field_name => $field_name, selected => $field_value, form_name => $form_name}, $description);
Extract form fields and their values from HTML content
my $form_values = Test::HTML::Form->get_form_values({filename => $filename, form_name => 'form1'});
Takes a hashref of arguments : filename (name of file or an HTTP::Response object, required), form_name (optional).
Returns a hashref of form fields, with name as key, and arrayref of XML elements for that field.
my $posting_id = Test::HTML::Form->extract_text({filename => 'publish.html', pattern => 'Reference :\s(\d+)'});
Aaron Trevena
Please report any bugs or feature requests to http://rt.cpan.org
Copyright 2008 Slando. Copyright 2009 Aaron Trevena.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Test::HTML::Form, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::HTML::Form
CPAN shell
perl -MCPAN -e shell install Test::HTML::Form
For more information on module installation, please visit the detailed CPAN module installation guide.