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.
CGI::Prototype::Mecha, a subclass of
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.
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.
WWW::Mechanize. An additional
protoappparameter is understood, expecting a
CGI::Prototype-derived application class (which should be located in the current
@INC). Returns the mecha object.
WWW::Mechanize(which inherits it directly from
LWP::UserAgent. This is where the magic happens.
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
A convenience method that dumps all the links (text/url) via
A convenience method that dumps all the forms via
Randal L. Schwartz, <firstname.lastname@example.org>
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.