예제 #1
0
        static void writeGridContent(string testDataFile, string testcase)
        {
            string TableType = "";
            string SearchBy = "";
            string SearchValue = "";
            int tindex = -1;
            var _logicalName = "";//coulmnname/fieldname  alias 
            Helper.TestDataManagement testData = new Helper.TestDataManagement();
            UIAutomation_App.UIAutomationAction uiautomation1 = new UIAutomation_App.UIAutomationAction();

            string _epath = ConfigurationManager.AppSettings["logfile"];
            uiautomation1._eLogPtah = _epath;


            try
            {

                testData.GetVerificationData(testDataFile, testcase);
                TableType = testData.Template.Rows[0]["TableType"].ToString();
                SearchBy = testData.Template.Rows[0]["SearchBy"].ToString().ToLower();
                SearchValue = testData.Template.Rows[0]["SearchValue"].ToString();
                if (SearchBy.ToLower() == "index")
                {
                    tindex = Int32.Parse(SearchValue);
                }

                uiautomation1.uiAutomationWindow = uiautomation1.GetUIAutomationWindow("title", "K2");

                uiautomation1.uiAutomationCurrentParent = uiautomation1.uiAutomationWindow;

                AutomationElement datagridtable = uiautomation1.GetUIAutomationDataGrid(SearchBy, SearchValue, tindex);
                if (datagridtable != null)
                {
                    uiautomation1.logTofile(uiautomation1._eLogPtah, "[writeGridContent]:Datagrid Object has been detected!");
                }
                AutomationElementCollection datarows = datagridtable.FindAll(TreeScope.Children,
                        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));
                uiautomation1.logTofile(uiautomation1._eLogPtah, "[writeGridContent]: DataGrid Rows count is =" + datarows.Count.ToString());
                for (int ip = 0; ip < datarows.Count; ip++)
                {
                    AutomationElementCollection cells = datarows[ip].FindAll(TreeScope.Children,
                    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
                    uiautomation1.logTofile(uiautomation1._eLogPtah, "[writeGridContent]: Cells or columns count " + cells.Count);
                    try
                    {
                        AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(cells[0]);
                        uiautomation1.logTofile(uiautomation1._eLogPtah, "after element node");
                        ValuePattern valpat = (ValuePattern)elementNode.GetCurrentPattern(ValuePattern.Pattern);
                        _logicalName = (string)testData.Template.Rows[0]["FieldName"];
                        var valueofcell = valpat.Current.Value;
                        valpat.SetValue((string)testData.ExpectedData.Rows[ip][_logicalName]);
                    }
                    catch
                    {
                    }
                    for (int i = 0; i < cells.Count; i++)
                    {
                        uiautomation1.logTofile(uiautomation1._eLogPtah, "[writeGridContent]: Trying Value patern " + i);
                        uiautomation1.logTofile(uiautomation1._eLogPtah, "before element node");
                        AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(cells[i]);
                        uiautomation1.logTofile(uiautomation1._eLogPtah, "after element node");
                        ValuePattern valpat = (ValuePattern)elementNode.GetCurrentPattern(ValuePattern.Pattern);
                        _logicalName = (string)testData.Template.Rows[i]["FieldName"];
                        var valueofcell = valpat.Current.Value;
                        valpat.SetValue((string)testData.ExpectedData.Rows[ip][_logicalName]);
                    }

                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("[writeGridContent]:Execption Message : " + ex.Message.ToString());
            }
        }