1

I looked at multiple sources on the web. For example, https://www.guru99.com/handling-cookies-selenium-webdriver.html Nothing works as they describe. After adding cookies with driver.manage().addCookie(ck), you still stay on the login page. Could you, please provide, at least one working example on how to bypass the login screen to speed up the test execution suite in WebDriver Java?

Vladimir
  • 630
  • 3
  • 12
  • 26
  • 1
    I think you want to set Selenium to use a profile that is already logged-in/remembered. It's going to depend on the site's authorization, but some will use sessions cookies which are tied to a profile. – pcalkins Jul 01 '20 at 22:10
  • @pcalkins Could you provide a code sample? Thanks – Vladimir Jul 01 '20 at 22:44
  • 1
    There's a post here about Chromedriver: https://stackoverflow.com/questions/14480717/load-chrome-profile-using-selenium-webdriver-using-java And Firefox here: https://stackoverflow.com/questions/52464598/how-can-i-set-a-default-profile-for-the-firefox-driver-in-selenium-webdriver-3 I don't think you can set one for IE/Edge. – pcalkins Jul 01 '20 at 22:50
  • @pcalkins, I could not find anything about adding cookies to ChromeOptions to bypass login in the links you provided. Could you please elaborate? – Vladimir Jul 01 '20 at 23:24
  • @Vladimir, the point is: 1. create manualy new browser profile 2. open browser manualy and perform login 3. load driver with the new profile. – pburgr Jul 02 '20 at 05:23
  • @pburgr 1. I created a new profile manually in Chrome Version 83.0.4103.116.2. Logged in to the page. 3. Added the new profile to the script. Still stay on the login page. String chromeProfilePath = "C:\\Users\\vladi\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1"; WebDriverManager.chromedriver().setup(); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + chromeProfilePath); WebDriver driver=new ChromeDriver(options); driver.get("http://demo.guru99.com/test/cookie/selenium_aut.php"); – Vladimir Jul 02 '20 at 20:05
  • I created an avatar Tester for the new profile. But when the script opens the login page I see Not Signed In icon. Is that the correct behavior? – Vladimir Jul 02 '20 at 20:51
  • 1
    You have to navigate the driver to http://demo.guru99.com/test/cookie/selenium_cookie.php to check the cookie. – pburgr Jul 03 '20 at 06:42

2 Answers2

1

I misunderstood the process. The sources I used all copy the same error. Thank you to @pburgr for the hint. The correct process is

  1. Login to the site with your username and password to record the cookies into the file.
  2. Open login page to get the domain cookies.
  3. Add cookies from the file to your request and go to the home page bypassing login process. In the code that is available on the web, they go to the login page in step 3 instead of the home page.
Vladimir
  • 630
  • 3
  • 12
  • 26
0

as Vladimir said:

driver.get("http://demo.guru99.com/test/cookie/selenium_aut.php");
//read cookies from file and add it to browser 
driver.manage().addCookie(cookie);
driver.navigate().refresh();
itronic1990
  • 1,231
  • 2
  • 4
  • 18
Brizz009
  • 43
  • 1
  • 5