Selenium-RC: Using the Perl Client Driver

PerlDoc reference is available

Installing the Selenium Perl Client Driver

In keeping with Perl's philosophy, there is always more than one way to install the Perl Client Driver. For one thing, you can grab Test-WWW-Selenium directly from CPAN. That's probably the easiest way to download and install it.

Another way to acquire the Perl driver is to use the Perl distribution available in the Selenium zip file to install Selenium to your local Perl distribution. You'll need to run Perl on "Makefile.PL" to autogenerate a makefile, and then run "make install" to install it into your Perl distribution. Note that this Makefile is incompatible with cygwin's GNU make; on Windows you should use nmake instead. (Note that nmake comes along with ActiveState Perl; it should already be available in your Perl\bin directory.)

Finally, you don't actually have to install the Perl driver at all; you just need to make sure that its libraries appear in your @INC variable when it comes time to include them. That might mean adding the "lib" directory to your PERL5LIB environment variable, for example.

Using the Selenium Perl Client Driver

Once you've installed the Perl Client Driver in one way or another, you'll need to use its modules. Just as there's more than one way to install the Perl Client Driver, there is also more than one way to use it.

First, make sure you've already started the Selenium Server separately in another process. The Selenium Server should remain up and running throughout this process; you shouldn't need to start/stop it each time you use the Client Driver. (Though, of course, if you need to start and stop the server, you certainly can, just by automatically starting it from the command line.)

If all you want to do is automate a browser, you can just create a new WWW::Selenium, which is full of handy methods that handle your Selenium Commands. You'll need to initialize the object using the hostname and port of the Selenium Server, the browser string to use with "getNewBrowserSession", and the base URL at which we'll start testing. When you're ready to begin, run the "start" method on your WWW::Selenium object; when it's time to close the browser, use the "stop" method. If one of the methods has an error (or if an "assert" command fails) the method will die with a handy error message, which you can wrap up in an eval block if you like. (Be sure to examine the $@ variable after your eval block, to make sure nothing went wrong.)

If you're going to use the driver for automated testing, you may prefer to use Test::WWW::Selenium instead. Test::WWW::Selenium subclasses WWW::Selenium and provides convenient testing functions, suitable for use with Test::More. Test::WWW::Selenium does not require explicit start/stop commands (since these will be handled during test cleanup), and allows you to quickly make any Selenium method a test simply by adding the suffix "_ok" to any Selenium method. Hence, instead of using $sel->click you can use $sel->click_ok to make it a test. In addition, for each Selenium getter (get_title, ...) there are six autogenerated methods (<getter>_is, <getter>_isnt, <getter>_like, <getter>_unlike, <getter>_contains, <getter>_lacks) to check the value of the attribute).

Examples: test_google.t, test_default_server.t.