ForgotPasswordAgain has asked for the wisdom of the Perl Monks concerning the following question:
I work on a large web application which needs lots of UI tests. It uses javascript in places. I started out by subclassing WWW::Mechanize and just emulating the javascript parts, but it gets annoying after a while, not to mention I'd like something more general anyway. So a few weeks ago, I set out on a quest for a way to parse javascript in HTML using Perl.
At first, I thought about adding javascript support to WWW::Mechanize using JavaScript::SpiderMonkey. It sounds nice in principle, because JS::SM is the javascript interpreter used by Mozilla. However, in fact it's only the raw interpreter, lacking any browser objects (window, document, etc.) or DOM initialization. After looking at several W3 specifications and HTML::TreeBuilder, I decided to pass on trying to implement the DOM myself.
Next, I found Win32::IE::Mechanize. This uses OLE to control Internet Explorer, and it emulates the WWW::Mechanize interface as a bonus. The only problem is it requires Microsoft® Windows®. Actually, I don't mind Windows so much, but Bricolage doesn't run on Windows so I couldn't test it on my laptop at home.
Trying to find an analogous approach on Linux, I thought of using DCOP with Konqueror, or KHTML. But I couldn't find enough documentation to do useful things (get a handle on the DOM, to click on buttons and links, select from dropdown menus, etc.). If anyone has any pointers/guidance along these lines, it would be much appreciated.
Then I thought again of using Mozilla. This time I had found Gtk2::MozEmbed, which is another great Perl module (the Gtk-Perl documentation and mailing list are fantastic). You can actually embed a Mozilla browser inside a Gtk2 application using Perl. However, it lacks support for things I need (get a handle on the DOM, to click on buttons and links, select from dropdown menus, etc.).
Finally, I found Perl XPCOM, which was yet another very promising path. These are Perl bindings to XPCOM, which are kind of the equivalent of OLE for Mozilla. The problem is, I couldn't get it to build, and the project seems dead (xpcom; the mailing list seems to no longer exist). To be honest, I'm not even sure how I'd proceed once I got XPCOM access, since the documentation I find seems to generally be either about creating XPCOM components in whatever language or is so general or abstract that I don't understand its usefulness.
So then.. I was wondering if anyone had found something. Actually, by this point, I'm not sure I even care whether it uses Perl, as long as I can script interaction with a web application.
UPDATE: I found this discussion. The point Perrin makes is interesting. I have to think about it more, though. I'm not sure if creating tests several pages deep into the interface would work well or not.
UPDATE 2: After noticing an update in the "What's New?" section of the plxpcom site, I built plxpcom in Mozilla 1.6 and it seems to work. I would like to find the "community" for this project, because apparently other than doing `cvs update` every day, there isn't much interaction with the person/people maintaining the project. From a discussion at use.perl.org, I know there are at least one or two others interested in the project.
UPDATE 3 (Aug 5, 2005): See Mozilla::DOM
|
---|