code and design reflected in occasionally coherent words

Article Search:

February 27, 2010

Selenium and Perl = tears of joy

  • Tim Brockman
  • @ 2:38 pm
Filed under: Foo+Design+Code,SEO+SEM+SMO — Tags: , , , ,

Selenium IDE + Selenium RC + Perl's WWW::Selenium is teh GG and I am compelled to share. For dankey's years I've been scraping, and crawling, and spidering, and mashing. For most basic stuff, w/o a good API, cURL works. Sometimes I need to get my LWP on or even Mech. I've even stooped to building some visual basic tools for a quick fix ie only solution. That stuff is great, until you run into another smelly .turd some government contractor 150+k salary fool made the big bucks for dropping on the web, you know the type with bad ajax, improperly closed tags, sketchy IRIS implementation, that your browser magically figures out what to do with, even though the markup is all over the place and thank god you don't need to follow their sloppy .asp.

Long ramble short Perl (or java, py, ruby, php, etal) + Selenium can turn that turd into a fertile land scrape of milk and honey, or something you can QA test the shit out of... until the IT guy thinks the Chinese are attacking his server. In fact it makes it so freakin' easy that I feel my magic special old school  knowledge fossilizing into who cares, but who cares.

In short this is the tool of choice for efficient/rapid quality assurance and testing for your web app, even if its AJAX y or Javascript aculious or whatever.

So here's the quick and magical step by step...

I won't tell you how to get Perl up on your system, Strawberry Perl is good as is Active State's offering. You can use cpan to install WWW::Selenium and whatnot. Perl is my language of choice to interface with the Selenium RC because of its skills with the words.

Selenium IDE is easy... the steps are download and install. SeleniumHQ has good docs for this.

Selenium RC for Windows can be a bit more trouble but you need it for WWW::Selenium to interface with, so here's that...

  1. Download and install the latest version of Java SE from http://java.sun.com/javase/downloads/index.jsp.
  2. Download the latest version of Selenium RC from http://seleniumhq.org/download/
  3. Extract them wherever is convenient for you... I'll use the c: drive as example.
  4. Open a Command Prompt and navigate into the selenium-server-1.0.1 folder.. (for me as I extracted into the selenium-rc folder directly on the c: drive) the process is as follows:
    • cd \
    • cd selen*
    • cd selenium-server*

    ...which brings me to the directory c:\selenium-rc\selenium-server-1.0.1\

  5. Once you find your way into the selenium server directory you will find the selenium-server.jar file, you want to run this command:
    • java -jar selenium-server.jar -interactive

    a bunch of stuff will fly by ending with a message Entering interactive mode...
    type Selenium commands here (e.g. cmd=open&1=http://www.yahoo.com)

    --If you do so you'll get probably some initiate session failness so instead try
    cmd=getNewBrowserSession&1=*chrome&2=http://www.yahoo.com if browser windows pop up and some success messages fly by ending in Got result: OK on session 132gobl3d13g00k time for popin the highlife and celebrating. If you upgraded to Firefox 3.6.x then you may fail; no worries ...the fix is addressed at the bottom with the big words

  6. In the future you may not need the -interactive mode for command line commands to the RC/Server or you may want a .bat file to launch stuff for you, but I'll leave that to your discretion.

Problems with some error about deleting ..\parent.lock when using *chrome or Firefox browsers are caused by Firefox 3.6 update.

So as a special bonus I fixed the file for Selenium-RC's Selenium-Server-1.0.1. This is a small problem caused by the update to Firefox 3.6.*... the current (1.0.1) version of selenium server does a version check for Firefox 3.5.*. I offer the file itself because I don't want to get into the how to of  breaking down and editing the jar file and then repacking it. (if you do look for 3.5.* in all the ff/chrome .rdf's and change em to 3.6*) ala QAAutomation.

Download my fixed selenium-server.jar file (until seleniumhq figures this out/releases a new version). Stop your current version of selenium server, rename your old version of selenium-server.jar and replace it with mine (or yours if you have the jdk and fixed the version check thing). Try the step 5 command again and things should work.

At any rate have fun...

4 Comments »

  1. Oh yeah!

    Brockman the rockman FTW!

    Thanks for providing the edited .jar file.

    I really appreciate that!

    BC

    p.s. and I would have to totally agree with you: Perl + selnium is an awesome combo! :)

    Comment by Bryan C — April 15, 2010 @ 2:26 am

  2. Hi,

    Please check the patched selenium-server.jar. It seems to be corrupted.

    Thanks.

    Comment by dmitry — April 20, 2010 @ 4:51 am

  3. Hi,

    Can this setup be done on a linux box.

    Comment by sri — April 15, 2011 @ 5:26 am

  4. It will be great if i cud get some test case specific example using selenium rc and perl.
    Can some one help

    Comment by sri — April 15, 2011 @ 5:27 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

...