How to read the value from a Flip Switch Control in EasyRepro?

Sending
User Review
0 (0 votes)

Introduction:

Over time we have seen how by using EasyRepro we can perform UI Automation testing in Dynamics 365 CRM by getting and setting values in fields of different datatypes. In EasyRepro we do find predefined methods to get and set values of fields of different data types.

However, recently while creating an automation project for our in-house solution we were needed to read the value from a Two OptionSet field for which the Flip Switch was enabled.

Usually, to read the value from a boolean field in easyrepro we would use the predefined GetValue method given below:

var boolValue = xrmApp.Entity.GetValue(new BooleanItem { Name = "Logical Name"});

But we noticed that for a boolean field with Flip Switch enabled, this method was not giving the desired output.  It did rather threw the following exception “Field: <logical name> Does not exist”.

To continue with our testing while avoiding the above issue we took the alternative step given below. And the boolean field used for context is ikl_showsubscriptionfields”.

Step 1:

First, we need to find the switch element to read its properties. And to access an element it is imperative we stay on current window. The below lines of code will ensure that we are on the current window where the field is present.

//Get the Current window handle
var win = client.Browser.Driver.CurrentWindowHandle;
//Switch to the window retrieved above
var currentWin = client.Browser.Driver.SwitchTo().Window(win);

Step 2:

Look for the element attribute which changes on change of the switch. The attribute is area-checked. And as can be seen from the below screenshot the value is false when the toggle is off.

read the value from a Flip Switch Control in EasyRepro

Once the toggle is on the value changes to true.

read the value from a Flip Switch Control in EasyRepro

read the value from a Flip Switch Control in EasyRepro

Step 3:

Now get the element using the attribute data-id in CssSelector in your code as shown below.

read the value from a Flip Switch Control in EasyRepro

var regardingElement = currentWin.FindElement(By.CssSelector("[data-id*='ikl_showsubscriptionfields'] [role='checkbox']"));

Step 4 :

Once you get the element now get the attribute value of “aria-checked” as shown below by using GetDomAttribute() method of Easyrepro.

var isChecked = regardingElement.GetDomAttribute("aria-checked");

Below is the entire sample code

//Get the Current window handle
var win = client.Browser.Driver.CurrentWindowHandle;
//Switch to the window retrieved above
var currentWin = client.Browser.Driver.SwitchTo().Window(win);
//Get the element
var regardingElement = currentWin.FindElement(By.CssSelector("[data-id*='ikl_showsubscriptionfields'] [role='checkbox']"));
//Read the attribute to get the boolean value from the element
var isChecked = regardingElement.GetDomAttribute("aria-checked");

Conclusion:

In this way, you can easily get the value of flip switch control in EasyRepro.

UAM

AllEscort