Running Selenium with a Firefox user profile from Eclipse

I am running Selenium tests from Eclipse, but I cannot load the Firefox user profile.

Most sources suggest that I run Selenium Server as follows:

java -jar selenium-server.jar -firefoxProfileTemplate </path/to/template/> 

But when I run my test from Eclipse, it does not use this - the tests will run if the Selenium server is not running.

This thread assumes that I can set the profile in the DefaultSelenium constructor:

Selenium RC - disabling cookie browser

But the code created for me by the Selenium IDE (Firefox plugin) does not use this constructor:

 package com.example.tests; import com.thoughtworks.selenium.*; import java.util.regex.Pattern; public class Example extends SeleneseTestCase { public void setUp() throws Exception { setUp("http://www.example.com/", "*firefox"); } public void testExample() throws Exception { selenium.open("/"); selenium.click("//body"); } } 

Where can I set DefaultSelenium configuration parameters? Or is there some other method that I can use to download my custom Firefox template?

Thanks! Stu

+2
eclipse firefox junit selenium
source share
2 answers

The version of the above code assumes that you run your tests against localhost on port 4444, so it has 2 options in the configuration.

To configure eclipse to run it, you will need to update the launch configuration. It is under

 Run > Run Configurations 

Look for the element that has selenium, and add the above configuration so that when it starts, it picks up and runs.

I personally just start the server when I start working, launching the batch file and killing it at the end of the day.

+1
source share

I made SeleniumTestCase, which starts / stops the server before / after each test class and starts / stops the Selenium instance before / after each test:

 public class SeleniumTestCase { protected static Selenium selenium; protected static AppNavUtils appNavUtils; @BeforeClass public static void setUpBeforeClass() throws Exception { SeleniumServerControl.getInstance().startSeleniumServer(); } @AfterClass public static void tearDownAfterClass() throws Exception { SeleniumServerControl.getInstance().stopSeleniumServer(); } @Before public void setUp() throws Exception { // Replace "*chrome" with "*firefox" for Selenium > 1.0 selenium = new DefaultSelenium("localhost", 5444, "*chrome", "http://localhost:8080/"); selenium.start(); appNavUtils = new AppNavUtils(selenium); } @After public void tearDown() throws Exception { selenium.stop(); } } 

SeleniumServerControl starts and stops the server:

 public class SeleniumServerControl { private static final SeleniumServerControl instance = new SeleniumServerControl(); public static SeleniumServerControl getInstance() { return instance; } private SeleniumServer server = null; protected SeleniumServerControl(){} public void startSeleniumServer() { if (server == null) { RemoteControlConfiguration rcc = new RemoteControlConfiguration(); rcc.setPort(5444); //rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate) server = new SeleniumServer(rcc); } server.start(); } public void stopSeleniumServer() { if (server != null) { server.stop(); server = null; } } } 
+2
source share

All Articles