1nickt has asked for the wisdom of the Perl Monks concerning the following question:

Learned brethren,

I have installed Selenium::Firefox on my linux machine. I have also installed the Firefox browser, geckodriver binary and Xvfb so Firefox can run pseudo-headlessly and a Selenium server is not required. I am trying to run the simplest test script:

use strict; use warnings; use feature 'say'; use Carp::Always; use Selenium::Firefox; my $driver = Selenium::Firefox->new; say 'Binary mode: ' . $driver->binary_mode; $driver->get('http://www.google.com'); say $driver->get_title; $driver->shutdown_binary; __END__
The module appears to behave as documented in so far as it finds and launches the relevant binaries, according to the process table:
vagrant 1885 00:03 /usr/local/sbin/geckodriver --port 9090 --m +arionette-port 2828 --binary /usr/lib/firefox/firefox.sh vagrant 1890 00:02 /usr/lib/firefox/firefox --marionette --pro +file /tmp/rust_mozprofile.Bezoxqxkgze8 vagrant 1933 00:01 /usr/lib/firefox/plugin-container -greomni +/usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -a +ppdir /usr/lib/firefox/browser 1890 true tab
But it just hangs then throws an exception when I run it with:
DISPLAY=:42 perl test/selenium.pl
I get the following error:
Could not create new session: at .../lib/perl5/Selenium/Remote/Driver +.pm line 428.
Working back using the stack trace as a map I found that the code for creating a session in Selenium::Remote::Driver is executed regardless of condition from within BUILD. I can't see any place where that is overridden by the class that extends it (Selenium::Firefox), even though use of that class should by definition rule out a session with the Selenium server.
if ($self->has_desired_capabilities) { $self->new_desired_session( $self->desired_capabilities ); } else { # Connect to remote server & establish a new session $self->new_session( $self->extra_capabilities ); }

I confess I am a bit lost a this point. Thanks for any tips!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: Selenium::Firefox (on Linux): create session error, but why? (SOLVED)
by 1nickt (Canon) on Mar 28, 2017 at 14:02 UTC

    To solve this problem I downgraded to the previous version (v.14) of the geckobinary. v.15 seems to be incompatible with the rest of my environment (Ubuntu 14.04, Firefox 52.0.1).

    Script above now outputs:

    Binary mode: 1 Google
    Note however, that Selenium::Firefox does not successfully terminate the Firefox process with shutdown_binary() (only the geckodriver process), so each time you call new() you will be left with a running Firefox instance until you kill it manually. This problem appears to be similar to one discussed here.


    The way forward always starts with a minimal test.