Search code examples
c#firefoxseleniumfirefox-driver

How to launch multiple instances of Firefox portable using Selenium FirefoxDriver


I use selenium FirefoxDriver in my tests and I run these tests parallel - in each thread is running separated Firefox instance. Everything works fine when I use normal FireFox, but if I want to run these tests with Firefox portable, the first instance launch successful, but second, third, etc... fails with this error:

Your Firefox profile cannot be loaded. It may be missing or inaccessible.

This is how I launch Firefox from code:

var profile = new FirefoxProfileManager().GetProfile("default");
var firefoxBinary = new FirefoxBinary("Path to FireFoxPortable.exe");
_driver = new FirefoxDriver(firefoxBinary, profile);

Any ideas what I am doing wrong? Thanks.


Solution

  • The Firefox driver is trying to launch Firefox using a profile that is already in use. This is not possible as a profile can only be used once. The reason why it appears to be working while launching Firefox manually multiple times is because Firefox will reuse the existing running Firefox process with the already loaded profile.

    Based on this information the solution to your problem is either 1) have the Firefox driver launch Firefox with unique/new profiles, 2) change your code so that only one instance of the Firefox driver is required.

    To launch Firefox with multiple instances, use: firefox.exe -P "My Profile" -no-remote. Do not that the -no-remote parameter should not be used with the first profile launched, which in your case will be the "default" profile. More on this here: http://kb.mozillazine.org/Opening_a_new_instance_of_Firefox_with_another_profile.

    To launch Firefox Portable with different profiles, if the previous commands are not applicable for Firefox Portable, follow the instructions here: http://portableapps.com/support/firefox_portable#second_profile.