如何在Dynamics 365内部部署中使用EasyRepro自动登录 [英] How to automatically login using EasyRepro in Dynamics 365 on-premise
问题描述
我正在尝试在Dynamics 365内部部署中使用EasyRepro进行自动UI测试.我设法解决了一个问题,但无法自动登录到Dynamics 365组织.下面是我使用的代码:
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();
}
当我运行它时,新打开的Chrome浏览器页面仍会要求我输入凭据,在输入凭据(CRM用户名/密码)后,脚本将顺利运行.
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.
自此,我计划将其用作我们的自动化测试的一部分. EasyRepro是否可以自动登录?
Since, I plan to use this as part of our automated testing. Is there any way for the EasyRepro to automatically login?
推荐答案
此 github问题讨论本地CRM实例自动登录脚本的登录部分.
This github issue talks about the login part for on-premise CRM instance automatic login scripting.
这就是我绕过Windows身份验证登录的方式(无法在本地CRM安装中使用ADFS登录).刚刚定义了Login元素:
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."); });
}
希望您能,但是请确保您正在使用 EasyRepro版本分支-OnPremise 回购.
I hope you are, but make sure you are using EasyRepro Release Branch - OnPremise repo.
这篇关于如何在Dynamics 365内部部署中使用EasyRepro自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!