Search code examples
seleniumselenium-rc

How do you reuse cookies between SeleniumRC sessions?


I'd like to run Selenium-RC and have it remember the cookies saved from the last time it was run. Is this possible?


Solution

  • Selenium server starts new profile for browser everytime, so your saved cookies and bookmarks do not exist on this profile.

    First create a profile, for firefox it is given here

    then bundle this profile to your selenium server like this

    SeleniumServer server = new SeleniumServer();
    RemoteControlConfiguration rcc = new RemoteControlConfiguration();
    //rcc.setPort(4444);
    File newFirefoxProfileTemplate = new File(ReadConFile.readcoFile("fiefoxProfilePath"));
    
    rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate);
    server = new SeleniumServer(rcc);
    server.start();
    DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome",ReadConFile.readcoFile("serverName"));
    

    to know your firefoxTemplate click this

    After doing this, manually open browser for this profile and save your cookies, bookmarks , certificates(very helpful for https).