How to handle basic authentication for test automation in Selenium Java?
Hey Yanisleidi!
To handle basic authentication for Java automation testing with Selenium, you can include the below snippet in your test script -
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();
driver = augmenter.addDriverAugmentation("chrome", HasAuthentication.class,
(caps, exec) -> (whenThisMatches, useTheseCredentials) -> devTools.getDomains().network()
.addAuthHandler(whenThisMatches, useTheseCredentials))
.augment(driver);
((HasAuthentication) driver).register(UsernameAndPassword.of("foo", "bar"));
Also, you can check the below GitHub repo that can help you handle basic authentication -