public AutomationElement WiatTillXenCenterHandleIsObtained() { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "WiatTillXenCenterHandleIsObtained", "info"); NewLogObj.WriteLogFile(LogFilePath, "================================", "info"); XenCenter NewOprtorObj = new XenCenter(); 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(3000); timer = timer + 3000; 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"); FileOperations FileObj = new FileOperations(); FileObj.ExitTestEnvironment(); } NewLogObj.WriteLogFile(LogFilePath, "Xencenter has opened after installation", "info"); Console.WriteLine("Xencenter has opened after installation "); Guizard NewGuiZardObj = new Guizard(); NewGuiZardObj.StartNewTest("GUizardlocation");//Edited for keywr // NewGuiZardObj.VerifyTestCompletedFilePresent("XenCenter Main Window"); --> Commenting as this takes a lot of time return(NewAutoObj); }
public int FinishCurrentTest(AutomationElement ParentObj) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "FinishCurrentTest", "info"); NewLogObj.WriteLogFile(LogFilePath, "====================", "info"); FileOperations FileObj = new FileOperations(); //string GuizardPathFile = Directory.GetCurrentDirectory() + "//GuizardPathFile.txt"; //string GuiZardLocation = FileObj.GetInputPattern(GuizardPathFile, "GuizardLocation"); Generic NewGenericObj = new Generic(); try { string SystemLocale = NewGenericObj.GetSystemLocale(); //NewLogObj.WriteLogFile(LogFilePath, "SystemLocale " + SystemLocale, "info"); string InputFileName = Directory.GetCurrentDirectory() + "\\Inputs\\Inputs_" + SystemLocale + ".txt"; string GuiZardLocation = FileObj.GetInputPattern(InputFileName, "GuiZardLocation"); string CurrentFileName = Environment.GetCommandLineArgs()[1]; //Remove the .txt part string Testname = CurrentFileName.Substring(0, CurrentFileName.Length - 4); //Check if guizard is running string GuizardResultsFolder = null; int ProcessStatus = NewGenericObj.CheckIfProcessIsRunning("GUIzard_3"); if (ProcessStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, "Guizard is running. Verifying Guizard results", "info"); Guizard NewGuiZardObj = new Guizard(); //Verify results of GUizard GuizardResultsFolder = NewGuiZardObj.VerifyGuiZardResults(Testname); //NewGuiZardObj.VerifyGuiZardResults(Testname); //GuizardResultsFolder = "C:\\TestResults\\" + Testname; NewGuiZardObj.CreateGuizardStopTestFile(GuiZardLocation); //Giving enough time for guizard to close NewGuiZardObj.WaitTillGuizardClose(); } else { NewLogObj.WriteLogFile(LogFilePath, "Guizard is not running.", "info"); } //Close the XenCenter AutomationElementIdentity GuiObj = new AutomationElementIdentity(); GuiObj.CloseChildWindowsUnderParent(ParentObj, 0); //check if process is still running string ParentProcessName = FileObj.GetInputPattern(InputFileName, "ParentProcessName"); int ParentProcessStatus = NewGenericObj.CheckIfProcessIsRunning(ParentProcessName); if (ParentProcessStatus == 1) { NewLogObj.WriteLogFile(LogFilePath, "Process " + ParentProcessName + "still running even after close. Killing the parent process", "fail"); NewGenericObj.KillProcess(ParentProcessName, LogFilePath); } //int Status = ReadLogFileForStatus(Testname); string TempStatus = ReadLogFileForStatus(Testname); string[] Temp = null; string TempStr = null; string Status = null; string FailureSummary = null; if (string.Compare(TempStatus, "1") == 0) { Status = "1"; } else { Temp = Regex.Split(TempStatus, ":"); Status = Temp[0]; //if(Status==1) //Extracting the fail summary int IndexFontColor = Temp[4].IndexOf("="); TempStr = Temp[4].Substring(IndexFontColor); if (Regex.IsMatch(TempStr, "guizard", RegexOptions.IgnoreCase)) { FailureSummary = "GUIZard failures"; } else { int MarkerIndex1 = TempStr.IndexOf(">"); int MarkerIndex2 = TempStr.IndexOf("<"); FailureSummary = TempStr.Substring(MarkerIndex1 + 1, MarkerIndex2 - (MarkerIndex1 + 1)); } } if (string.Compare(Status, "1") == 0) { //NewLogObj.WriteLogFile(LogFilePath, "*******************************************", "info"); NewLogObj.WriteLogFile(LogFilePath, "Test " + Testname + " PASS", "PASS"); //NewLogObj.WriteLogFile(LogFilePath, "*******************************************", "info"); NewLogObj.WriteToTestSummaryFile(Testname, "PASS", GuizardResultsFolder, "NA"); } //else if(Status==-1) else if (string.Compare(Status, "-1") == 0) { //NewLogObj.WriteLogFile(LogFilePath, "*******************************************", "info"); NewLogObj.WriteLogFile(LogFilePath, "Test " + Testname + " FAIL", "FAIL"); //NewLogObj.WriteLogFile(LogFilePath, "*******************************************", "info"); NewLogObj.WriteToTestSummaryFile(Testname, "FAIL", GuizardResultsFolder, FailureSummary); } //else if (Status == 0) else if (string.Compare(Status, "0") == 0) { //NewLogObj.WriteLogFile(LogFilePath, "*******************************************", "info"); NewLogObj.WriteLogFile(LogFilePath, "Test " + Testname + " FAIL", "FAIL"); //NewLogObj.WriteLogFile(LogFilePath, "*******************************************", "info"); NewLogObj.WriteToTestSummaryFile(Testname, "FAIL", GuizardResultsFolder, FailureSummary); string RerunFilePattern = "^ReRun"; if (Regex.IsMatch(CurrentFileName, RerunFilePattern)) { Console.WriteLine("Rerun pattern found in filename. Exiting"); Environment.Exit(1); Console.WriteLine("Exiting"); } else { //Check if rerun is required CheckIfRerunRequired(); } } } catch (Exception Ex) { NewLogObj.WriteLogFile(LogFilePath, "Exception at FinsihCurrentTest " + Ex.ToString(), "warn"); } return(1); }
static void Main(string[] args) { XenCenter NewOprtorObj = new XenCenter(); Logger NewLogObj = new Logger(); NewLogObj.CreateLogFolder(); string LogFilePath = NewLogObj.CreateLogFile(); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); Guizard NewGuiZardObj = new Guizard(); FileOperations FileObj = new FileOperations(); Generic GenericObj = new Generic(); XenServer XenObj = new XenServer(); // Session session =XenObj.Login("10.105.83.51", 80, "root", "citrix"); // XenObj.GetVMParam(session, "GSEN-Win7x86_29aug2012_1", "IP"); Generic NewGenericObj = new Generic(); //int ProcessStatus = NewGenericObj.CheckIfProcessIsRunning("GUIzard_3"); FileObj.FinishCurrentTest("MyTest"); //string cur = Thread.CurrentThread.CurrentCulture.Name; //CultureInfo us = new CultureInfo("zh-CN"); //string shortUsDateFormatString = us.DateTimeFormat.ShortDatePattern; // string shortUsTimeFormatString = us.DateTimeFormat.ShortTimePattern; // string LabelPanel1 = "General"; // string LabelPanel2 = "Custom Fields"; // string InputFilePath = FileObj.GetInputFilePath(LogFilePath, "Inputs.txt"); // string XenServerName = FileObj.GetInputPattern(InputFilePath, "AddedXenServerDisplayName"); // string ChangeHyperlink = "Change..."; // string EditTagsHyperlink = "Edit tags..."; // string LocalizedFilePath = FileObj.GetLocalizedFilePath(); // if (LocalizedFilePath != null) // { // LabelPanel1 = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, LabelPanel1); // LabelPanel2 = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, LabelPanel2); // ChangeHyperlink = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, ChangeHyperlink); // EditTagsHyperlink = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, EditTagsHyperlink); // } // AutomationElement XenCenterObj = NewOprtorObj.SetFocusOnWindow(AutomationElement.RootElement, "NameProperty", "XenCenter", TreeScope.Children, "XenCenter", 1, LogFilePath); // AutomationElement ServerObj = NewOprtorObj.CheckXenCenterServerNodetree(XenCenterObj, XenServerName, LogFilePath, 1, 1, "Right"); // // Open properties // System.Windows.Forms.SendKeys.SendWait("r"); // Thread.Sleep(2000); // AutomationElement PropertiesWindow=GenericObj.VerifyWindowOnScreen(XenCenterObj, "EditHostGeneralSettingsDialog", "TabTitle", LabelPanel1, 1); // PropertyCondition ParentListCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "verticalTabs", 1, LogFilePath); // AutomationElement ParentListObj = GuiObj.FindAutomationElement(PropertiesWindow, ParentListCondition, TreeScope.Descendants, "ParentListCondition", 1, LogFilePath); // //Select customfields tab // //GuiObj.SelectItemFromParent(ParentListObj, LabelPanel2, 1); //AutomationElement ListElement= GuiObj.GetListElementAndSelect(ParentListObj,1,3,LabelPanel2, 1); //System.Windows.Point ClickablePoint = ListElement.GetClickablePoint(); //System.Drawing.Point p = new System.Drawing.Point(Convert.ToInt32(ClickablePoint.X), Convert.ToInt32(ClickablePoint.Y)); //Microsoft.Test.Input.Mouse.MoveTo(p); // Thread.Sleep(2000); //Microsoft.Test.Input.Mouse.Click(Microsoft.Test.Input.MouseButton.Left); // NewGuiZardObj.VerifyGuiZardResults(); //NewGuiZardObj.KillGuizard(); System.Console.WriteLine("Finsihed"); //string LogFilePath = NewLogObj.GetLogFilePath(); //NewGuiZardObj.VerifyGuiZardHasFinishedCapturing(AddServerDialog, "AddServerDialog"); //string AddServerDialog = "Add New Server"; //string LocalizedFilePath = FileObj.GetLocalizedFilePath(); //if (LocalizedFilePath != null) //{ // AddServerDialog = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, AddServerDialog); //} //NewGuiZardObj.VerifyGuiZardHasFinishedCapturing(AddServerDialog, "AddServerDialog"); }