We recently migrated our selenium script from Selenium 3.141.x and JDK 1.8 to Selenium 4.18.1 and JFK 17.
In our web application, we use multiple role with each role has a seperate username and password for login into application.
In our Selenium 3.141.x we use to send the username and password in the URL as below to login into specific roles.
driver.get("https://username:[email protected]/");
This works fine and few scenario, where we cannot pass the username and password in URL, we have used Robot class to enter the credentials details in the popup.
As we are migrating the script from Selenium 3.x to Selenium 4.x version, we want to use the HasAuthentication option and do not want to pass the username and password in the URL.
Now, manually when I try to open the URL in chrome browser, it opens with "FAAdmin" user, even when password is not stored in chrome browser [really not sure].
Below is the code.
// in a propertyfile we have storied the username and password in Encrypted text
// It's get decrypted at run time.
String propertyUserName = EncryptedURL.getUserName(environment, userrole");
String propertyPassword = EncryptedURL.getUserName(environment, userrole");
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "CHROMEDRIVER_PATH";
ChromeOptions cOptions new ChromeOptions();
cOptions.addAguments("--disable-setuid-sandbox");
cOptions.addAguments("--disable-web-security");
cOptions.addAguments("--ignore-certificate-errors");
cOptions.addAguments("--allow-running-insecure-content");
cOptions.addAguments("chrome.switches","--disable-extensions");
cOptions.addAguments("--incognito");
driver = new ChromeDriver(cOptions);
driver.manage().deleteAllCookies();
driver.manage().timeouts.pageLoadTimeout(Duration.ofSeconds(180));
((HasAuthentication) driver).register(
uri -> uri.getHost().contains("enteprise.sok.dev")
() -> new UsernameAndPassword(propertyUserName, propertyPassword);
driver.manage().timeouts.maximize();
driver.get("https://environmentname.enterprise.sok.dev/");
Now above code works fine as long as browser is opened in "incognito" mode. It's opening with the username and password we pass in function UsernameAndPassword(propertyUserName, propertyPassword);
Now in above code if i comment the line "cOptions.addAguments("--incognito");", then in normal browser mode, it's not using the username and password we pass in function UsernameAndPassword(propertyUserName, propertyPassword); , but it uses the default username "FAAdmin".
*// cOptions.addAguments("--incognito");*
Our organization is a financial institution and downgrading of chrome browser version is not a option. We have to use Chrome version 122 [mostly latest stable version].
Browser doesn't have any password stored, but still manually also, it's login with default user "FAAdmin"
Couple of question,
In normal mode, it's using default credentials and not username and password we pass in UsernameAndPassword(propertyUserName, propertyPassword). How to make script to the credentials when we pass in normal code. Script works fine when opened in "incognito" mode.
In chrome settings > Autofill and passwords > Password section, we have not stored any password, whole section is blank, again when we open the url, it's login with "FAAdmin" user. where are user details come into picture.
JDK: 17 Maven dependency used:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-devtools-v122</artifactId>
<version>4.18.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.18.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.18.1</version>
</dependency>
