I am trying to run selenium web driver(Firefox) test cases which will need a single sign on (web). Issue over here is i have to sign in manually with my OTP every time i tear down the test case. So i will have to enter my username, password and OTP(second password which is generated dynamically), which obvious is very tedious for hundreds of test cases. Any reference or suggestions to deal SSO with web driver would be of help!

Thanks in advance.

  • 1
    Welcome to SQA, Reddy. The programmer who solves the pop-up dialog problem in Selenium once and for all will be a king among testers. In the mean time, have you tried searching this site for "Selenium authentication".
    – user246
    May 31, 2012 at 12:30

1 Answer 1


This question comes up a lot. Here is a possible solution, but it will require some additional development. You could use a customized HTTP proxy that acts as a pass-through filter except when it sees an HTTP 401 response. In the latter case, the proxy would respond with authentication credentials of your choosing.

Here is how you might do it, in steps:

  1. Find an HTTP proxy that you can modify in whatever language you use for your test. For brevity, I will assume you are using Java, so you want an HTTP proxy written in Java. (See https://stackoverflow.com/questions/860362/write-http-proxy-in-java for more details on open source, Java, HTTP proxies.)
  2. Presumably you have some means of determining second, dynamically-generated password, and the details of that are not important. I will call that mechanism the "OTP oracle". You need to write a Java method that can ask the OTP oracle for the next OTP.
  3. Modify the HTTP proxy to respond to 401 responses by asking the OTP oracle for the next password and responding back to the server with a new HTTP request with the appropriate credentials.
  4. Embed the HTTP proxy in your test, i.e. code your test so that at start-up, it launches the HTTP proxy in a separate thread.
  5. Tell Selenium to launch the browser so that it uses your HTTP proxy.

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.