public void ClickRightBtnOnAutomationElement(AutomationElement AutoEle, int TerminateStatus, string LogFilePath) { Logger NewLogObj = new Logger(); try { System.Windows.Point clickablePoint = AutoEle.GetClickablePoint(); if (clickablePoint != null) { System.Drawing.Point p = new System.Drawing.Point(Convert.ToInt32(clickablePoint.X), Convert.ToInt32(clickablePoint.Y)); Microsoft.Test.Input.Mouse.MoveTo(p); Microsoft.Test.Input.Mouse.Click(Microsoft.Test.Input.MouseButton.Right); } else { AutomationElementIdentity GuiObj = new AutomationElementIdentity(); GuiObj.GetPositionFromBoundingRectangleAndClick(AutoEle, LogFilePath, "Right"); } //else //{ // NewLogObj.WriteLogFile(LogFilePath, "Unable tp get the clickable point", "fail"); // if (TerminateStatus == 1) // { // NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); // NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ClickOnAutomationElement**", "fail"); // Environment.Exit(1); // } //} } catch (Exception Ex) { // NewLogObj.WriteLogFile(LogFilePath, "Exception at ClickOnAutomationElement" + Ex.ToString(), "fail"); // if (TerminateStatus == 1) // { // NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); // NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ClickOnAutomationElement**", "fail"); // Environment.Exit(1); // } // else // { // NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); // } AutomationElementIdentity GuiObj = new AutomationElementIdentity(); GuiObj.GetPositionFromBoundingRectangleAndClick(AutoEle, LogFilePath, "Left"); } }
//######################################################################################### // Check the Xencenter server node tree for an element //Will perform a click on the found element if 'Click' is set to 1. ClickMouseBtn should be either left or right. will simulate right or left click //######################################################################################### public AutomationElement CheckXenCenterServerNodetree(AutomationElement XenCenterObj, string ElementToCheck, string LogFilePath, int TerminateStatus, int ClickRequired, string ClickMouseBtn) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "CheckXenCenterServerNodetree", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); try { PropertyCondition TreeReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "treeView", 1, LogFilePath); AutomationElement ServerPane = GuiObj.FindAutomationElement(XenCenterObj, TreeReturnCondition, TreeScope.Descendants, "Server Paniewe V", 0, LogFilePath); PropertyCondition XenCenterParentCondition = GuiObj.SetPropertyCondition("NameProperty", "XenCenter", 1, LogFilePath); AutomationElement XenCenterParentElement = GuiObj.FindAutomationElement(ServerPane, XenCenterParentCondition, TreeScope.Descendants, "XenCenterParentElement", 0, LogFilePath); if (ClickRequired == 1) { int PatternSupport = GuiObj.CheckIfPatternIsSupported(XenCenterParentElement, "ExpandCollapse"); if (PatternSupport == 1) { ExpandCollapsePattern expPattern = XenCenterParentElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; Thread.Sleep(1000); if (string.Compare(expPattern.Current.ExpandCollapseState.ToString(), "Collapsed") == 0) { expPattern.Expand(); } } } TestAPI TestApiObj = new TestAPI(); //TestApiObj.ClickLeftBtnOnAutomationElement(XenCenterParentElement, 1, LogFilePath); //AutomationElement SearchElement = GuiObj.GetTheTreeElement(XenCenterParentElement, ElementToCheck, LogFilePath); AutomationElement SearchElement = GuiObj.CheckTreeForElementAndClickIfReqd(XenCenterParentElement, ElementToCheck, 0, "0", LogFilePath); if (SearchElement != null && ClickRequired == 1) { //TestApiObj.ClickLeftBtnOnAutomationElement(SearchElement, 1, LogFilePath); //SelectionItemPattern SelectionPattern = SearchElement.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; //SelectionPattern.Select(); GuiObj.GetPositionFromBoundingRectangleAndClick(SearchElement, LogFilePath, ClickMouseBtn); } if (SearchElement != null) { NewLogObj.WriteLogFile(LogFilePath, "SearchElement found", "info"); return(SearchElement); } else { NewLogObj.WriteLogFile(LogFilePath, "SearchElement returnd is null", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from CheckXenCenterServerNodetree as SearchElement returnd is null**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); return(null); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); return(null); } } } catch (Exception Ex) { NewLogObj.WriteLogFile(LogFilePath, "Exception at ClickOnXenCenterNode" + Ex.ToString(), "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ClickOnXenCenterNode as main menunot found**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); return(null); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); return(null); } } }
public void ConnectToXenserver(AutomationElement XenCenterObj, string ServerName, string LogFilePath, int TerminateStatus, string Password) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "ConnectToXenserver", "info"); NewLogObj.WriteLogFile(LogFilePath, "=================", "info"); int ConnecToServerTimeOut = 60000; AutomationElementIdentity GuiObj = new AutomationElementIdentity(); try { AutomationElement XenCenterNodeFound = ClickOnXenCenterNode(XenCenterObj, LogFilePath, TerminateStatus); if (XenCenterNodeFound != null) { // AutomationElement ServerNodeFound = GuiObj.GetTheTreeElement(XenCenterNodeFound, ServerName, LogFilePath); AutomationElement ServerNodeFound = GuiObj.CheckTreeForElementAndClickIfReqd(XenCenterNodeFound, ServerName, 0, "0", LogFilePath); if (ServerNodeFound == null) { NewLogObj.WriteLogFile(LogFilePath, "ServerNodeFound is null", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ConnectToXenserver as ConnecToServerTimeOut**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); } } //PropertyCondition ServerNodeCondition = GuiObj.SetPropertyCondition("NameProperty", ServerName, 1, LogFilePath); //AutomationElement ServerNodeFound = GuiObj.FindAutomationElement(XenCenterNodeFound, ServerNodeCondition, TreeScope.Descendants, "Server node", 0, LogFilePath); ExpandCollapsePattern expPattern = ServerNodeFound.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; Thread.Sleep(1000); string CurrentState = expPattern.Current.ExpandCollapseState.ToString(); NewLogObj.WriteLogFile(LogFilePath, "ServerNodeFound CurrentState " + CurrentState, "info"); if (string.Compare(CurrentState, "LeafNode") == 0) { NewLogObj.WriteLogFile(LogFilePath, "ServerNodeFound is leaf node ", "info"); GuiObj.GetPositionFromBoundingRectangleAndClick(ServerNodeFound, LogFilePath, "Left"); Thread.Sleep(3000); Microsoft.Test.Input.Mouse.Click(Microsoft.Test.Input.MouseButton.Right); Thread.Sleep(3000); System.Windows.Forms.SendKeys.SendWait("c"); Thread.Sleep(1000); //Check for Add new server window PropertyCondition WindowReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "AddServerDialog", 1, LogFilePath); AutomationElement ServerDialogObj = GuiObj.FindAutomationElement(XenCenterObj, WindowReturnCondition, TreeScope.Descendants, "Add New Server Window", 1, LogFilePath); PropertyCondition PasswordReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "PasswordTextBox", 1, LogFilePath); AutomationElement PasswordTextBoxObj = GuiObj.FindAutomationElement(ServerDialogObj, PasswordReturnCondition, TreeScope.Descendants, "PasswordTextBox", 1, LogFilePath); GuiObj.SetTextBoxText(PasswordTextBoxObj, Password, "PasswordTextBox", 1, LogFilePath); PropertyCondition AddBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "AddButton", 1, LogFilePath); AutomationElement AddBtnObj = GuiObj.FindAutomationElement(ServerDialogObj, AddBtnCondition, TreeScope.Descendants, "AddBtn", 0, LogFilePath); GuiObj.ClickButton(AddBtnObj, 1, "AddBtn", 1, LogFilePath); //PropertyCondition ConnecToServerDialogReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "ConnectingToServerDialog", 1, LogFilePath); //AutomationElement ConnecToServerDialogObj = GuiObj.FindAutomationElement(XenCenterObj, ConnecToServerDialogReturnCondition, TreeScope.Descendants, "ConnectingToServerDialog", 1, LogFilePath); //if (ConnecToServerDialogObj != null) //{ NewLogObj.WriteLogFile(LogFilePath, "ConnecToServerDialogObj found ", "info"); int Timer = 0; while ((string.Compare(CurrentState, "LeafNode") == 0) && (Timer < ConnecToServerTimeOut)) { expPattern = ServerNodeFound.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; CurrentState = expPattern.Current.ExpandCollapseState.ToString(); NewLogObj.WriteLogFile(LogFilePath, "ServerNodeFound CurrentState " + CurrentState, "info"); if (string.Compare(CurrentState, "LeafNode") == 0) { NewLogObj.WriteLogFile(LogFilePath, "Server still the leaf node ", "info"); Thread.Sleep(5000); Timer = Timer + 5000; } else { NewLogObj.WriteLogFile(LogFilePath, "Server is not the leaf node. Server added successfully ", "info"); break; } } if (Timer >= ConnecToServerTimeOut) { NewLogObj.WriteLogFile(LogFilePath, "ServerNodeFound is null even after wait of " + ConnecToServerTimeOut, "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ConnectToXenserver as ConnecToServerTimeOut**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); } } //} //else //{ // NewLogObj.WriteLogFile(LogFilePath, "ConnecToServerDialogObj not found ", "fail"); //} } else { GuiObj.GetPositionFromBoundingRectangleAndClick(ServerNodeFound, LogFilePath, "Left"); } } else { NewLogObj.WriteLogFile(LogFilePath, "ServerNodeFound is null at ConnectToXenserver", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ConnectToXenserver as main menunot found**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); } } } catch (Exception Ex) { NewLogObj.WriteLogFile(LogFilePath, "Exception at ConnectToXenserver" + Ex.ToString(), "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ConnectToXenserver as main menunot found**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); } } }