Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

schwern (1528)

schwern
  (email not shown publicly)
http://schwern.net/
AOL IM: MichaelSchwern (Add Buddy, Send Message)
Jabber: schwern@gmail.com

Schwern can destroy CPAN at his whim.

Journal of schwern (1528)

Sunday June 07, 2009
07:20 PM

Unit test your Javascript in 8 seconds!

[ #39092 ]

I posted about my WWW::Selenium + Test.Simple hack yesterday to enable automated Javascript unit testing. One of the problems was it was very slow. It had to start and kill a Firefox instance between each test which takes 8 seconds per test on my machine. Running 7 tests is a full minute.

Solution? Cache the selenium object! This will reuse the same Firefox session between tests so you only get slammed by the startup cost once. Now my 7 tests run in 8 seconds, the time to start up Firefox. That's awesome!

Will reusing the same Firefox process cause a problem? Unlikely. When I test web sites, with or without Selenium, I sure don't restart Firefox between checks. And neither will your users, so this is far more realistic. Web browsers are designed to isolate page requests from one another.

The prototype works. Future directions...

* Roll selenium-server into the distribution.
* Automate starting the selenium server.
* Add a config file...
    * Which browser(s) to use?
    * Which selenium server to use, or start its own?
    * What file extensions to test with selenium?
* Rerun tests across multiple browsers
* Turn the HTML wrapper into a configurable template
* Make it play nice with prove.
    * Turn it into something which can be used with --exec
    * Turn it into something which can be put into .proverc
* Modularize it
* Figure out how to keep the Firefox process from appearing
    * Or at least run backgrounded

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Will reusing the same Firefox process cause a problem?

    Your arguments in favor of reusing the process are very similar to my arguments in favor of running tests in a single process with Test::Aggregate. Even though it's worked very well, a few people raked me over the coals for this decision. I wonder if they'll give you the same level of grief :)

    • A web browser is designed to keep things strictly separated. Perl is, at best, a half-blind chaperonage in a French farce.

      Test::Aggregate is the mod_perl of the testing world. If you take a bunch of things which were all designed to run in their own process once and then terminate and try to smash them together they're going to step all over each other and themselves. It requires careful recrafting, and restricting, of the formerly independent tests for them to all run together. Even then you can't be s

  • Awhile back, I wrote the following tutorial

    # Using WWW::Selenium To Test Or Automate An Ajax Website

    http://perlmonks.org/?node_id=720018 [perlmonks.org]

    It is more about getting the most out of Selenium and working around some issues than it is about integrating it into your testing framework. In any event, any tips, tricks or pointers you might be able to share would be very much appreciated.

    • I had none of the problems you had getting Selenium RC running on OS X. It fired right up and found my Firefox. I get no errors switching base domains. I didn't try it with SSL. Maybe they fixed it with 1.0?

      I don't have much experience with Selenium, honestly. I've taken over doing acceptance level QA at Open Sourcery and have just started seriously using Selenium. Its all been in the IDE up to this point -- recording and tweaking for Ajax (I've found waitForElementPresent to be very handy in that reg

  • Selenium server itself supports "multiWindow" mode, which means that when the server is started up it also kicks firefox off at that time. It will then open a new window as a child and run your tests in there.

    Other ways to speed the process up is to create your own dump of a firefox profile (selenium creates one for you, but does it every time). This will also reduce the time required to start selenium up.

    I had previously sent a patch, but it looks like it got dropped. WWW::Selenium creates a brand ne