How to validate a particular row data among many rows in the table for testing in c# and once if all the data are verified than test case is passed and if not verified then fail?

using System;
using System.Threading;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Winium;

namespace SFGridDataTest
    public class UnitTest1
        public void TestMethod1()
            DesktopOptions options = new DesktopOptions();
            options.ApplicationPath = @"C:\Users\windev\Desktop\WPF\bin\Debug\SfDataGridDemo.exe";
            WiniumDriver driver = new WiniumDriver(@"C:\Users\windev\Desktop\DemoWPF\Winium.Desktop.Driver", options);
            AutomationElement desktop = AutomationElement.RootElement;

            //AutomationElement of SfDataGrid.
            AutomationElement datagrid = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "sfgrid"));

            //AutomationElement of GridCell in SfDataGrid
            var cellAutomationElement = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "Cell1"));
            var cellAutomationElement1 = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "Cell2"));
            var cellAutomationElement2 = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "Cell3"));
            var cellAutomationElement3 = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "Cell4"));
            var cellAutomationElement4 = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "Cell5"));

            //AutomationElement of Row in SfDataGrid
            var row = desktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "Row1"));

            //Loctating the automation id for the each cell
            AutomationElement.AutomationElementInformation currentAutomationElement = cellAutomationElement.Current;
            AutomationElement.AutomationElementInformation currentAutomationElement1 = cellAutomationElement1.Current;
            AutomationElement.AutomationElementInformation currentAutomationElement2 = cellAutomationElement2.Current;
            AutomationElement.AutomationElementInformation currentAutomationElement3 = cellAutomationElement3.Current;
            AutomationElement.AutomationElementInformation currentAutomationElement4 = cellAutomationElement4.Current;

            //extracting each value from the cells
            string[] array = currentAutomationElement.ItemStatus.Split(new string[]
            }, StringSplitOptions.RemoveEmptyEntries);
            string[] array1 = currentAutomationElement1.ItemStatus.Split(new string[]
            }, StringSplitOptions.RemoveEmptyEntries);
            string[] array2 = currentAutomationElement2.ItemStatus.Split(new string[]
            }, StringSplitOptions.RemoveEmptyEntries);
            string[] array3 = currentAutomationElement3.ItemStatus.Split(new string[]
            }, StringSplitOptions.RemoveEmptyEntries);
            string[] array4 = currentAutomationElement4.ItemStatus.Split(new string[]
            }, StringSplitOptions.RemoveEmptyEntries);

            //Storing the each value of cells
            var cellValue = array[0];
            var cellValue1 = array1[0];
            var cellValue2 = array2[0];
            var cellValue3 = array3[0];
            var cellValue4 = array4[0];
            System.Diagnostics.Debug.WriteLine("Cell Zero: " + cellValue);
            System.Diagnostics.Debug.WriteLine("Cell One: " + cellValue1);
            System.Diagnostics.Debug.WriteLine("Cell Two: " + cellValue2);
            System.Diagnostics.Debug.WriteLine("Cell Three: " + cellValue3);
            System.Diagnostics.Debug.WriteLine("Cell Four: " + cellValue4);
            Assert.IsTrue(cellValue == "1001");
            System.Diagnostics.Debug.WriteLine("Full Row Data: " + cellValue + " " + cellValue1 + " " + cellValue2 + " " + cellValue3 + " " + cellValue4);
  • when you run the test what is it returning? – DEnumber50 Oct 11 at 19:19
  • Try to edit the code to only the relevant parts. – João Farias Oct 12 at 8:10

(I am on mobile - formatting help would be appreciated)

Your code seems to have many internal representations that are not easy to interpret for someone outside your project; so I will suggest something in general:

Let's say: 1 - A row is located by the tr tag. 2 - The row has two cells, located by the classes .cell1 and .cell2

You want to check the data of the row which cell1 is enabled.

You would do:

// Grab all the rows rows = driver.findElements(By.cssSelector("tr"));

// Filter the rows by the enabled criteria, grabbing the first matching row enabledRow = rows.filter( row => row.findElement(".cell1").isEnabled())[0];

// Checks the data assertEquals( enabledRow.findElement(".cell1").text, "Cell 1"); assertEquals( enabledRow.findElement(".cell2").text, "Cell 2");

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.