NAME
Test::HTML::Form - HTML Testing and Value Extracting
VERSION
1.01
SYNOPSIS
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+)'});
DESCRIPTION
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)
FUNCTIONS
image_matches
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
no_image
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.
Takes a list of arguments filename/response, string or quoted-regexp to match, and optional test comment/name
link_matches
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');
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
no_link
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.
Takes a list of arguments filename/response, string or quoted-regexp to match, and optional test comment/name
title_matches
Test that some HTML contains a title tag with content matching the pattern/string provided.
title_matches($filename,'Foo bar home page','title matches');
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
no_title
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.
Takes a list of arguments filename/response, string or quoted-regexp to match, and optional test comment/name
tag_matches
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
Passes when at least one instance found, fails if no matches found.
Takes a list of arguments
- filename/response - string of path/name of file, or an HTTP::Response object
- tag type(s) - string or arrarref of strings naming which tag(s) to match
- attributes - hashref of attributes and strings or quoted-regexps to match
- comment - an optional test comment/name
no_tag
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
Passes if no matches found, fails when at least one instance found.
Takes a list of arguments filename/response, hashref of attributes and strings or quoted-regexps to match, and optional test comment/name
text_matches
Test that some HTML contains some content matching the pattern/string provided.
text_matches($filename,$text,$name); # check text found in file
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
no_text
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
Passes if no matches found, fails when at least one instance found.
Takes a list of arguments filename/response, string or quoted-regexp to match, and optional test comment/name
script_matches
Test that HTML script element contains text matcging that provided.
script_matches($response, qr/function someWidget/, 'found widget in JS');
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
form_field_value_matches
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
Test that the HTML contains a form element with the value matching that provided.
form_select_field_matches($filename,{ field_name => $field_name, selected => $field_value, form_name => $form_name}, $description);
Takes a mixed list/ hashref of arguments :
- filename/response,
- hashref of search attributes, keys are : field_name, selected, form_name (optional)
- optional test comment/name
Selected field value can be string or quoted regexp
form_checkbox_field_matches
Test that the HTML contains a form element with the value matching that provided.
form_checkbox_field_matches($filename,{ field_name => $field_name, selected => $field_value, form_name => $form_name}, $description);
Takes a mixed list/ hashref of arguments :
- filename/response,
- hashref of search attributes, keys are : field_name, selected, form_name (optional)
- optional test comment/name
Selected field value can be string or quoted regexp
get_form_values
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.
extract_text
my $posting_id = Test::HTML::Form->extract_text({filename => 'publish.html', pattern => 'Reference :\s(\d+)'});
SEE ALSO
AUTHOR
Aaron Trevena
BUGS
Please report any bugs or feature requests to http://rt.cpan.org
COPYRIGHT & LICENSE
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.