12 May 2005 11:15:29 UTC
- Distribution: CGI-Prototype-Mecha
- Module version: 0.21
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (2)
- Testers (78 / 308 / 0)
- KwaliteeBus factor: 0
- % Coverage
- License: unknown
- Activity24 month
- Download (4.41KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionMERLYN Randal L. Schwartz
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";
Test::Moreis 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
STDERRinto 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, <email@example.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.
Module Install Instructions
To install CGI::Prototype::Mecha, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install CGI::Prototype::Mecha
For more information on module installation, please visit the detailed CPAN module installation guide.