Introduction
EasyRepro is a framework which is used to automate UI testing for dynamics customers Projects.
Problem
Grid.OpenRecord() method is used for opening the record from home page. This method opens the record by clicking on the first available anchor tag in the list of records, which makes it necessary to have the first column as primary name field of the entity.
Below code emphasize the same:
Code
internal BrowserCommandResult<bool> OpenRecord(int index, int thinkTime = Constants.DefaultThinkTime, bool checkRecord = false)
{
this.Browser.ThinkTime(thinkTime);
return this.Execute(GetOptions($”Open Grid Record”), driver =>
{
var currentindex = 0;
var rows = driver.FindElements(By.ClassName(“wj-row”));
//TODO: The grid only has a small subset of records. Need to load them all
foreach (var row in rows)
{
if (!string.IsNullOrEmpty(row.GetAttribute(“data-lp-id”)))
{
if (currentindex == index)
{
//This is the piece of code that does the opening of the record
var tag = checkrecord ? “div” : “a”;
row.findelement(by.tagname(tag)).click();
break;
}
currentindex++;
}
}
driver.WaitForTransaction();
return true;
});
}
Scenario
Suppose, we want to open the record from “All Opportunities” view by using Grid.OpenRecord() method. Then, we need to have a solution that opens the record without finding an anchor tag. The current method searches for first anchor tag(link). And with topic name blank, the first anchor tag(link) is of account due to which account record is opened instead of opportunity.
Solution
We need to replace the logic of opening the record on the basis of clicking an anchor tag to look for a label and double click it.
internal BrowserCommandResult<bool> OpenRecord(int index, int thinkTime = Constants.DefaultThinkTime, bool checkRecord = false)
{
this.Browser.ThinkTime(thinkTime);
return this.Execute(GetOptions($”Open Grid Record”), driver =>
{
var currentindex = 0;
var rows = driver.FindElements(By.ClassName(“wj-row”));
//TODO: The grid only has a small subset of records. Need to load them all
foreach (var row in rows)
{
if (!string.IsNullOrEmpty(row.GetAttribute(“data-lp-id”)))
{
if (currentindex == index)
{
//Replacing it with the below piece solves the issue.
var tag = checkRecord ? “div” : “label”;
SeleniumExtensions.DoubleClick(driver, By.TagName(tag), true);
break;
}
currentindex++;
}
}
driver.WaitForTransaction();
return true;
});
}
Conclusion
The above code will help you to open record without finding an anchor tag in Dynamics 365 Unified Interface.