I'm creating a method for logging in to MS Dynamics 365 and get the error below when RUN the test:
AADSTS90100: login parameter is empty or not valid.
Here is my code:
public void Login(SecureString login, SecureString password)
{
_driver.Url = "https://{domain}.crm4.dynamics.com/";
_driver.WaitForPageToLoad(TimeSpan.FromSeconds(10));
var userNameInput = _driver.WaitUntilAvailable(By.CssSelector("input[type = 'email']"),
TimeSpan.FromSeconds(10));
userNameInput.SendKeys(login.ToUnsecureString());
var submitButton = _driver.WaitUntilClickable(By.CssSelector("input[type = 'submit'][value =
'Next']"), TimeSpan.FromSeconds(10));
submitButton.Click();
//userNameInput.SendKeys(Keys.Enter);
// following actions
}
I also tried sending the Enter key and Submit() method but no luck. Interesting thing - I cannot reproduce the issue manually or when DEBUG the test. The error appears only in the RUN mode of the test.
I compared URLs in RUN and DEBUG modes and there is not any difference.
I spent 3 hours in Google but didn't find a solution. It should be mentioned, that I'm not an experienced dev. So can miss or don't understand something.
Some ideas?
I've found the root cause.
Actually, the issue occurs not after submitButton.Click();
but after another action which is not provided here, since the error message is a bit confusing.
The thing is we used EasyRepro framework in our solution and getting rid of it now since it's not been supported for more than a year now.
If we take a look at EasyRepro login logic, there is such a method:
private static void EnterPassword(IWebDriver driver, SecureString password)
{
var input =
driver.FindElement(By.XPath(Elements.Xpath[Reference.Login.LoginPassword]));
input.SendKeys(password.ToUnsecureString());
input.Submit();
}
And the error is caused by input.Submit();
line. I just copied it in my new method.
It seems like the method submits the whole form before the login has time to be written somewhere.
So, I simply changed that to this one:
private bool EnterPassword(string password)
{
var passwordInput = _driver.FindElement(By.CssSelector("input[type =
'password']"));
passwordInput.SendKeys(password);
var submitButton = _driver.WaitUntilClickable(By.CssSelector("input[type =
'submit'][value = 'Sign in']"),
_defaultWait);
submitButton.Click();
var staySignedInDialog = _driver.WaitUntilAvailable(By.XPath("//div[contains(text(), 'Stay signed
in?')]"), _defaultWait);
return staySignedInDialog != null;
}
Hope will be useful for someone in the future.