1

I'm using Selenium to Unit Test an Azure AD application in ASP.NET Core MVC web app and I am looking for a better method of logging in the test user besides searching the DOM for login input elements. I'm Unit Testing in Azure DevOps so logging in with the browser UI is not an option. Any ideas?

James S.
  • 140
  • 2
  • 12

1 Answers1

2

In OAuth based technologies it is not easy to get a token as a user without an interactive redirect. For automated test purposes the simplest option is often to use the Resource Owner Password Grant. This is not recommended for production usage in real UIs though.

Gary Archer
  • 22,534
  • 2
  • 12
  • 24
  • I did not know Microsoft even allowed that. I was able to get this working in conjunction with a client_secret to acquire the Access Token and ID Token. Now how can I get this into the cookie? – James S. Jul 31 '20 at 04:33
  • Ah - I was assuming you were using a token based Web UI in which case my suggestion would work well for testing. Cookie based apps come with lots of hidden complexity and this is only one aspect. You will need to act like a real browser and simulate posting DOM element values if you need cookies to call APIs. – Gary Archer Jul 31 '20 at 12:21
  • That's what I'm doing now, and it's quite painful. I'll just leave it at that then, as I don't want to switch to storing tokens on the client just to make unit testing easier. – James S. Aug 11 '20 at 10:09