How to automatically login using EasyRepro in Dynamics 365 on-premise

我与影子孤独终老i 提交于 2020-02-15 08:09:29

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/60056050/how-to-automatically-login-using-easyrepro-in-dynamics-365-on-premise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!