http://www.perlmonks.org?node_id=809138


in reply to Re: Using WWW::Selenium To Test Or Automate An Ajax Website
in thread Using WWW::Selenium To Test Or Automate An Ajax Website

icleave,
Are you running the Selenium core? You need to have Selenium running before you can use the Selenium Remote-Control (driven by WWW::Selenium. It should be along the lines of (from memory and likely off a bit):
java --jar selenium-core.jar

You can verify that you have something listening on port 4444 by doing a netstat -an | grep LISTEN | grep 4444. If you don't see anything then you haven't properly started Selenium.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Using WWW::Selenium To Test Or Automate An Ajax Website
by bart (Canon) on Nov 17, 2010 at 08:51 UTC
    Nowadays, it is (apparently) recommended to use Selenium RC server instead — Selenium Core is no longer maintained. You can download it from http://seleniumhq.org/download/.

    To run it, do

    java -jar selenium-server.jar

    Make sure to use a recent enough version of Java, it fails here with java 1.4.2 but it works with 1.6.0.

Re^3: Using WWW::Selenium To Test Or Automate An Ajax Website
by icleave (Initiate) on Nov 25, 2009 at 11:16 UTC

    Ty Limbic~Region for the post. I wasn't aware I needed to run the Selenium core. I did try running $netstat -an | grep LISTEN | grep 4444 and it didn't do anything so I figured I really didn't have the Selenium core.

    I tried running the $java --jar selenium-core.jar suggestion from my terminal but I got the following error:

    Unrecognized option: --jar Could not create the Java virtual machine.
    I guessed you meant "-jar" rather than "--jar" so I retyped the command at the terminal but I got the following:

    The program 'java' can be found in the following packages: * gij-4.3 * java-gcj-compat-headless * openjdk-6-jre-headless * cacao * gij-4.2 * jamvm * kaffe Try: sudo apt-get install <selected package> bash: java: command not found

    So I tired "sudo apt-get selenium-core" hoping this would work but it didn't. So the next thing I did was try searching the Synaptic Package Manager with no luck. I then googled and found http://release.seleniumhq.org/selenium-core/1.0.1/selenium-core-1.0.1.zip. I downloaded it and extracted but I couldn't make heads or tails of what to do next after reading the 'install-readme.txt.'

    Any advice on how I actually install Selenium core on Ubuntu? All my other searches for information on this didn't result in anything I could use.

    Also assuming that I get Selenium core running, is there any code I need to know about to "start" the Selenium core? I can't remember where I read it, but I read that you need the following code in your perl program:

    $sel->start();

    If so, where do I put it? I put it in my program here:

    my $sel = Test::WWW::Selenium->new( host => "localhost", port => 4444, browser => "*chrome", browser_url => "http://www.example +.com/" ); $sel->start(); $sel->open("/home/index.jsp");

    Did I get this code position correct?

    Many thanks for the help!

      icleave,
      Any advice on how I actually install Selenium core on Ubuntu?

      There really isn't anything to install. You just download the jar files and run them. Looking at the error message you got, I would guess you don't have Java installed. You need to install Java to run Selenium. WWW::Selenium is a perl interface to Selenium Remote Control only.

      Did I get this code position correct?

      Yes. You should always check the SYNOPSIS in TFM which shows you the typical usage.

      Cheers - L~R

        Thanks for the tips! I finally figured it all out except for the class path stuff (I have no idea how to create a java classpath to the .jar file) but I eventually experimented until I figured out that I can run one terminal running selenium rc and open another terminal and run my perl code from that.

        Low and behold my perl code comes to life and firefox loads up... only to die time and time again with a popup box that loads when you click 'login' on the website I'm trying to automate access to. After spending a whole day learning about how you need to select the popup box and close it, then select 'null' to get back to the original browser window I just can't seem to get my perl/selenium code to do what I want. The main issue is that upon clicking the 'logon' link at the website I'm trying to automate access, it is random event where by:

        1. No popup box pops up, or
        2. A popup box named 'stealth' pops up, or
        3. A popup box named 'entry' pops up.

        I found that selenium is very fragile when it comes to coding the next step for it to preform... if I run my code without any mention to a popbox then everything is fine, but when I run the code and a popup box happens then it dies with a "255" exit message. Looking around the options in the IDE I couldn't see any program flow commands for selenium IDE so after going to the selenium website it seemed to me that program flow must come from the coding language you are using.

        So I thought, ok, Perl has program flow commands, why not use the "if" statement and "elseif" and "else" for all three possibilities:

        1. no popup
        2. popup "stealth"
        3. popup "entry".

        I coded it up as best as I could in Perl but then I got syntax errors where my blocks where. I was under the impression that something like $sel->title_is("Entry") would give perl a 'true' or 'false' and operate the program flow accordingly. Please help, I'm quite confused, a sample of the code is below:

        my $sel = Test::WWW::Selenium->new( host => "localhost", port => 4444, browser => "*chrome", browser_url => "http://www.example +.com/" ); $sel->start(); $sel->set_timeout("60000"); $sel->open("/home/index.jsp"); $sel->click("link=Log in"); $sel->wait_for_page_to_load("60000"); if ($sel->title_is("Entry")) { $sel->select_window("entry"); $sel->close(); $sel->select_window("null"); } else ($sel->title_is("Stealth")) { $sel->select_window("stealth"); $sel->close(); $sel->select_window("null"); } $sel->click("emailAddress"); $sel->type("emailAddress", "anon@anywhere.com"); $sel->click("password"); $sel->type("password", "password"); $sel->click("remember"); $sel->click("subButton"); $sel->wait_for_page_to_load("60000");