0

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?

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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>");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.