I'm trying to do Automated UI Testing using EasyRepro in Dynamics 365 On-Premise. I managed to the testing with one issue, I can't automatically login to my Dynamics 365 Organization. Below are the code that I used:
var client = new WebClient(TestSettings.Options);
using (var xrmApp = new XrmApp(client))
{
xrmApp.OnlineLogin.Login(_xrmUri, _username, _password);
xrmApp.Navigation.OpenSubArea("My Work", "Companies");
xrmApp.CommandBar.ClickCommand("New");
xrmApp.Entity.SetValue("name", TestSettings.GetRandomString(5,15));
xrmApp.Entity.Save();
}
When I run it, the newly open chrome page will still ask me to put my credential, after I enter my credential (the CRM username/password), the script will run smoothly.
Since, I plan to use this as part of our automated testing. Is there any way for the EasyRepro to automatically login?
This github issue talks about the login part for on-premise CRM instance automatic login scripting.
This is how I got around Windows Authentication Login (Could not use the ADFS Login on our On-Premise CRM Install). Just defined the Login elements:
using (var xrmBrowser = new Browser(TestSettings.Options))
{
DateTime dt = DateTime.Now;
String xpath = "//*[@id='search']";
// String logoffcrm = "#navBarUserInfoTextId > span.navTabButtonUserInfoText.navTabButtonUserInfoCompany";
Actions keyAction = new Actions(xrmBrowser.Driver);
xrmBrowser.GoToXrmUri(_xrmUri);
xrmBrowser.Driver.FindElement(By.Id("ContentPlaceHolder1_UsernameTextBox")).SendKeys(_username);
xrmBrowser.ThinkTime(1000);
xrmBrowser.Driver.FindElement(By.Id("ContentPlaceHolder1_PasswordTextBox")).SendKeys(_password);
xrmBrowser.ThinkTime(1000);
try
{
if (_browser == "Chrome")
{
xrmBrowser.Driver.FindElement(By.Id("ContentPlaceHolder1_SubmitButton")).Click();
}
if (_browser == "IE")
{
xrmBrowser.Driver.FindElement(By.Id("ContentPlaceHolder1_SubmitButton")).Submit();
}
xrmBrowser.Driver.WaitUntilVisible(By.XPath(xpath)
, new TimeSpan(0, 0, 60),
e => { xrmBrowser.Driver.WaitForPageToLoad(); },
f => { throw new Exception("Login failed."); });
}
catch (StaleElementReferenceException)
{
//old element has gone
//Console.WriteLine(g);
xrmBrowser.Driver.WaitUntilVisible(By.XPath(xpath)
, new TimeSpan(0, 0, 60),
e => { xrmBrowser.Driver.WaitForPageToLoad(); },
f => { throw new Exception("Login failed."); });
}
I hope you are, but make sure you are using EasyRepro Release Branch - OnPremise repo.
According to the docs, you can add credentials in app.config
like so:
<add key="OnlineUsername" value="name@name.onmicrosoft.com" />
<add key="OnlinePassword" value="*********" />
<add key="OnlineCrmUrl" value="https://org.crm.dynamics.com/" />
Source: https://github.com/Microsoft/EasyRepro