CGI::Prototype::Mecha - test CGI::Prototype applications with WWW::Mechanize
use CGI::Prototype::Mecha; my $m = CGI::Prototype::Mecha->new(protoapp => 'My::App'); $m->get('http://mecha/'); ok $m->success, "fetched welcome page" or $m->diag_response; like $m->content, qr/Select a task/, "welcome page content verified";
WWW::Mechanize combined with Test::More is a great toolbench for testing a web application. But you need to have your code installed in the right location on a running server, and you can't poke behind the scenes to see if data structures or databases in your application are as they are expected to be after a particular web hit.
WWW::Mechanize
Test::More
Enter CGI::Prototype::Mecha, a subclass of WWW::Mechanize.
CGI::Prototype::Mecha
Simply create a Mecha object, giving it the name of your CGI::Prototype-derived application class, and "visit" the magic URL of http://mecha/. Your application is fired up (loading the classes as needed), and you get a "response" as if it were being sent to the browser.
CGI::Prototype
http://mecha/
But, your object is in the same program as your test, so you can set environment variables to simulate auth success or control testing databases. Or even capture STDERR into a file to make sure that a particular error log value is or is not being written.
STDERR
Extended from WWW::Mechanize. An additional protoapp parameter is understood, expecting a CGI::Prototype-derived application class (which should be located in the current @INC). Returns the mecha object.
protoapp
@INC
Extended from WWW::Mechanize (which inherits it directly from LWP::UserAgent. This is where the magic happens.
LWP::UserAgent
Note that visiting any URL that does not start with http://mecha/ is fatal. A future version may fall back to the original WWW::Mechanize, letting you test your app's outbound links properly.
As of version 0.20, even "input type=file" fields will be properly handled.
A convenience method that dumps the result "as_string" via diag() from Test::More.
diag()
A convenience method that dumps all the links (text/url) via diag().
A convenience method that dumps all the forms via diag().
CGI::Prototype, WWW::Mechanize, Test::More
Randal L. Schwartz, <merlyn@stonehenge.com>
Special thanks to Geekcruises.com and an unnamed large university for providing funding for the development of this module.
Copyright (C) 2003, 2004 by Randal L. Schwartz
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.5 or, at your option, any later version of Perl 5 you may have available.
To install CGI::Prototype::Mecha, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Prototype::Mecha
CPAN shell
perl -MCPAN -e shell install CGI::Prototype::Mecha
For more information on module installation, please visit the detailed CPAN module installation guide.