.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test::WWW::Declare 3pm" .TH Test::WWW::Declare 3pm "2015-12-30" "perl v5.22.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::WWW::Declare \- declarative testing for your web app .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Test::WWW::Declare tests => 3; \& use Your::Web::App::Test; \& \& Your::Web::App::Test\->start_server; \& \& session \*(Aqtestuser\*(Aq => run { \& flow \*(Aqlog in and out\*(Aq => check { \& flow \*(Aqlog in\*(Aq => check { \& get \*(Aqhttp://localhost/\*(Aq; \& fill form \*(Aqlogin\*(Aq => { \& username => \*(Aqtestuser\*(Aq, \& password => \*(Aqdrowssap\*(Aq, \& }; \& content should contain \*(Aqlog out\*(Aq; \& }; \& \& flow \*(Aqlog out\*(Aq => check { \& get \*(Aqhttp://localhost/\*(Aq; \& click href \*(Aqlog out\*(Aq; \& }; \& }; \& }; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Often in web apps, tests are very dependent on the state set up by previous tests. If one test fails (e.g. \*(L"follow the link to the admin page\*(R") then it's likely there will be many more failures. This module aims to alleviate this problem, as well as provide a nicer interface to Test::WWW::Mechanize. .PP The central idea is that of \*(L"flow\*(R". Each flow is a sequence of commands (\*(L"fill in this form\*(R") and assertions (\*(L"content should contain 'testuser'\*(R"). If any of these commands or assertions fail then the flow is aborted. Only that one failure is reported to the test harness and user. Flows may also contain other flows. If an inner flow fails, then the outer flow fails as well. .SH "FLOWS AND SESSIONS" .IX Header "FLOWS AND SESSIONS" .SS "session \s-1NAME\s0 => run { \s-1CODE \s0}" .IX Subsection "session NAME => run { CODE }" Sessions are a way of associating a set of flows with a WWW::Mechanize instance. A session is mostly equivalent with a user interacting with your web app. .PP Within a session, every command (\f(CW\*(C`get\*(C'\fR, \f(CW\*(C`click link\*(C'\fR, etc) is operating on that session's WWW::Mechanize instance. You may have multiple sessions in one test file. Two sessions with the same name are in fact the same session. This lets you write code like the following, simplified slightly: .PP .Vb 5 \& session \*(Aqfirst user\*(Aq => run { \& get "$URL/give?task=1&victim=other"; \& session \*(Aqother user\*(Aq => run { \& get "$URL/tasks"; \& content should match qr/task 1/; \& \& # this is the same session/mech as the outermost \*(Aqfirst user\*(Aq \& session \*(Aqfirst user\*(Aq => run { \& get "$URL/tasks"; \& content shouldnt match qr/task 1/; \& }; \& }; \& }; .Ve .SS "flow \s-1NAME\s0 => check { \s-1CODE \s0}" .IX Subsection "flow NAME => check { CODE }" A flow encompasses a single test. As described above, each flow is a sequence of commands, assertions, and other flows. If any of the components of a flow fail, the rest of the flow is aborted and one or more test failures are reported to the test harness. .SH "COMMANDS" .IX Header "COMMANDS" .SS "get \s-1URL\s0" .IX Subsection "get URL" .SS "click button" .IX Subsection "click button" .SS "click href" .IX Subsection "click href" .SS "follow_link" .IX Subsection "follow_link" .SS "fill form \s-1NAME\s0 => {\s-1FIELD1\s0 => \s-1VALUE1, FIELD2\s0 => \s-1VALUE2\s0}" .IX Subsection "fill form NAME => {FIELD1 => VALUE1, FIELD2 => VALUE2}" .SH "ASSERTIONS" .IX Header "ASSERTIONS" Every assertion has two parts: a subject and a verb. .SS "\s-1SUBJECTS\s0" .IX Subsection "SUBJECTS" \fIcontent\fR .IX Subsection "content" .PP \fItitle\fR .IX Subsection "title" .PP \fIurl\fR .IX Subsection "url" .SS "\s-1VERBS\s0" .IX Subsection "VERBS" \fIshould(nt) (caselessly) match \s-1REGEX\s0\fR .IX Subsection "should(nt) (caselessly) match REGEX" .PP \fIshould(nt) (caselessly) contain \s-1STRING\s0\fR .IX Subsection "should(nt) (caselessly) contain STRING" .PP \fIshould(nt) (caselessly) lack \s-1STRING\s0\fR .IX Subsection "should(nt) (caselessly) lack STRING" .PP \fIshould(nt) (caselessly) equal \s-1STRING\s0\fR .IX Subsection "should(nt) (caselessly) equal STRING" .SH "SUBCLASSING" .IX Header "SUBCLASSING" One of the goals of this module is to let you subclass it to provide extra features, such as automatically logging in a user each time a session is created. .SH "CAVEATS" .IX Header "CAVEATS" If you fail any tests, then the actual number of tests run may be fewer than you have in your file. This is because when a flow fails, it immediately aborts the rest of its body (which may include other flows). So if you're setting the number of tests based on how many ran, make sure that all tests passed. .SH "BUGS" .IX Header "BUGS" Hopefully few. We'd like to know about any of them. Please report them to \&\f(CW\*(C`bug\-test\-www\-declare@rt.cpan.org\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" Test::WWW::Mechanize, Jifty. .SH "MAINTAINER" .IX Header "MAINTAINER" Shawn M Moore \f(CW\*(C`\*(C'\fR .SH "ORIGINAL AUTHOR" .IX Header "ORIGINAL AUTHOR" Jesse Vincent \f(CW\*(C`\*(C'\fR .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2007\-2008 Best Practical Solutions, \s-1LLC\s0 .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.