Actual Selenium with old Firefox 47.0.1

Jump to: navigation, search

It's possible to use current versions of Selenium (3.x right now, the very same used with Chrome and other browsers) against old versions of Firefox (47.0.1), here you will learn a little bit about why this version is so important, and how to enable your testing infrastructure to be able to use it. Be warned that this is an interim situation until the new Mozilla's alternative is ready for us (read below).

Brief history

Selenium (Selenium Standalone Server) historically has worked with its own (bundled) firefox-driver and plugin to control Firefox. But that stopped working with Firefox 48. Since that version Marionette and GeckoDriver (basically Mozilla's own controller and driver) became the default option. Main problem is that such a new and nice combination (really similar to the approach followed by Chrome, with its own driver) is still incomplete, missing some parts of the webdriver specification required to allow our behat tests to run ok with them.

So, we decided to keep using the old (2.53.1) version of Selenium with the old (47.0.1) version of Firefox until Mozilla's stuff was ready for us. And that has worked acceptably ok.

Problems (or complications) started to arrive when other browsers started to request newer versions of Selenium in order to continue working (specifically Selenium 3.x versions). That automatically implied that we had to have really different versions of Selenium to be able to test in different browsers.

But, recently, we discovered that the new versions of Selenium can be configured to stop using the Marionette / Gecko-driver stuff and, instead, continue using the old (bundled) driver with Firefox. So just one Selenium (3.x) version to root all the browsers (Firefox and Chrome), yay one less dependency.

But, as said, it comes with a cost. It needes to be explictly configured that we don't want to use marionette. And here it's how to achieve that in various, alternative, ways (tl;dr. it's always about to add the
'marionette' => false
extra capability to the behat profile being used. Let's see them:

Direct edition of behat.yml

Find the behat.yml file within your site's moodledata and define a new profile (called here "firefox_no_marionette" for better understanding it). It should look like:

firefox_no_marionette:
  extensions:
    Behat\MinkExtension:
      default_session: goutte
      goutte: null
      javascript_session: selenium2
      selenium2:
        browser: firefox
        capabilities:
          extra_capabilities:
            marionette: false

(note that you must perform this everytime that behat init.php is executed, as far as it's 100% rewritten. For persistent solutions, look to the 2 solutions below)

Using $CFG->behat_profiles

You should define a new profile (called here "firefox_no_marionette" for better understanding it). It should look like:

$CFG->behat_profiles = [
    ....
    ....
    'firefox_no_marionette' => [
        'browser' => 'firefox',
        'capabilities' => [
            'extra_capabilities' => [
                'marionette' => false,
                "binary" => "/Applications/Firefox.app/Contents/MacOS/firefox-bin",
            ],
        ],
    ],
    ....
    ....
];

Using $CFG->behat_config

You should define a new profile (called here "firefox_no_marionette" for better understanding it). It should look like:

$CFG->behat_config = [
    ....
    ....
    'firefox_no_marionette' => [
        'extensions' => [
            'Behat\MinkExtension' => [
                'default_session' => 'goutte',
                'goutte' => null,
                'javascript_session' => 'selenium2',
                'selenium2' => [
                    'browser' => 'firefox',
                    'capabilities' => [
                        'extra_capabilities' => [
                            'marionette' => false,
                        ]
                    ],
                ]
            ]
        ]
    ],
    ....
    ....
];

Once you've defined the new "firefox_no_marionette" profile... you will be able to execute behat normally, but adding
--profile firefox_no_marionette
and, magic... your new (3.x) Selenium will be able to handle the old (47.0.1) Firefox perfectly (in fact it does it better than older (2.x) versions of Selenium. Yay!