2

I'm using Selenium and Java to automate tests.

When opening the page under test, Chrome performs basic authentication (prompts for username/password). However, authentication should be solved on the domain level.

When opening the browser manually, I'm not prompted for credentials.

I tried to force Chrome to use the default profile with following ChromeOptions:

ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir=C:\Users\my-username\AppData\Local\Google\Chrome\User Data\Default");

But no luck. What am I doing wrong?

3 Answers 3

1

Selenium can be flaky with auto authentication.

The simple solution is you're better off just altering the URL to include it.

e.g. https://username:[email protected]

0
1

To add to the answer by @Klynt, although this is a solution, this is deprecated for browsers like firefox and chrome. In this approach, you don't really have expose your credentials. You can store your credentials as environment variables or in your .bashrc and export the same in your test.

There is another approach as well, but you might need to downgarde the version of webdriver you are using. I am not sure of the exact version (may be 3.1x), there is an API withCredentials(user, pass) that you can use to perform basic auth.

1

I can't comment yet on this forum so some feedback on @Klynt and another suggestion I have found as I'm facing the same issue..

  • While on Chrome and Firefox including the credentials works, this is not recommended. Also this does not work in IE. (no idea about Edge or Safari)

  • The solution I found so far is you can use a script (autoIt) which you can call in your test after you opened your URL. In this script you can define which keys to send to the window asking you for your credentials.

So far that is the only solution I have found (other then making changes in the registry)..

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.