Write functional test-suites for webapps with Test::WWW::Mechanize::Runner
I’ve been playing with WWW::Mechanize in order to write some functional tests for a webapp. My goal is to simulate as closely as possible a human-made browsing: accessing pages, clicking here and there and submiting forms.
WWW::Mechanize is good. But if you want to be as close as possible to a real browsing, the best thing to do is to drive an instance of a real browser. There comes in play Mozilla::Mechanize and Win32::IE::Mechanize. Both of them use the browser they implement to do the work, and that’s pretty great.
Even better : you want to support javascript and simulate real clicks done in the webpage? Mozilla::Mechanize::GUITester does the job. The CPAN is really a gold-mine, you know.
I was happy, I could use several agents to run my tests, that was what I wanted. But when I started writing my tests suites, I realized I was about to write the same suites for each agent I wanted to test. That sucks. Do not repeat yourself, you know, the mantra. Hmm.
I got the idea of a small test-wrapper that could handle the suites and run them with the agent you like. After a couple of experiments I came to something I was happy with, and published the first version, it’s called Test::WWW::Mechanize::Runner.
As you can read in the documentation, you write your test in a module that inherits from the runner; each of the test receives the agent in its argument list. Once the suites are defined in your module, just use it in your test script, set the agent you like and call the run() method.
For instance, say you want to run your “GoogleTest” suite with IE and Mozilla :
test-google.t:
use GoogleTest;
GoogleTest->init('msie');
GoogleTest->run();
GoogleTest->init('mozilla');
GoogleTest->run();