private static void ClickMenus(string windowTitle, string menus, int processID) { try { UIAutomation_App.UIAutomationAction uAutomation = new UIAutomation_App.UIAutomationAction(); uAutomation._processId = processID; AutomationElement winElement = uAutomation.GetUIAutomationWindow("title", windowTitle); uAutomation.uiAutomationCurrentParent = winElement; Console.WriteLine(winElement.Current.Name); string[] menuNames = menus.Split('|'); #region search for the start in LOWIS Client Console.WriteLine("Searching Start"); AutomationElementCollection textCollection = winElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)); AutomationElement start = null; for (int i = 0; i < textCollection.Count; i++) { if (textCollection[i].Current.Name.ToLower() == "Start".ToLower() || textCollection[i].Current.AutomationId.ToLower() == "Start".ToLower()) { start = textCollection[i]; break; } } ClickControl(start); Console.WriteLine("Start Button:" + start.Current.Name); #endregion if (menuNames.Length != 2) { throw new Exception("Need to pass menu names separared by pipe e.g. Menu1|Menu2"); } AutomationElementCollection menuCollection = AutomationElement.RootElement.FindAll(TreeScope.Descendants, new System.Windows.Automation.PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem)); AutomationElement firstLevel = null; Console.WriteLine("Menu Count" + menuCollection.Count); for (int i = 0; i < menuCollection.Count; i++) { Console.WriteLine(menuCollection[i].Current.Name); if (menuCollection[i].Current.Name.ToLower() == menuNames[0].ToLower()) { firstLevel = menuCollection[i]; ExpandCollapsePattern value = (ExpandCollapsePattern)menuCollection[i].GetCurrentPattern(ExpandCollapsePattern.Pattern); value.Expand(); break; } } AutomationElementCollection secondCollection = firstLevel.FindAll(TreeScope.Descendants, new System.Windows.Automation.PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem)); for (int i = 0; i < secondCollection.Count; i++) { Console.WriteLine(secondCollection[i].Current.Name); if (secondCollection[i].Current.Name.ToLower() == menuNames[1].ToLower()) { InvokePattern value = (InvokePattern)secondCollection[i].GetCurrentPattern(InvokePattern.Pattern); value.Invoke(); break; } } } catch (Exception ex) { throw new Exception(ex.Message); } }
private static void ClickBeamDesign(string windowtitle, string tabName, string buttonAutomationID, int processID) { try { UIAutomation_App.UIAutomationAction uAutomation = new UIAutomation_App.UIAutomationAction(); uAutomation.logTofile(uAutomation._eLogPtah, "Inside ClickBeamDesign"); uAutomation._processId = processID; AutomationElement winElement = uAutomation.GetUIAutomationWindow("title", windowtitle); uAutomation.uiAutomationCurrentParent = winElement; uAutomation.logTofile(uAutomation._eLogPtah, "Window Name: " + winElement.Current.Name); AutomationElement beamDesignTab = uAutomation.GetUIAutomationUltratab("name", tabName, -1); uAutomation.logTofile(uAutomation._eLogPtah, "Tab Name: " + beamDesignTab.Current.Name); SelectionItemPattern select = (SelectionItemPattern)beamDesignTab.GetCurrentPattern(SelectionItemPattern.Pattern); select.Select(); if (beamDesignTab.Current.IsOffscreen.ToString().ToLower() == "true") { uAutomation.logTofile(uAutomation._eLogPtah, "BeamDesign tab not visible"); AutomationElement btn = winElement.FindFirst(TreeScope.Descendants, new System.Windows.Automation.AndCondition( new System.Windows.Automation.PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new System.Windows.Automation.PropertyCondition(AutomationElement.AutomationIdProperty, buttonAutomationID))); uAutomation.logTofile(uAutomation._eLogPtah, "Button:" + btn.Current.Name); InvokePattern value = (InvokePattern)btn.GetCurrentPattern(InvokePattern.Pattern); value.Invoke(); uAutomation.logTofile(uAutomation._eLogPtah, "Clicked Button"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
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()); } }