Set the subject hierarchy field on Products, Cases, Sales Literature and Articles using Easypro

Sending
User Review
0 (0 votes)

EasyRepro is an automated UI testing framework that helps developers perform unit testing on Dynamics 365 CRM. Even though it helps a lot for UI testing, still there are some shortcomings due to which we cannot perform certain actions on Dynamics 365 CRM.

In this blog, we will be tackling one such issue of EasyRepro that have been mentioned here. The issue is, the Subject field requires special handling, which is as of now not achievable at the time of writing this blog as is using EasyRepo Framework.

To handle this special field, one can use the below code to set N-number of hierarchy.

Code: –

/// <summary>

/// Function to set value in Special Type of Subject hierarchy field in CRM

/// </summary>

/// <param name=”fieldLogicalName”></param>

/// <param name=”category”></param>

/// <param name=”xrmApp”></param>

/// <param name=”driver”></param>

public void setSubjectField(string fieldLogicalName, string[] category, XrmApp xrmApp, IWebDriver driver) {

//Select and open dropdown Field

var control = driver.LastWindow().FindElement(By.CssSelector(“*[id*=’” + fieldLogicalName + “‘] *[id*=’input’]”));

control.Click();

xrmApp.ThinkTime(2000);

//Parent Element

var listOfOptions = driver.LastWindow().FindElements(By.CssSelector(“*[id*=’” + fieldLogicalName + “‘] li[id*=’tree-dropdown’]”));

//Find teh first element

IWebElement iwebelm = listOfOptions.FirstOrDefault(t => t.Text == category.FirstOrDefault());

if (iwebelm == null) return;

if (category.Length <= 1) { /*Select first element */ iwebelm.Click(); return; }

//Expand the parent element if need to select child element

if (!Convert.ToBoolean(iwebelm.GetAttribute(“aria-expanded”)))

{

//Expand the child hierarchy

var caretDown = iwebelm.FindElement(By.CssSelector(“*[id*=’” + fieldLogicalName + “‘] *[id*=’tree-dropdown-icon’]”));

if (caretDown != null)

caretDown.Click();

}

for (int i = 1; i < category.Length; i++)

{

xrmApp.ThinkTime(500);

var listOfCategory = driver.LastWindow().FindElements(By.CssSelector(“*[id*=’” + fieldLogicalName + “‘] li[id*=’tree-dropdown-sublist’]”));

var subCategoyList = listOfCategory[(listOfCategory.Count > 1) ? i – 1 : 0].FindElements(By.TagName(“li”));

var subCategoryElement = subCategoyList.FirstOrDefault(t => t.FindElement(By.CssSelector(“label”)).Text == category[i]);

if (i != category.Length – 1 && subCategoryElement != null)

{

//expand

var caretElement = subCategoryElement.FindElement(By.CssSelector(“span”));

if (caretElement != null)

caretElement.Click();

}

else if (subCategoryElement != null)

{

//Select child element

xrmApp.ThinkTime(1000);

subCategoryElement.FindElement(By.CssSelector(“label”)).Click();

}

}

}

Working

Suppose we have a requirement of setting up Product Delivery in the Subject tree which is a child of Delivery which is further inside the Service node.

SET THE SUBJECT HIERARCHY FIELD ON PRODUCTS, CASES, SALES LITERATURE, AND ARTICLES USING EASYREPRO

In the code we need to pass the parameter for the above function as

  • FieldName
  • String Array Containing list of subject hierarchy (which in the above case would be Service, Delivery, Product Delivery)
  • XrmApp (XrmApp object)
  • Driver (Client Driver)

e.g.

xrmApp.CommandBar.ClickCommand(“New Case”);

xrmApp.ThinkTime(200);

setSubjectField(“subjectid”, new string[] { “Service”, “Delivery”, “Product Delivery” }, xrmApp, xrmBrowser.Driver);

Result

SET THE SUBJECT HIERARCHY FIELD ON PRODUCTS, CASES, SALES LITERATURE, AND ARTICLES USING EASYREPRO

Using the above code we can set the Subject field present on products, cases, sales literature, and article.