public void ClickCancel(AutomationElement SetupDialogObj, string SetUpWindowTitle, string BtnToClick) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "ClickCancel", "info"); NewLogObj.WriteLogFile(LogFilePath, "============", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition CancelBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "551", 1, LogFilePath); AutomationElement CancelBnObj = GuiObj.FindAutomationElement(SetupDialogObj, CancelBtnReturnCondition, TreeScope.Descendants, "Next Btn", 1, LogFilePath); GuiObj.ClickButton(CancelBnObj, 1, "Cancel Button", 1, LogFilePath); Thread.Sleep(2000); //Check if the child iwnodw with "yes"/'No" btns has appeared\ PropertyCondition ChildWndReturnCondition = GuiObj.SetPropertyCondition("NameProperty", SetUpWindowTitle, 1, LogFilePath); AutomationElement ChildWindowObj = GuiObj.FindAutomationElement(SetupDialogObj, ChildWndReturnCondition, TreeScope.Descendants, "Yes No Window", 1, LogFilePath); if (string.Compare(BtnToClick, "yes") == 0) { PropertyCondition YesBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "618", 1, LogFilePath); AutomationElement YesBtnwObj = GuiObj.FindAutomationElement(ChildWindowObj, YesBtnReturnCondition, TreeScope.Descendants, "Yes Btn", 1, LogFilePath); GuiObj.ClickButton(YesBtnwObj, 1, "Yes Button", 1, LogFilePath); } else if (string.Compare(BtnToClick, "no") == 0) { PropertyCondition NoBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "617", 1, LogFilePath); AutomationElement NoBtnwObj = GuiObj.FindAutomationElement(ChildWindowObj, NoBtnReturnCondition, TreeScope.Descendants, "No Btn", 1, LogFilePath); GuiObj.ClickButton(NoBtnwObj, 1, "No Button", 1, LogFilePath); } Thread.Sleep(3000); }
public AutomationElement SelectFromXenCenterTree(AutomationElement XenCenterObj, String TextToSelect, int TerminateStatus, string LogFilePath) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "SelectFromXenCenterTree", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); try { // AutomationElement SearchObj=TypeInXenCenterSearchBox(XenCenterObj, TextToSelect, 1, LogFilePath); 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); ExpandCollapsePattern expPattern = XenCenterParentElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; Thread.Sleep(1000); expPattern.Expand(); PropertyCondition XenCenterElementCondition = GuiObj.SetPropertyCondition("NameProperty", TextToSelect, 1, LogFilePath); AutomationElement XenCenterElementToSearch = GuiObj.FindAutomationElement(ServerPane, XenCenterElementCondition, TreeScope.Descendants, "XenCenterTextToSearch", 1, LogFilePath); ExpandCollapsePattern expPattern1 = XenCenterElementToSearch.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; Thread.Sleep(1000); expPattern1.Expand(); //var e = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right); //e.RoutedEvent = Mouse.MouseDownEvent; //XenCenterElementToSearch.OnMouseDown(e); return(null); } catch (Exception Ex) { NewLogObj.WriteLogFile(LogFilePath, "Exception at SelectFromXenCenterTree" + Ex.ToString(), "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from SelectFromXenCenterTree as main menunot found**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); return(null); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); return(null); } } }
public AutomationElement WaitTillFinishButtonIsActive(PropertyCondition WindowReturnCondition) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "ClickCancWaitTillFinishButtonIsActiveel", "info"); NewLogObj.WriteLogFile(LogFilePath, "===============================", "info"); int Timer = 0; int Timeout = 600000; //10 min AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition FinishBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "589", 1, LogFilePath); AutomationElement FinishBnObj = null; while (FinishBnObj == null && Timer < Timeout) { AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); FinishBnObj = GuiObj.FindAutomationElement(SetupDialogObj, FinishBtnReturnCondition, TreeScope.Descendants, "FinishBtn", 1, LogFilePath); if (FinishBnObj != null) { NewLogObj.WriteLogFile(LogFilePath, "Finish btn is active aftre Xencenter install", "info"); return(FinishBnObj); } Timer = Timer + 3000; Thread.Sleep(3000); } NewLogObj.WriteLogFile(LogFilePath, "Finish btn is not active even aftre Xencenter install timeout", "fail"); return(null); }
public AutomationElement GetXenCenterMainMenuObject(AutomationElement XenCenterObj, string LogFilePath, int TerminateStatus) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "GetXenCenterMainMenuObject", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition MainMenuReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "MainMenuBar", 1, LogFilePath); AutomationElement MainMenuObj = GuiObj.FindAutomationElement(XenCenterObj, MainMenuReturnCondition, TreeScope.Descendants, "XenCenter Main menu", 1, LogFilePath); if (MainMenuObj != null) { return(MainMenuObj); } else { NewLogObj.WriteLogFile(LogFilePath, "XenCenterMainMenu object is null", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from GetXenCenterMainMenuObject as main menunot found**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); return(null); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); return(null); } } }
public AutomationElement FindAndClickBtn(AutomationElement ParentObj, string BtnAutomationID, string ElementName, int TerminateStatus) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "FindAndClickBtn", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); NewLogObj.WriteLogFile(LogFilePath, "ElementName to be checked " + ElementName, "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition BtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", BtnAutomationID, 1, LogFilePath); AutomationElement BtnObj = GuiObj.FindAutomationElement(ParentObj, BtnCondition, TreeScope.Descendants, ElementName, 1, LogFilePath); if (BtnObj == null) { NewLogObj.WriteLogFile(LogFilePath, "BtnObj is null for " + ElementName, "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, "Exiting application from FindAndClickBtn as " + ElementName + " is null", "fail"); Environment.Exit(1); } return(null); } GuiObj.ClickButton(BtnObj, 0, ElementName, 1, LogFilePath); return(BtnObj); }
//####################################################################################################################################### // Will do a Left mouse Click on the XenCenter element //####################################################################################################################################### public AutomationElement ClickOnXenCenterNode(AutomationElement XenCenterObj, string LogFilePath, int TerminateStatus) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "ClickOnXenCenterNode", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); try { // AutomationElement SearchObj=TypeInXenCenterSearchBox(XenCenterObj, TextToSelect, 1, LogFilePath); 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); 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); return(XenCenterParentElement); } 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); } } }
// This can be used when the window with the same automtaion id, will have multiple child windows // eg: All the NEw VM windows and their panel tops have the same wuotmation id. //Using this to get the label of each windows public AutomationElement VerifyWindowOnScreen(AutomationElement XenCenterObj, string ParentAutomationID, string ChildAutomationID, string ExpectedWindowLabel, int TerminateStatus) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "VerifyWindowOnScreen", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); NewLogObj.WriteLogFile(LogFilePath, "Label to be checked " + ExpectedWindowLabel, "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition NewVMWindowCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", ParentAutomationID, 1, LogFilePath); AutomationElement NewVMWindowObj = GuiObj.FindAutomationElement(XenCenterObj, NewVMWindowCondition, TreeScope.Descendants, ParentAutomationID, 1, LogFilePath); ////Locate the panel on window //PropertyCondition PanelWindowCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "panelTop", 1, LogFilePath); //AutomationElement PanelWindowObj = GuiObj.FindAutomationElement(NewVMWindowObj, PanelWindowCondition, TreeScope.Descendants, "New VM", 1, LogFilePath); //Locate the panel on window PropertyCondition LabelWindowCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", ChildAutomationID, 1, LogFilePath); AutomationElement LabelWindowObj = GuiObj.FindAutomationElement(NewVMWindowObj, LabelWindowCondition, TreeScope.Descendants, ChildAutomationID, 1, LogFilePath); NewLogObj.WriteLogFile(LogFilePath, "Panel Label found " + LabelWindowObj.Current.Name, "info"); if (string.Compare(ExpectedWindowLabel, LabelWindowObj.Current.Name) == 0) { NewLogObj.WriteLogFile(LogFilePath, "Expectde window found " + LabelWindowObj.Current.Name, "info"); return(NewVMWindowObj); } else { NewLogObj.WriteLogFile(LogFilePath, "window found is not the expected one " + LabelWindowObj.Current.Name, "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from TypeInXenCenterSearchBox as main menunot found**", "fail"); Environment.Exit(1); return(null); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); return(null); } } }
public AutomationElement TypeInXenCenterSearchBox(AutomationElement XenCenterObj, string TextToType, int TerminateStatus, string LogFilePath) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "TypeInXenCenterSearchBox", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); try { AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition WindowReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "TreeSearchBox", 1, LogFilePath); AutomationElement SearchDialogObj = GuiObj.FindAutomationElement(XenCenterObj, WindowReturnCondition, TreeScope.Descendants, "Search Box", 1, LogFilePath); PropertyCondition TextBoxReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "textBox1", 1, LogFilePath); AutomationElement SearchTextDialogObj = GuiObj.FindAutomationElement(SearchDialogObj, TextBoxReturnCondition, TreeScope.Descendants, "Search Box", 1, LogFilePath); GuiObj.SetTextBoxText(SearchTextDialogObj, TextToType, "Search Box", 1, LogFilePath); string TextSet = GuiObj.GetTextBoxText(SearchTextDialogObj, "Search Box Text", 1, LogFilePath); //MbUnit.Framework.Assert.AreEqual(TextToType, TextSet); return(SearchDialogObj); } catch (Exception Ex) { NewLogObj.WriteLogFile(LogFilePath, "Exception at TypeInXenCenterSearchBox" + Ex.ToString(), "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from TypeInXenCenterSearchBox 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 CheckInterruptedDialog(PropertyCondition SetupDialogObjCondition, string InterruptedDialog) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "CheckInterruptedDialog", "info"); NewLogObj.WriteLogFile(LogFilePath, "============", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, SetupDialogObjCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); PropertyCondition InterruptedDialogReturnCondition = GuiObj.SetPropertyCondition("NameProperty", InterruptedDialog, 1, LogFilePath); AutomationElement InterruptedDialogObj = GuiObj.FindAutomationElement(SetupDialogObj, InterruptedDialogReturnCondition, TreeScope.Descendants, "Finish Btn", 1, LogFilePath); }
public AutomationElement VerifyIfAnElementExistUnderXenCenterTree(AutomationElement XenCenterObj, string ElementName, int TerminateStatus) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "VerifyIfAnElementExistUnderXenCenterTree", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); NewLogObj.WriteLogFile(LogFilePath, "ElementName to be checked " + ElementName, "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); NewLogObj.WriteLogFile(LogFilePath, "Checking in Xencenter tree for element " + ElementName, "info"); //Verify if pool is added from Xencenter tree, by checking if a object with that name exists //Xencenter treeview 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); ExpandCollapsePattern expPattern = XenCenterParentElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; expPattern.Expand(); PropertyCondition AddedEleReturnCondition = GuiObj.SetPropertyCondition("NameProperty", ElementName, 1, LogFilePath); AutomationElement XenCenterAddedeElement = GuiObj.FindAutomationElement(ServerPane, AddedEleReturnCondition, TreeScope.Descendants, "XenCenterParentElement", 0, LogFilePath); if (XenCenterAddedeElement != null) { NewLogObj.WriteLogFile(LogFilePath, ElementName + "Exist in Xencenter tree", "info"); return(XenCenterAddedeElement); } else { NewLogObj.WriteLogFile(LogFilePath, ElementName + "does not exist in Xencenter tree", "info"); return(null); } }
static void Main(string[] args) { AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition NameCond = GuiObj.SetPropertyCondition("NameProperty", "Citrix StoreFront", 1, null); AutomationElement SFObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, NameCond, TreeScope.Children, "parent", null); PropertyCondition GridCond = GuiObj.SetPropertyCondition("AutomationIdProperty", "siteListView", 1, null); AutomationElement GridObj = GuiObj.FindAutomationElement(SFObj, GridCond, TreeScope.Descendants, "parent", null); PropertyCondition DataItemCond = GuiObj.SetPropertyCondition("ControlTypeProperty", "DataItem", 1, null); AutomationElementCollection GridChildren = GridObj.FindAll(TreeScope.Descendants, DataItemCond); Program PgmObj = new Program(); foreach (AutomationElement GridChild in GridChildren) { int Status = PgmObj.CheckRawView(GridChild, "Pass-through from NetScaler Gateway"); if (Status == 1) { Console.WriteLine("Element Found.. Exiting"); } } //AutomationElement DataItem = GuiObj.FindAutomationElement(GridObj, DataItemCond, TreeScope.Descendants, "parent", null); // Program PgmObj = new Program(); // PgmObj.CheckRawView(DataItem, "User name and password"); }
//public void ClickFinishBtn(AutomationElement SetupDialogObj) public void ClickFinishBtn(PropertyCondition SetupDialogObjCondition) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "ClickFinishBtn", "info"); NewLogObj.WriteLogFile(LogFilePath, "============", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, SetupDialogObjCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); PropertyCondition FinishBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "589", 1, LogFilePath); AutomationElement FinishBtnwObj = GuiObj.FindAutomationElement(SetupDialogObj, FinishBtnReturnCondition, TreeScope.Descendants, "Finish Btn", 1, LogFilePath); GuiObj.ClickButton(FinishBtnwObj, 1, "FinishBtnwObj", 1, LogFilePath); }
public void MaximizeXenCenter(AutomationElement XenCenterObj) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "MaximizeXenCenter", "info"); NewLogObj.WriteLogFile(LogFilePath, "=====================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition MaximizedBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "Maximize", 1, LogFilePath); AutomationElement MaximizedBtn = GuiObj.FindAutomationElement(XenCenterObj, MaximizedBtnCondition, TreeScope.Descendants, "XenCenter Maximize Btn", 0, LogFilePath); if (MaximizedBtn != null) { GuiObj.ClickButton(MaximizedBtn, 0, "MaximizedBtn", 1, LogFilePath); } }
public void VerifySetupWindowClosed(string SetUpWindowTitle) { Logger NewLogObj = new Logger(); FileOperations FileObj = new FileOperations(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "VerifySetupWindowClosed", "info"); NewLogObj.WriteLogFile(LogFilePath, "=====================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition WindowReturnCondition = GuiObj.SetPropertyCondition("NameProperty", SetUpWindowTitle, 1, LogFilePath); AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 0, LogFilePath); if (SetupDialogObj == null) { NewLogObj.WriteLogFile(LogFilePath, "SetupDialog not closed even after clicking on finish btn", "fail"); NewLogObj.WriteLogFile(LogFilePath, "Exiting test", "fail"); FileObj.ExitTestEnvironment(); } else { NewLogObj.WriteLogFile(LogFilePath, "SetupDialog closed after clicking on finish btn", "pass"); } }
public AutomationElement SetFocusOnWindow(AutomationElement ParentObject, string PropertyCondName, string PropertyCondData, TreeScope Scope, string ElementName, int TerminateStatus, string LogFilePath) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "SetFocusOnWindow", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); AutomationElementIdentity NewElement = new AutomationElementIdentity(); PropertyCondition WindowReturnCondition = NewElement.SetPropertyCondition(PropertyCondName, PropertyCondData, 1, LogFilePath); int WaitTimeOut = 30000; // 5min int timer = 0; if (WindowReturnCondition != null) { AutomationElement NewWindowObj = NewElement.FindAutomationElement(ParentObject, WindowReturnCondition, Scope, ElementName, 0, LogFilePath); if (NewWindowObj != null) { //NewGuiZardObj.StartNewTest(); NewLogObj.WriteLogFile(LogFilePath, "Object with name " + ElementName + "found", "info"); IntPtr hwnd = (IntPtr)NewWindowObj.Current.NativeWindowHandle; SetForegroundWindow(hwnd); Thread.Sleep(2000); SetActiveWindow(hwnd); Thread.Sleep(2000); MaximizeXenCenter(NewWindowObj); // NewGuiZardObj.VerifyTestCompletedFilePresent("XenCenter Main Window"); return(NewWindowObj); } else { while (timer < WaitTimeOut && NewWindowObj == null) { NewWindowObj = NewElement.FindAutomationElement(ParentObject, WindowReturnCondition, Scope, ElementName, 0, LogFilePath); NewLogObj.WriteLogFile(LogFilePath, "Waiting for Object with name " + ElementName, "info"); if (NewWindowObj == null) { timer = timer + 3000; Thread.Sleep(3000); } else { NewLogObj.WriteLogFile(LogFilePath, "Object with name" + ElementName + "found", "info"); IntPtr hwnd = (IntPtr)NewWindowObj.Current.NativeWindowHandle; SetForegroundWindow(hwnd); Thread.Sleep(2000); SetActiveWindow(hwnd); Thread.Sleep(2000); return(NewWindowObj); } } if (timer < WaitTimeOut && NewWindowObj == null) { NewLogObj.WriteLogFile(LogFilePath, "Object with name" + ElementName + "not found from SetFocusOnWindow", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, "***Exiting Application from SetFocusOnWindow***", "fail"); //Application.Exit(); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } } return(null); } } else { NewLogObj.WriteLogFile(LogFilePath, "WindowReturnCondition is null", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, "***Exiting Application from SetFocusOnWindow***", "fail"); //Application.Exit(); } return(null); } }
public void CheckXenCenterInstalledVersion(string HelpMenu, string AboutXenCenterMenu, string XenCenterVersion) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "CheckXenCenterInstalledVersion", "info"); NewLogObj.WriteLogFile(LogFilePath, "==============================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); XenCenter NewOprtorObj = new XenCenter(); FileOperations FileObj = new FileOperations(); NewOprtorObj.OpenXenCenter(LogFilePath); Thread.Sleep(2000); AutomationElement NewAutoObj = NewOprtorObj.SetFocusOnWindow(AutomationElement.RootElement, "NameProperty", "XenCenter", TreeScope.Children, "XenCenter", 1, LogFilePath); int WaitTimeOut = 300000;//5 mins int timer = 0; while (NewAutoObj == null && timer < WaitTimeOut) { NewAutoObj = NewOprtorObj.SetFocusOnWindow(AutomationElement.RootElement, "NameProperty", "XenCenter", TreeScope.Children, "XenCenter", 1, LogFilePath); Thread.Sleep(2000); timer = timer + 2000; NewLogObj.WriteLogFile(LogFilePath, "Waiting for Xencenter to open", "info"); Console.WriteLine("Waiting for Xencenter to open "); } if (NewAutoObj == null && timer >= WaitTimeOut) { Console.WriteLine("Timeout waiting for Xencenter to open after installation.Exiting.. "); NewLogObj.WriteLogFile(LogFilePath, "Timeout waiting for Xencenter to open after installation.Exiting.. ", "fail"); FileObj.ExitTestEnvironment(); } NewLogObj.WriteLogFile(LogFilePath, "Xencenter has opened after installation", "info"); Console.WriteLine("Xencenter has opened after installation "); //Check if periodic update cjheck window has come //Commenting for demo.. Remmber to uncomment ***************************************** //PropertyCondition AllowUpdateWindowCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "AllowUpdatesDialog", 1, LogFilePath); //AutomationElement AllowUpdatesDialog = GuiObj.FindAutomationElement(NewAutoObj, AllowUpdateWindowCondition, TreeScope.Children, "AllowUpdatesDialog", 0, LogFilePath); //WaitTimeOut = 60000;//1 mins //timer = 0; //while (AllowUpdatesDialog == null && timer < WaitTimeOut) //{ // AllowUpdatesDialog = GuiObj.FindAutomationElement(NewAutoObj, AllowUpdateWindowCondition, TreeScope.Children, "AllowUpdatesDialog", 0, LogFilePath); // Thread.Sleep(3000); // timer = timer + 3000; // NewLogObj.WriteLogFile(LogFilePath, "Waiting for AllowUpdatesDialog to open", "info"); // Console.WriteLine("Waiting for AllowUpdatesDialog to open "); //} //if (AllowUpdatesDialog == null && timer >= WaitTimeOut) //{ // Console.WriteLine("Timeout waiting for AllowUpdatesDialog to open after installation. "); // NewLogObj.WriteLogFile(LogFilePath, "Timeout waiting for AllowUpdatesDialog to open after installation. ", "fail"); // //Environment.Exit(1); //} //if (AllowUpdatesDialog != null) //{ // NewLogObj.WriteLogFile(LogFilePath, "AllowUpdatesDialog has opened after installation", "info"); // Console.WriteLine("AllowUpdatesDialog has opened after installation "); // NewLogObj.WriteLogFile(LogFilePath, "AllowUpdatesDialog found after installation", "info"); // PropertyCondition YesBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "YesButton", 1, LogFilePath); // AutomationElement YesBtnObj = GuiObj.FindAutomationElement(AllowUpdatesDialog, YesBtnCondition, TreeScope.Children, "YesBtn", 1, LogFilePath); // GuiObj.ClickButton(YesBtnObj, 1, "YesBtnObj", 1, LogFilePath); // Thread.Sleep(1000); //} //Commenting for demo.. Remmber to uncomment ***************************************** NewOprtorObj.InvokeXenCenterSubMenuItem(NewAutoObj, HelpMenu, AboutXenCenterMenu, LogFilePath, 1); Thread.Sleep(3000); PropertyCondition AboutDialogCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "AboutDialog", 1, LogFilePath); AutomationElement AboutDialogObj = GuiObj.FindAutomationElement(NewAutoObj, AboutDialogCondition, TreeScope.Children, "AboutDialog", 1, LogFilePath); PropertyCondition TblLayoutCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "tableLayoutPanel1", 1, LogFilePath); AutomationElement TblLayoutObj = GuiObj.FindAutomationElement(AboutDialogObj, TblLayoutCondition, TreeScope.Children, "AboutDialog", 1, LogFilePath); //Get the version PropertyCondition VersionLabelCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "VersionLabel", 1, LogFilePath); AutomationElement VersionLabelObj = GuiObj.FindAutomationElement(TblLayoutObj, VersionLabelCondition, TreeScope.Children, "AboutDialog", 1, LogFilePath); string VersionNumber = VersionLabelObj.Current.Name.ToString(); NewLogObj.WriteLogFile(LogFilePath, "VersionNumber found after install *" + VersionNumber + "*", "info"); NewLogObj.WriteLogFile(LogFilePath, "Expected VersionNumber XenCenterVersion *" + XenCenterVersion + "*", "info"); if (string.Compare(XenCenterVersion, VersionNumber) == 0) { NewLogObj.WriteLogFile(LogFilePath, "Right version of Xencenter installed " + VersionNumber, "pass"); } else { NewLogObj.WriteLogFile(LogFilePath, "Wrong version of Xencenter installed. Version found from Xenvcenter " + VersionNumber + "Version from inputs file " + XenCenterVersion, "fail"); } PropertyCondition OKBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "OkButton", 1, LogFilePath); AutomationElement OKBtnObj = GuiObj.FindAutomationElement(TblLayoutObj, OKBtnCondition, TreeScope.Children, "OKBtnObj", 1, LogFilePath); GuiObj.ClickButton(OKBtnObj, 1, "OKBtnObj", 1, LogFilePath); }
public void InvokeXenCenterSubMenuItem(AutomationElement XenCenterObj, string MenuName, string MenuItem, string LogFilePath, int TerminateStatus) { Logger NewLogObj = new Logger(); NewLogObj.WriteLogFile(LogFilePath, "InvokeXenCenterSubMenuItem", "info"); NewLogObj.WriteLogFile(LogFilePath, "=============================", "info"); try { AutomationElement XenCenterMainMenuObj = GetXenCenterMainMenuObject(XenCenterObj, LogFilePath, TerminateStatus); if (XenCenterMainMenuObj != null) { AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition MainMenuReturnCondition = GuiObj.SetPropertyCondition("NameProperty", MenuName, TerminateStatus, LogFilePath); AutomationElement MainMenuObj = GuiObj.FindAutomationElement(XenCenterMainMenuObj, MainMenuReturnCondition, TreeScope.Descendants, "XenCenter Sub menu", 1, LogFilePath); //ExpandCollapsePattern expPattern = MainMenuObj.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; //expPattern.Expand(); PropertyCondition SubMenuReturnCondition = GuiObj.SetPropertyCondition("NameProperty", MenuItem, 1, LogFilePath); AutomationElement SubMenuObj = GuiObj.FindAutomationElement(MainMenuObj, SubMenuReturnCondition, TreeScope.Descendants, MenuItem, TerminateStatus, LogFilePath); if (SubMenuObj != null) { InvokePattern invokePattern = SubMenuObj.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; if (invokePattern != null) { NewLogObj.WriteLogFile(LogFilePath, "Invoking menuitem" + MenuItem, "info"); invokePattern.Invoke(); } else { NewLogObj.WriteLogFile(LogFilePath, "invokePattern is null", "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from GetXenCenterMainMenuObject as invokePattern is null**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } } } else { NewLogObj.WriteLogFile(LogFilePath, "SubMenuObj is null", "fail"); } } else { NewLogObj.WriteLogFile(LogFilePath, "XenCenterMainMenuObj is null", "fail"); } } catch (Exception Ex) { NewLogObj.WriteLogFile(LogFilePath, "Exception at InvokeXenCenterSubMenuItem" + Ex.ToString(), "fail"); if (TerminateStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info"); NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from GetXenCenterMainMenuObject as main menunot found**", "fail"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } else { NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info"); } } }
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"); } } }
static void Main(string[] args) { string XenCenterInstallStatusFile = "C:\\XenCenterInstalled.txt"; String TestStatus = "Pass"; Logger NewLogObj = new Logger(); NewLogObj.CreateLogFolder(); string LogFilePath = NewLogObj.CreateLogFile(); NewLogObj.WriteLogFile(LogFilePath, "Test : Installer", "info"); NewLogObj.WriteLogFile(LogFilePath, "======================", "info"); if (File.Exists(XenCenterInstallStatusFile)) { File.Delete(XenCenterInstallStatusFile); } FileOperations FileObj = new FileOperations(); string InputFilePath = FileObj.GetInputFilePath(LogFilePath, "Inputs.txt"); string InstallerLocation = FileObj.GetInputPattern(InputFilePath, "InstallerLocation"); string InstallerProcessName = FileObj.GetInputPattern(InputFilePath, "InstallerProcessName"); string LocationToInstallXenCenter = FileObj.GetInputPattern(InputFilePath, "LocationToInstallXenCenter"); string XenCenterVersion = FileObj.GetInputPattern(InputFilePath, "XenCenterVersion"); string SetUpWindowTitle = "Citrix XenCenter Setup"; string InterruptedDialog = "Citrix XenCenter Setup Wizard was interrupted"; string HelpMenu = "&Help"; string AboutXenCenterMenu = "&About XenCenter"; string LocalizedFilePath = FileObj.GetLocalizedFilePath(); //if (LocalizedFilePath != null) //{ SetUpWindowTitle = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, SetUpWindowTitle); InterruptedDialog = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, InterruptedDialog); HelpMenu = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, HelpMenu); AboutXenCenterMenu = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, AboutXenCenterMenu); //} //else //{ // //Substitue the & // HelpMenu = FileObj.RemovePatternFromString(HelpMenu, "&"); // AboutXenCenterMenu = FileObj.RemovePatternFromString(AboutXenCenterMenu, "&"); //} //string InputFilePath1 = FileObj.GetInputFilePath(LogFilePath, "Mapped_CH.txt"); //string SetupWindowTitle = FileObj.SearchFileForPattern(InputFilePath1, "Citrix XenCenter Setup", 1, LogFilePath); //int IndexEqual2 = SetupWindowTitle.IndexOf("="); //SetupWindowTitle = SetupWindowTitle.Substring(IndexEqual2 + 1); Console.WriteLine("InstallerLocation " + InstallerLocation); Console.WriteLine("InstallerProcessName " + InstallerProcessName); Generic GenricObj = new Generic(); GenricObj.StartProcess(InstallerLocation, InstallerProcessName, LogFilePath, 1); Thread.Sleep(5000); //Console.WriteLine("handling UAC"); ////Assuming that UAC prompt is on the screen //System.Windows.Forms.SendKeys.SendWait("{LEFT}"); //Thread.Sleep(1000); //System.Windows.Forms.SendKeys.SendWait("{ENTER}"); //Thread.Sleep(3000); // Console.WriteLine("Click send to UAC"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition WindowReturnCondition = GuiObj.SetPropertyCondition("NameProperty", SetUpWindowTitle, 1, LogFilePath); AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); Console.WriteLine("Checking for SetupDialog "); NewLogObj.WriteLogFile(LogFilePath, "Checking for SetupDialog", "info"); int WaitTimeOut = 240000;//3 mins int timer = 0; while (SetupDialogObj == null && timer < WaitTimeOut) { SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); Thread.Sleep(3000); timer = timer + 3000; NewLogObj.WriteLogFile(LogFilePath, "Waiting for SetupDialog", "info"); Console.WriteLine("Waiting for SetupDialog "); } if (SetupDialogObj == null && timer < WaitTimeOut) { Console.WriteLine("Timeout waiting for setup dialog obj.Exiting.. "); Console.WriteLine("Timeout waiting for SetupDialog obj.Exiting.. "); FileObj.ExitTestEnvironment(); } NewLogObj.WriteLogFile(LogFilePath, "SetupDialog obj found", "info"); Console.WriteLine("SetupDialog obj found "); //Click cancel btn & verify actions Program PgmObj = new Program(); PgmObj.ClickCancel(SetupDialogObj, SetUpWindowTitle, "yes"); PgmObj.CheckInterruptedDialog(WindowReturnCondition, InterruptedDialog); PgmObj.ClickFinishBtn(WindowReturnCondition);; //Start installer again GenricObj.StartProcess(InstallerLocation, InstallerProcessName, LogFilePath, 1); Thread.Sleep(3000); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); timer = 0; while (SetupDialogObj == null && timer < WaitTimeOut) { SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); Thread.Sleep(3000); timer = timer + 3000; NewLogObj.WriteLogFile(LogFilePath, "Waiting for SetupDialog", "info"); Console.WriteLine("Waiting for SetupDialog "); } if (SetupDialogObj == null && timer < WaitTimeOut) { Console.WriteLine("Timeout waiting for setup dialog obj.Exiting.. "); Console.WriteLine("Timeout waiting for SetupDialog obj.Exiting.. "); FileObj.ExitTestEnvironment(); } //Click cancel & no PgmObj.ClickCancel(SetupDialogObj, SetUpWindowTitle, "no"); //Verify SetupDialogObj is still there SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); if (SetupDialogObj != null) { NewLogObj.WriteLogFile(LogFilePath, "SetupDialogObj is there after pressing on no btn", "info"); } PropertyCondition NextBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "613", 1, LogFilePath); AutomationElement NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Descendants, "Next Btn", 1, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); ////Destination text //PropertyCondition DestinationTextReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "679", 1, LogFilePath); //AutomationElement DestinationTextObj = GuiObj.FindAutomationElement(SetupDialogObj, DestinationTextReturnCondition, TreeScope.Descendants, "Xencenter install DestinationTextObj", 1, LogFilePath); //Click on browse btn PropertyCondition BrowseBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "683", 1, LogFilePath); AutomationElement BrowseBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, BrowseBtnReturnCondition, TreeScope.Descendants, "Next Btn", 1, LogFilePath); GuiObj.ClickButton(BrowseBtnObj, 1, "Browse Button", 1, LogFilePath); //Verify if child winodw with xencenter location has apperaed AutomationElement LocationChildWndObj = GuiObj.FindAutomationElement(SetupDialogObj, WindowReturnCondition, TreeScope.Descendants, "Xencenter install location browse", 1, LogFilePath); //LOcate the textbox having location PropertyCondition LocationEditCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "547", 1, LogFilePath); AutomationElement LocationObj = GuiObj.FindAutomationElement(LocationChildWndObj, LocationEditCondition, TreeScope.Descendants, "Xencenter install location edit box", 1, LogFilePath); GuiObj.SetTextBoxText(LocationObj, LocationToInstallXenCenter, "Xencenter Install location textbox", 1, LogFilePath); PropertyCondition OKBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "549", 1, LogFilePath); AutomationElement OKbtnObj = GuiObj.FindAutomationElement(LocationChildWndObj, OKBtnCondition, TreeScope.Descendants, "Xencenter install location edit box", 1, LogFilePath); GuiObj.ClickButton(OKbtnObj, 1, "OK Button", 1, LogFilePath); Thread.Sleep(2000); //find the radio btns PropertyCondition ForAllRadioBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "507", 1, LogFilePath); AutomationElement ForAllradioBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, ForAllRadioBtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.SetRadioButton(ForAllradioBtnObj, "Install for all radioBytn", 1, LogFilePath); Thread.Sleep(1000); PropertyCondition ForMeRadioBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "781", 1, LogFilePath); AutomationElement ForMeradioBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, ForMeRadioBtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.SetRadioButton(ForMeradioBtnObj, "Install for me radioBytn", 1, LogFilePath); Thread.Sleep(1000); //Click next btn PropertyCondition Next1BtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "613", 1, LogFilePath); AutomationElement Next1BtnObj = GuiObj.FindAutomationElement(SetupDialogObj, Next1BtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.ClickButton(Next1BtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); //Click install btn PropertyCondition InstallBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "648", 1, LogFilePath); AutomationElement InstallBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, InstallBtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.ClickButton(InstallBtnObj, 1, "Install Button", 1, LogFilePath); AutomationElement FinishBtnObj = PgmObj.WaitTillFinishButtonIsActive(WindowReturnCondition); if (FinishBtnObj == null) { NewLogObj.WriteLogFile(LogFilePath, "Xencenter installation timeout", "fail"); NewLogObj.WriteLogFile(LogFilePath, "Exiting ...", "fail"); FileObj.ExitTestEnvironment(); } GuiObj.ClickButton(FinishBtnObj, 0, "Finish Button", 1, LogFilePath); File.Create(XenCenterInstallStatusFile); PgmObj.CheckXenCenterInstalledVersion(HelpMenu, AboutXenCenterMenu, XenCenterVersion); FileObj.FinishCurrentTest("Installer"); }
//######################################################################################### // 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); } } }
static void Main(string[] args) { Logger NewLogObj = new Logger(); NewLogObj.CreateLogFolder(); string LogFilePath = NewLogObj.CreateLogFile(); NewLogObj.WriteLogFile(LogFilePath, "Test : InstallTextExecute", "info"); NewLogObj.WriteLogFile(LogFilePath, "======================", "info"); Console.WriteLine("Starting testexceute installation"); //This file will be used by another scripts to verify that test complete installed successfully string StatusFilePath = "C:\\TestCompleteInstalledSuccess.txt"; if (File.Exists(StatusFilePath)) { File.Delete(StatusFilePath); } Console.WriteLine("Starting the process testexceute "); System.Diagnostics.Process.Start("C:\\testexecute80.exe"); Thread.Sleep(10000); Console.WriteLine("process started "); //Process[] pname = Process.GetProcessesByName("testexecute80.exe"); //if (pname.Length == 0) //{ // NewLogObj.WriteLogFile(LogFilePath, "Uable to start testexecute", "fail"); // Environment.Exit(1); //} //Will take some time for the installer to launch & unzip file Thread.Sleep(15000); int WindowWaitTimeOut = 3000000; int timer = 0; AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition WindowReturnCondition = GuiObj.SetPropertyCondition("NameProperty", "AutomatedQA TestExecute 8 - InstallShield Wizard", 1, LogFilePath); AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); Console.WriteLine("Looking for setupdailaog "); while (SetupDialogObj == null && timer < WindowWaitTimeOut) { SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); timer = timer + 3000; Thread.Sleep(3000); } if (SetupDialogObj == null && timer >= WindowWaitTimeOut) { NewLogObj.WriteLogFile(LogFilePath, "Uable to find testexecute window even after timeout. Exiting ..", "fail"); Environment.Exit(1); } int WaitForNextBtn = 300000; timer = 0; Console.WriteLine("Looking for nexr btn "); PropertyCondition NextBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "1", 1, LogFilePath); AutomationElement NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); while (NextBtnObj == null && timer < WaitForNextBtn) { SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); if (SetupDialogObj != null) { NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); } Thread.Sleep(3000); timer = timer + 3000; } if (NextBtnObj == null && timer >= WaitForNextBtn) { NewLogObj.WriteLogFile(LogFilePath, "Uable to find Next btn even after timeout. Exiting ..", "fail"); Environment.Exit(1); } GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); PropertyCondition AcceptReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "1000", 1, LogFilePath); AutomationElement AcceptObj = GuiObj.FindAutomationElement(SetupDialogObj, AcceptReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.SetRadioButton(AcceptObj, "Accept license", 1, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); //Wait for Installation complete window int InstallationTimeout = 1200000; // 20 mins int InstallationTimer = 0; SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); PropertyCondition InstallationCompleteLabelCondition = GuiObj.SetPropertyCondition("NameProperty", "TestExecute Installation Complete", 1, LogFilePath); AutomationElement InstallCompleteLabelObj = GuiObj.FindAutomationElement(SetupDialogObj, InstallationCompleteLabelCondition, TreeScope.Children, "TestExecute install complete label", 0, LogFilePath); while (InstallCompleteLabelObj == null && InstallationTimer < InstallationTimeout) { Thread.Sleep(5000); InstallationTimer = InstallationTimer + 5000; SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); if (SetupDialogObj != null) { InstallCompleteLabelObj = GuiObj.FindAutomationElement(SetupDialogObj, InstallationCompleteLabelCondition, TreeScope.Children, "TestExecute install complete label", 0, LogFilePath); } } if (InstallCompleteLabelObj == null && InstallationTimer >= InstallationTimeout) { NewLogObj.WriteLogFile(LogFilePath, "Testexecute installation timed out.. Exiting", "fail"); Environment.Exit(1); } if (InstallCompleteLabelObj != null) { NewLogObj.WriteLogFile(LogFilePath, "Testexecute installaticompleted", "info"); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "TestExecute Setup window", 0, LogFilePath); NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Children, "Next Btn", 0, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Finsih Button", 1, LogFilePath); //Create status file File.Create(StatusFilePath); } }