Search This Blog

Wednesday, May 19, 2010

How to run test cases in specified browser profile

Selenium creates a new and clean profile each time it runs a test, so it won't keep any cookies of the previous session and it wont use any browser plug-in however you can force selenium to use your own profile.

1. Close all instances of firefox browser.
2. Create a new firefox profile : Go to Run and type firefox -p and press OK . This will open a dilog bod where you create new firefox profile, have a name "nk" and save it in C: drive.
3. Start the browser: Go to run and type firefox -p that will open a dialog box. Select the profile "NK" which you created in the 2nd step.
4. Install all plug-ins in this profile ; like SSL security bypass

5. Now you write you test cases like below

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;
import com.thoughtworks.selenium.*;

public class firefoxprofile extends SeleneseTestCase {

private SeleniumServer seleniumServer;
private Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS="60000";

public void setUp() throws Exception {

File template = new File("C:\\nk");
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "");


public void googling() {"/");
selenium.type("q", "");"btnG");

public void tearDown() throws InterruptedException{



  1. My test remembers its cookies and information when I am running tests using *iexplore. How do I start new IE session without remembering old cookies and information?


  2. I believe selenium starts a new and fresh browser session every time a test runs.
    But if you use your profile then all adons will be there to assist you for your testing.

  3. Niraj, You have a lot of really good tips here. Thanks for sharing.
    I tried this one without success however. I created a new profile and set the user_agent. I then launched and expected to see the string i enter (which would indicate it found the correct one). It did not work. Have you successfully changed user agent?

  4. My bad Niraj. I got it working. The problem was that I used the name of Profile when I created it rather than the name of the file as Firefox saved it. Many thanks for these tips. Keep them coming.

  5. Niraj: I found this post very useful. I appreciate it for sharing this trick. BTW, is there a way to avoid the adons pop-up everytime the profile template is loaded?. I am afraid it might interfere with multi-window actions. Thanks!.

  6. Thanks Niraj for the helpful tips. Do you have the same instructions for linux?

  7. mild infections can be vulcanized with this and you lodge to your decision to bring around yeast infection naturally,
    you are on the proper way to get rid of it for
    a retentive time period of sentence.

    my weblog: yeast infection in toddlers

  8. Hi Niraj,

    I have a problem with Facebook API,while running test script it hits log in with Facebook user button then Facebook API pop up window appears, It enters user id, password and clicked on log in button, i am getting Facebook API pop up White blank and not redirected. I am using selenium RC. Let me know any solution for this please help me.

    Thanks& Regards
    Satya Ranimekala

  9. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.

  10. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai