Reputation: 836
I am automating test cases for an application which requires an authentication to launch homepage. I am using below code to make it work.
String url = "http://i.user:i.password@baseURL_1/home";
driver.get(url);
Once I am inside the application , there is another link called "workflow" , clicking on which opens another application of same system. i.e. it redirects to http://baseURL_2/home.
While opening page from second application , browser(Chrome) authentication window re-appears. How do I handle it in automation script?
Upvotes: 0
Views: 747
Reputation: 103
var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("username", "password");
alert.Accept();
Upvotes: 0
Reputation: 407
Try below code :-
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
Upvotes: 1
Reputation: 287
I see you've tried to pass the username and password within the URL. I had a similar issue a while back, the resolution for me was to whitelist my IP, this means the website wont request a username and password when you visit.
Hope this helps.
Upvotes: 0