EzElement

EzElement provides the base class for all elements within an application. EzGrid, EzGridItem, EzList, and EzListItem all inheret from EzElement. When querying for an element, an EzElement is what is returned. That instance can then be used to create a more specific type of element of desired. This class is very key to using EazyE2E so be sure to check out the Samples and Usage section at the bottom as well as the tutorial
💡 Note

EzElement is the base class for all other elements in EazyE2E. It can be instantiated by itself or used to create a more specific element type.

Syntax

        public class EzElement

Constructors

Name Input Description
EzElement(EzElement element) EzElement Creates a new instance of EzElement based on an existing EzElement. Can be used for finding a child/descendant of a previously obtained element
EzElement(EzRoot root) EzRoot Creates a new instance of EzElement based on an existing EzRoot. Generally used for finding the first element after getting the root element
EzElement(AutomationElement element) AutomationElement Creates a new instance of EzElement based on an existing AutomationElement. Creates an instance of EzElement based on a Windows AutomationElement object

Properties

Name Type Description
Parent EzElement Houses the parent element for the current element if the parent exists
Name string Gets the Name property of the EzElement. Usually used for verifying output in the UI or querying for elements
AutomationId string Gets the AutomationId property of the EzElement. Usually used for querying for elements. Generally, this is the preferable property to use when searching the UI for elements
ClassName string Gets the ClassName property of the EzElement. Usually used for determining what the element is used for from a user interaction perspective
Type ControlType Gets the ControlType of the EzElement. Usually used for determining what underlying control patterns exist for the element
BackingAutomationElement AutomationElement Gets the backing AutomationElement for the EzElement. Even if an AutomationElement was not used to construct this instance of EzElement, it will still have a BackingAutomationElement

Methods

Name Return Type Description
Click() void Invokes the delegate method the current element has (if any) when clicked. Note that this does not perform a physical click of the element, but instead simulates one
BringIntoFocus() void Brings the current element into focus. It will also focus all other elements that are ancestors of the element. For example, if the application under test is all one large window, the entire window will be brought into focus if this method is called on any of its descendants
FindChildByName(string name, bool searchRaw = false) EzElement Queries all children of the current element and returns the first one whose Name property matches the name parameter passed in. If the searchRaw flag is set to true, the framework will check all elements that are children of the current elements instead of just the Control elements
FindDescendantByName(string name) EzElement Queries all descendants of the current element and returns the first one whose Name property matches the parameter passed in. Note that if configuration property AllowSearchingForDescendants is set to false, calling this method will throw an exception
FindChildByAutomationId(string name, bool searchRaw = false) EzElement Queries all children of the current element and returns the first one whose AutomationId property matches the parameter passed in. If the searchRaw flag is set to true, the framework will check all elements that are children of the current elements instead of just the Control elements
FindDescendantByAutomationId(string name) EzElement Queries all descendants of the current element and returns the first one whose AutomationId property matches the parameter passed in. Note that if configuration property AllowSearchingForDescendants is set to false, calling this method will throw an exception
FindChildByClass(string name, bool searchRaw = false) EzElement Queries all children of the current element and returns the first one whose Class property matches the parameter passed in. If the searchRaw flag is set to true, the framework will check all elements that are children of the current elements instead of just the Control elements
FindChildByMultipleCriteria(params SearchTypeProperty[] properties) EzElement Queries all the children of the current element and returns the first one whose properties match each criterion passed in
FindDescendantByMultipleCriteria(params SearchTypeProperty[] properties) EzElement Queries all the descendants of the current element and returns the first one whose properties match each criterion passed in. Note that if configuration property AllowSearchingForDescendants is set to false, calling this method will throw an exception
FindChildrenByName(string name, bool searchRaw = false) IEnumerable<EzElement> Queries all children of the currenent element and returns all children whose Name properties match the parameter passed in
FindDescendantsByName(string name) IEnumerable<EzElement> Queries all descendants of the current element and returns all descendants whose Name properties match the parameter passed in. Note that if configuration property AllowSearchingForDescendants is set to false, calling this method will throw an exception
FindChildrenByAutomationId(string name) IEnumerable<EzElement> Queries all children of the current element and returns all children whose AutomationId properties match the parameter passed in
FindDescendantsByAutomationId(string name) IEnumerable<EzElement> Queries all descendants of the current element and returns all descendants whose AutomationId properties match the parameter passed in
FindChildrenByMultipleCriteria(params SearchTypeProperty[] properties) IEnumerable<EzElement> Queries all children of the current element and returns all children whose properties match each criterion passed in
FindDescendantsByMultipleCriteria(params SearchTypeProperty[] properties) IEnumerable<EzElement> Queries all descendants of the current element and returns all descendants whose properties match each criterion passed in
GetAllChildren() IEnumerable<EzElement> Gets all children of the current element
GetAllDescendants() IEnumerable<EzElement> Gets all descendants of the current element. It should be noted that this element can potentially very inefficient if the element you are calling this method on has many descendants. Use with caution. Note that if configuration property AllowSearchingForDescendants is set to false, calling this method will throw an exception

Samples and Usage

The EzElement class sits underneath basically all functionality involved in querying for elements and following the hierarchy of the application to find elements that you want. EzElement also provides the basic building block to make a more specialized class (like EzGrid or EzList for example). See the tutorial for a fuller explanation of what the EzElement class can do.

Sample:

        //Simple method to launch Windows' built in calculator application and click the 7 button
        const string calculatorPath = C:\\Windows\\System32\\calc.exe";

        //Get an instance of EzProcess in order to create EzRoot.  Wrap it in a using statement to ensure that
        //.Dispose() is called
        using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
        {
            process.StartProcess();

            //Get the root element of the application
            EzRoot root = new EzRoot(process);

            //Use the .FindChildByAutomationId to query all children of the root for the first element whose
            //AutomationId property is equal to "NumberPad"
            EzElement numPad = root.RootElement.FindChildByAutomationId("NumberPad");

            //Find the first child of the NumberPad element whose AutomationId property is equal to "num7Button"
            EzElement sevenButton = numPad.FindChildByAutomationId("num7Button");

            //Click the 7 button.  This will perform a click operation and the calculator's display should now say "7"
            sevenButton.Click();
        }