S_2016
S_2016

Reputation: 1

Browser Session testing with Selenium WebDriver

I have following scenario to automate :

  1. User Logs in to a website. Navigates to a certain page on website
  2. Save the url for that page.
  3. Close browser
  4. Open the browser again and navigate to the saved url.
  5. User should be able to see the page without logging in.

I can automate first 3 steps. But when I open browser again in step 4, a new session is started and my user sees log in page. I believe the web driver browser is in incognito mode. So session cookie is not stored.

Is there any way to automate this scenario using selenium web driver?

Upvotes: 0

Views: 1439

Answers (2)

Shiva Krishna Chippa
Shiva Krishna Chippa

Reputation: 688

You have to quit the webdriver before launching the saved url. At 3rd step write driver.quit(); and at 4th step write: driver.get("<saved_url>");

Upvotes: 0

sunder kandasamy
sunder kandasamy

Reputation: 190

It's because every time when you invoke browser, selenium opens a new browser profile..so your cookies will be lost..

You can inject cookies for the second time..

Cookie ck = new Cookie("name", "value");
driver.manage().addCookie(ck);

Or you can use same browser profile for driver..

FirefoxBinary binary = new FirefoxBinary();  
File firefoxProfileFolder = new File("/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile");
FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
webDriver driver= new FirefoxDriver(binary, profile);

Upvotes: 1

Related Questions