- You can follow the instructions provided at: https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
- Give the profile a name we can refer in the next steps. E.g.
selenium
- Create the profile in the default localtion (keep in mind the location for the next steps).
- In OSX, the profiles are located at
~/Library/Application Support/Firefox/Profiles
. Find where they are in your operating system. - In the profiles folder you will find the profile you just created, for this case we will use the folder name
hcqx24zh.selenium
. - Copy the profile to a folder called
firefox
in a given location. E.g.:
mkdir /tmp/firefox/
cp -r ~/Library/Application Support/Firefox/Profiles/hcqx24zh.selenium /tmp/firefox/
- In the
/tmp/firefox
folder, create a text file calledprofiles.ini
, with the following content:
[General]
StartWithLastProfile=1
[Profile0]
Name=selenium
IsRelative=1
Path=hcqx24zh.selenium
- This file is needed because Firefox will use it as a reference to know which profiles exist. So even if the profile is present but the file is not, Firefox won't be aware of the profile.
In short, we will mount a volume using the /tmp/firefox
folder to a specific path in the container. In addition, we will use the JAVA_OPTS
configuration option to pass the Firefox profile name.
Note that when passing the option -Dwebdriver.firefox.profile
to Selenium Grid, the specified value must be the profile name, not the path. In this case, it will look like this: -Dwebdriver.firefox.profile=selenium
.
There is a small issue with docker, we cannot pass an env var like this: JAVA_OPTS='-Dwebdriver.firefox.profile=selenium'
. We get the following error (even when trying without quotations or with double quotations):
docker: Error parsing reference: " " is not a valid repository/tag: invalid reference format.
See 'docker run --help'.
Therefore, we export the env var first and then we use it in the docker run
command.
export JAVA_OPTS=-Dwebdriver.firefox.profile=selenium
(If there is a different way to do this, please let me know).
Now we can start the container (using the Firefox Standalone debug here, but it can work with the other Firefox images):
docker run --rm -p 4444:4444 -p 5900:5900 \
-v /tmp/firefox:/home/seluser/.mozilla/firefox \
-e JAVA_OPTS selenium/standalone-firefox-debug:3.4.0-chromium
What happens there, is that the folder where the custom profile is, gets mapped to the folder where Firefox looks for the existing profiles. When Firefox finds the profiles.ini
file, it notices the file and the profiles described in the file.
That's it, the tests should run with a Firefox custom profile run in docker-selenium.
Create the custom profile and the profiles.ini
file, then build the docker-selenium image on your own including these files in the expected folder (/home/seluser/.mozilla/firefox
), and start the grid/node with the -Dwebdriver.firefox.profile=selenium
option.
- I might have missed some Firefox configuration options that could make this process easier. If you find them, we can update this small document.
- I noticed that the profile stores paths relative to your machine/OS. In my case, I created a custom profile in OSX and it was being used in the docker-selenium container (Ubuntu), and some options I configured were not present due to this. So better double check that the options are there or just create the profile in an Ubuntu machine.
As an alternative I created a Firefox profile and created a tar archive
ff_profile.tar.gz
. I also created aprofiles.ini
file like in the example above and modifiedentry_point.sh
like thisjava ${JAVA_OPTS} -Dwebdriver.firefox.profile=seluser -jar /opt/selenium/selenium-server-standalone.jar \
by adding the java option selecting the user profile.
Then I built a custom image using Dockerfile including these lines
This was tested in the grid with
selenium/node-firefox:3.0.1
as source image.