0

I wanna run my test cases in headless mode, and I picked HtmlUnit is the way to achieve my requirement. But, the initial page where I need to handle windows based authentication box, and based on valid authentication it will take me to summary page of my application. We can able to handle the window based pop up by using Robot class, or AUtoIT but I'm not sure how that handled in headless mode. Can somebody help me on this? How do I bypass the authentication window in headless mode. I surfed and found there was some solution by using https://username:password@url, but it doesn't help me to fix my issue.

Note : I'm using Selenium JAVA libraries.

imBollaveni
  • 99
  • 1
  • 13
ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84
  • Possible duplicate of [How to handle authentication popup with Selenium WebDriver using Java](https://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java) –  Oct 06 '17 at 03:52
  • Possible duplicate of [Selenium - Other way to basic authenticate than via url](https://stackoverflow.com/questions/45345882/selenium-other-way-to-basic-authenticate-than-via-url) – undetected Selenium Oct 06 '17 at 06:45
  • Actually those fixes only for firefox, and chrome. I tried those but it's not working for HtmlUnit (Headless browser execution). The question is how to accept the authentication in headless mode using htmlunit. – ArrchanaMohan Oct 06 '17 at 07:22
  • Possible duplicate of [How do I handle authentication with the HtmlUnitDriver using Selenium WebDriver?](https://stackoverflow.com/questions/11242723/how-do-i-handle-authentication-with-the-htmlunitdriver-using-selenium-webdriver) – imBollaveni Oct 06 '17 at 08:35
  • I already tried to @override the newWebClient(), and modifyWebClient but unfortunately nothing resolve my issue. – ArrchanaMohan Oct 06 '17 at 09:09
  • 1
    check it once. u can use chrome as headless browser https://stackoverflow.com/questions/45790062/limitation-of-htmlunit-driver-for-headless-testing?rq=1 – imBollaveni Oct 06 '17 at 13:36
  • Its really helpful one. I will try, and post my updates. – ArrchanaMohan Oct 09 '17 at 05:00
  • ok Sure @arrchanaMohan – imBollaveni Oct 09 '17 at 08:22
  • The script is running as headless browser mode now in chrome. But, It doesn't accept the window authentication js submit form. I used Keypress and release methods from robot class file in java. But no luck. – ArrchanaMohan Oct 09 '17 at 17:18

1 Answers1

0

You can do it by using following code in selenium webdriver:

var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("username", "password");
alert.Accept();
  • Many thanks for helping me to resolve this issue. I'm using java libraries, and I didn't find any setAuthenticationCredentials() in JAVA library. – ArrchanaMohan Oct 06 '17 at 05:06