📜 ⬆️ ⬇️

Using Selenium WebDriver to test MS Dynamics CRM

This article will not explain what Selenium and Selenium WebDriver are - many wonderful articles have already been written about this.

Here I want to give just a small example of how you can test client code in MS Dynamics CRM.

But I think a couple of words about Selenium WebDriver can still be mentioned.
So, Selenium WebDriver is a library that allows you to control the browser: give the browser some commands, populate UI elements, read values, run scripts.
')
So let's go!



First of all, create a standard Unit Test Project.



Visual Studio will carefully create for us a test class and a test method — rename them according to our subject area.

Then we install the following things using nuget: Selenium.WebDriver and WebDriverIEDriver (if IE is the default browser for MS Dynamics CRM).



Well, almost all the work we have done :)
Now it only remains to write our unit test.

The following case will check our test: there are two fields “Estimated Amount” and “Weighted Amount”, while “Weighted Amount” should equal 30% of “Estimated Amount”. And this value should be set by the client script.

namespace CrmSeleniumUnitTest { [TestClass] public class OpportunityTests { [TestMethod] public void WeightedSummCalculate() { decimal estimatedValue = 1000m; decimal expectedWeightedValue = estimatedValue * 0.3m; string contentFrame = "contentIFrame"; string estimatedValueId = "estimatedvalue"; string weightedEstimatedValueId = "isv_weightedestimatedvalue"; string weightedEstimatedValueAttribute = "value"; var driver = new InternetExplorerDriver(); driver.Navigate().GoToUrl("https://test.crm.crm"); driver.SwitchTo().Frame(contentFrame); var estimatedValueElement = driver.FindElement(By.Id(estimatedValueId)); estimatedValueElement.Clear(); estimatedValueElement.SendKeys(Keys.Tab); estimatedValueElement.SendKeys(estimatedValue.ToString(CultureInfo.InvariantCulture)); estimatedValueElement.SendKeys(Keys.Tab); Thread.Sleep(10000); var weightedValueElement = driver.FindElement(By.Id(weightedEstimatedValueId)); var actualWeightedValue = Decimal.Parse(weightedValueElement.GetAttribute(weightedEstimatedValueAttribute),CultureInfo.InvariantCulture); driver.Quit(); Assert.AreEqual(expectedWeightedValue, actualWeightedValue); } } } 


Run the test.



Well, that's all - short and to the point :)

Source: https://habr.com/ru/post/274001/


All Articles