Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
Coded UI Tests on UltraGrid
posted

Hi,

I have an UltraGrid with multiple rows and 2 columns. Out of these 2 columns 1 is a read-only and other one is editable. Using Coded UI I need to write into the editable column of a particular row (Will define this row by the 1st column). 

Also I was looking  documentation / tutorials regarding using Coded UI with Infragistics controls (especially grids and combo-boxes) but could not find any. Could you please point me to some ?

Parents Reply
  • 21795
    Offline posted in reply to Abhinav Pandey

    Hello Abhinav,

    One possible way is to iterate through all the rows in the grid and check the value of the cells in the first column. If the value match the one you need click on the cell in the same row in the second column and set its value. Please check this thread in our forum, where was discussed and shown how you can iterate through all the rows in a grid and get the cells’ values. When you get the cell value you can check it against the one you need. If the value match the one you need you can get the AutomationElement of the cell in the next column, click on it and set its text.

    Here is a sample method doing all this:

    public void SetCellValue()
    {
        UITestControl uIColScrollRegion0RowSTree =
            this.UIForm1Window.UIForm1Client.UIUltragridCustom.UIDataAreaCustom.UIColScrollRegion0RowSTree;
        UltraUiaEdit uIUltragrid_EmbeddableEdit =
            this.UIForm1Window.UIUltraGrid1Window.UIUltragrid_EmbeddableEdit;

        int rowIndex = 0;
        AutomationElement containerAutomationElement =
            uIColScrollRegion0RowSTree.NativeElement as AutomationElement;
        AutomationElement rowAutomationElement = null;
        ItemContainerPattern containerPattern =
            containerAutomationElement.GetCurrentPattern(ItemContainerPattern.Pattern) as ItemContainerPattern;
        rowAutomationElement =
            containerPattern.FindItemByProperty(
                null,
                AutomationElement.AutomationIdProperty,
                rowIndex.ToString());
        while (rowAutomationElement != null)
        {
            // get the collection of cell automation elements
            AutomationElementCollection cellsAutomationElements =
                rowAutomationElement.FindAll(TreeScope.Children, Condition.TrueCondition);

            // get the automation element for the cell in first column
            AutomationElement cellAutomationElement = cellsAutomationElements[0];

            // Scroll the cell into view
            ScrollItemPattern scrollPattern =
                cellAutomationElement.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;
            scrollPattern.ScrollIntoView();

            // use the ValuePattern to get the Value.
            ValuePattern valuePattern =
                cellAutomationElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
            var cellValue = valuePattern.Current.Value.ToString();

            // check the cell value
            if (cellValue == "Cat")
            {
                // get the automation element for the cell in second column
                AutomationElement nextCellAutomationElement = cellsAutomationElements[1];

                // get clickable point on the cell in second column
                Point poinToClick = nextCellAutomationElement.GetClickablePoint();

                //  click on the cell
                Mouse.Click(poinToClick);

                // set the cell Text
                uIUltragrid_EmbeddableEdit.Text =
                    this.RecordedMethod1Params.UIUltragrid_EmbeddableEditText;

                // get clickable point on the cell in the first column
                poinToClick = cellAutomationElement.GetClickablePoint();

                //  click on the cell
                Mouse.Click(poinToClick);

                break;
            }

            // get the next row
            rowIndex++;
            rowAutomationElement =
                containerPattern.FindItemByProperty(
                    null,
                    AutomationElement.AutomationIdProperty,
                    rowIndex.ToString());
        }
    }

    Please let me know if you need any additional information.

Children
No Data