How to automate Microsoft two-way authentication based login page in Selenium using C#?
In an application user needs to enter email id and password on a Microsoft login page. After clicking on the Log in button, it sends a sms to a mobile number. Now User has to enter the OTP to login in the appication.
How do I automate this scenario in Selenium using C#?
jeanid last edited by
Some options in my order of preference:
Probably you do not want to test the TwoFactorAuth, but you want to test the application behind it. Consider building a backdoor which is only enabled in the test environment, so that you can bypass the TFA.
Generate the OTP from code with OTP.Net: https://dev.to/j_sakamoto/selenium-testing---how-to-sign-in-to-two-factor-authentication-2joi
I have read that people try to create an Appium test to retrieve the OTP so that could be another path: https://discuss.appium.io/t/how-to-read-otp-from-messages-using-appium/16949/8
Use a SMS api service and let the code retrieve the SMS text from that service.
Overall this is pretty challenging and makes the test setup complex and contain dependecies.