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"); }
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); } }