Friday, October 19, 2018

Selenium Firefox (v2) - Test an Invalid User in Auth dialog on Application

I am trying to test how my web application handles an invalid user attempting to log in.

My Spring Security Application displays a Basic Authentication dialog (launched from the server side) before allowing the User to continue access into the web application (and render on client side). This dialog has only username and password fields.

I can't code lines that would enter the username and password into this authentication dialog. Thus, I followed a similar method like the solution given here:
http://www.tothenew.com/blog/easy-approach-to-handle-authentication-window-in-selenium-webdriver/

With a valid username and password, this code works and doesn't break my tests nor stops my test suite. However, with a an invalid username and password, this code does NOT work and breaks my testing. Specifically, the authentication dialog remains open (or displayed) in front of an open browser. I don't even know how to close this authentication dialog. How do I click 'Cancel' or 'OK' on this authentication dialog?

So, this is the problem I'm trying to solve.

I googled "selenium test invalid user in authentication dialog". From the results, I opened this StackOverflow article.
https://stackoverflow.com/questions/11522434/how-to-handle-login-pop-up-window-using-selenium-webdriver

From this StackOverflow article, there's a comment that led me to google "selenium firefox switch to alert". I see there's information on using Selenium to handle pop-up dialogs. Nice!

https://www.guru99.com/alert-popup-handling-selenium.html
https://stackoverflow.com/questions/30064528/java-selenium-firefox-driver-driver-switchto-alert-hangs-on-alert-dialo
So, I tried this and nothing from this article worked.

Further research, and I found these articles.

https://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java
This article has some comments which mention the use of Alert.authenticateUsing(), but seems that not all Drivers have this alert or method. At least, I didn't see it here:
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/Alert.html

So, I googled "selenium firefox alert authenticateusing" and then read this article:
https://sqa.stackexchange.com/questions/25769/authentication-acting-as-alert-not-as-window
I tried this code, but this gave me the following error.
Error: NoAlertPresent No alert present (WARN...)
I realize this code didn't work because it's for Selenium 3 and I am using Selenium 2.53.

So, let's look into this article.
https://www.softwaretestingmaterial.com/handle-authentication-popup-window/
This article also did not help because I need to first resolve the issue with my driver not finding the alert dialog (i.e. authentication dialog).

Trying this article:
https://stackoverflow.com/questions/48823661/how-to-switch-to-window-authentication-popup-and-enter-credentials
Also, not helpful.

Trying this article:
https://sqa.stackexchange.com/questions/2277/using-selenium-webdriver-with-windows-authentication
This referenced article is great due to the author's explanation of using the Firefox add-on AutoAuth with steps to implement this solution.
http://www.codemiller.com/blog/2011/05/28/overcoming-auth-pop-ups/

Next, trying this article:
https://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium
This also didn't provide a solution that I needed. Not for Selenium 2.

I guess I will just need to upgrade my Selenium version.

No comments:

Post a Comment