Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (38 sloc) 1.99 KB
layout title date excerpt categories
post
WebDriverJS: Firefox profile
2016-12-01 23:55:00 -4000
How to set the Firefox profile path when working with WebDriverJS (Selenium for Node.js).
webdriverjs firefox nodejs javascript selenium

Let's go over how to set the Firefox profile for WebDriverJS (Selenium for Node.js).

Prerequisites

You need Firefox and geckodriver installed. (You can follow this video if you're on a Mac.)

Given you have homebrew installed, you can run the following:

# install the browser
$ brew cask install firefox

# install the driver
$ brew install geckodriver

Building your driver

Now you want to build your driver. See how it's done [here]({% post_url 2016/2016-11-25-webdriverjs-launch-browser %}).

Firefox options

Before instantiating the driver, you want to set the profile in Firefox options:

const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options();
// replace `/path/to/profile`
options.setProfile('/path/to/profile');

Unlike [ChromeDriver]({% post_url 2016/2016-11-27-webdriverjs-chrome-profile %}), the profile must be valid otherwise the driver will fail to build. To create and manage Firefox profiles, see the official documentation.

Update the builder so WebDriverJS launches Firefox based on the specified profile:

builder.forBrowser('firefox');
builder.setFirefoxOptions(options);

To confirm the profile is correct, you can check the path if you go to about:support:

const driver = builder.build();
driver.get('about:support');