1

I'm trying to automate a windows based application Using Coded UI. In this application some control are not accesible so i have used UI automatin element to identify the control.

First Screen Contains List of Employees in the form Grid.

When user Doubles click on selected Employee. New Tab is created where it contains emplyee Details in the form of TextBox

New TabPage we have TextBox and some other controls such as Checkbox and ListItem.

List Item are detectable using coded ui but TextBox are not detectable with coded ui so we have used UI Automation Element for this.

[CodedUITest]
public class CodedUITest1
{   

    [TestMethod]
    public void CodedUITestMethod2()
    {

        LaunchApplication(); //done using coded ui
        Login()//done using Coded UI;
        ClickonEmpListTab()//Done Using Coded UI
        SelectEmployee()//done using Coded UI
       //now new Tab is created in application 
        empoyeeUICodedUIControl.CurrentEmpComboBox.Checked= true; //done using coded ui
       empoyeeUIAutomationControl.EnterText(empoyeeUIAutomationControl.FirsName,"MyFirstName"); // done using coded ui
        empoyeeUIAutomationControl.EnterText(empoyeeUIAutomationControl.LastName,"MyLastName"); // done usin coded ui
        }
    private EmployeeUIAutomationUIMap _employeeUIAutomationcontrol;
    public EmployeeUIAutomationUIMap empoyeeUIAutomationControl
    {
        get
        {
            if(_employeeUIAutomationcontrol == null)
            {
                _employeeUIAutomationcontrol = new EmployeeUIAutomationUIMap();
            }
            return _employeeUIAutomationcontrol;
        }
    }

    private EmployeeUIMap _employeeUICodedUIcontrol;
    public EmployeeUIMap empoyeeUICodedUIControl
    {
        get
        {
            if (_employeeUICodedUIcontrol == null)
            {
                _employeeUICodedUIcontrol = new EmployeeUIAutomationUIMap();
            }
            return _employeeUICodedUIcontrol;
        }
    }

// Class contains controls which are detectable using coded ui

public class EmployeeUIMap { public WinTabPage ListEmpmTab { get { WinTabPage tab = new WinTabPage();
return tab; } }

    public WinCheckBox CurrentEmpComboBox
    {
      get 
        {
            WinCheckBox combox = new WinCheckBox();
            return combox;
        }
    }
}

//Class contains Control which are detectable using UI Automation Element

public class EmployeeUIAutomationUIMap {

    public Condition GetCondition(AutomationProperty propery,string value)
    {
        Condition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, value);
        return cond;
    }

    public AutomationElement GetElement(AutomationElement parentControl,Condition cond)
    {
        return parentControl.FindFirst(TreeScope.Descendants, cond);
    }

    public AutomationElement MainRootElement
    {
        get
        {
            return AutomationElement.RootElement;
        }
    }

    public AutomationPattern GetPattern(AutomationElement element)
    {
        //returns the pattern as per element 
        return pattern;
    }

    public void  EnterText(AutomationElement element,string value)
    {
        var pattern = GetPattern(element);
        pattern.SetValue = value;
    }
    public AutomationElement FirsName
    {
        var cond=GetCondition(AutomationElement.AutomationIdProperty,"FNID");
        var element=GetElement(MainRootElement,cond);
        return  element;

    }

    public AutomationElement LastName
    {
        var cond=GetCondition(AutomationElement.AutomationIdProperty,"LNID");
        var element=GetElement(MainRootElement,cond);
        return  element;

    }


}

When i Run my TestMethod it works fine till clicking on selected employee. once new tab page is opened i perform operation on checkBox using coded ui which workds, but when i try to enter text in textbox using UI automation. It throws null exception in GetElement() Method on element.

So i commented below code and manually opened the application till new tab is opened. and run the test method, now uiAuomation recognizes the element and perform the respective action.

[TestMethod]
    public void CodedUITestMethod2()
    {

        /*
          LaunchApplication(); //done using coded ui
          Login()//done using Coded UI;
          ClickonEmpListTab()//Done Using Coded UI
          SelectEmployee()//done using Coded UI
       */
        empoyeeUICodedUIControl.CurrentEmpComboBox.Checked= true; //done using coded ui

empoyeeUIAutomationControl.EnterText(empoyeeUIAutomationControl.FirsName,"MyFirstName"); // done using UIAutomation element

empoyeeUIAutomationControl.EnterText(empoyeeUIAutomationControl.LastName,"MyLastName"); // done usin Automation Element }

When i run my complete test method UIAutomation is not able to identify the control.

Please help me to resolve the problem.

pasupati
  • 57
  • 9

1 Answers1

0

UI Automation is a framework to implement standardized support for non-standard UI widgets. This being said, if the support is not implemented(and installed) on the test machíne, CUIT will handle all objects as generic Objects. You need to implement support first via the UI Automation framework for your widgets aka you have to teach windows why a specific WinClass is a Button and what should happen in the background when it is clicked.

Afterwards CUIT will be able to interact with your Object. So don't think of UI Automation as a magic solution for everything. It is something similar like the HPE UFT Extensibility Kit, just on a lower level (OS). HPE Ext Kit operates on the Application Level

Bela Tamas Jozsa
  • 714
  • 5
  • 10
  • You mean i wont be able to use UI Automation in this scenario.In this case What would be the solution for this issue. – pasupati Jun 11 '18 at 16:26
  • One point i wanted to add when i run my coded ui and UI Automation element in two different test methods. controls are able to recognize. but with single test method for some reason ui automation doesn't recognize the controls. it returns null every time. what actually happens when we run two test methods together. – pasupati Jun 11 '18 at 16:41
  • my assumptions may have been wrong then. In this case the problem is not at Native Support but maybe a sync issue, aka the Object is not fully loaded into the memory but the script wants to interact with it. Can you try adding some Wait / Sleep statements before each interaction with your application(big enough to be sure that everything is loaded / synchronized). If that solves the issue then you need to work on your synchronisation part. – Bela Tamas Jozsa Jun 11 '18 at 18:48
  • I tired doing that but still the same issue. – pasupati Jun 12 '18 at 12:00