Selenium WebDriverを使用してMS Dynamics CRMをテストする

この記事では、SeleniumとSelenium WebDriverが何であるかについては説明しません。これについては多くのすばらしい記事がすでに書かれています。

ここでは、MS Dynamics CRMでクライアントコードをテストする方法の簡単な例を紹介します。

しかし、Selenium WebDriverについてのいくつかの言葉はまだ言えると思います。
そのため、Selenium WebDriverは、ブラウザを制御できるライブラリです。ブラウザにコマンドを与え、UI要素を入力し、値を読み取り、スクリプトを実行します。

さあ、行こう!



まず最初に、標準の単体テストプロジェクトを作成します。



Visual Studioは、テストクラスとテストメソッドを慎重に作成します-サブジェクトエリアに従って名前を変更します。

次に、nugetを使用して次のものをインストールします:Selenium.WebDriverおよびWebDriverIEDriver(IEがMS Dynamics CRMの既定のブラウザーである場合)。



まあ、私たちはほとんどすべての仕事をしました:)
今は単体テストを書くだけです。

私たちのテストは次の場合にテストされます。「推定額」と「加重額」の2つのフィールドがあり、「加重額」は「推定額」の30%でなければなりません。 また、この値はクライアントスクリプトによって設定する必要があります。

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); } } } 


テストを実行します。



まあ、それはすべてです-簡単に、そしてビジネスで:)

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


All Articles