Esempio n. 1
0
        public string VerifyGuiZardResults(string TestName)
        {
            Logger         NewLogObj   = new Logger();
            FileOperations NewFileObj  = new FileOperations();
            string         LogFilePath = NewLogObj.GetLogFilePath();
            //NewLogObj.WriteLogFile(LogFilePath, "VerifyGuiZardResults", "info");
            //NewLogObj.WriteLogFile(LogFilePath, "=====================", "info");
            FileOperations FileObj = new FileOperations();

            // CreateGuizardSkipTestFile();
            Thread.Sleep(5);
            //string GuizardResultsPath = GetResultsFolderPath();
            string GuizardResultsPath = FileObj.GetLatestFileInDirectory("C:\\TestResults");

            NewLogObj.WriteLogFile(LogFilePath, "GuizardResultsPath " + GuizardResultsPath, "info");
            if (GuizardResultsPath == null)
            {
                NewLogObj.WriteLogFile(LogFilePath, "GuizardResultsPath is null " + GuizardResultsPath, "fail");
                return("-1");
                //  return 0;
            }
            string GuizardSummaryResults = GuizardResultsPath + "//SummaryData.xml";
            string ResultsFolderPath     = null;

            if (File.Exists(GuizardSummaryResults))
            {
                string[] lines = System.IO.File.ReadAllLines(GuizardSummaryResults);
                NewLogObj.WriteLogFile(LogFilePath, "Start verifying Guizard results", "info");
                int FailFlag      = 0;
                int FirstCopyFlag = 0;
                foreach (string line in lines)
                {
                    if (Regex.IsMatch(line, "FAIL"))
                    {
                        //Extracting the window caption
                        int    IndexOfQuotes1 = line.IndexOf("\"");
                        string temp           = line.Substring(IndexOfQuotes1 + 1);
                        int    IndexOfQuotes2 = temp.IndexOf("\"");
                        string WindowCaption  = line.Substring(3, IndexOfQuotes2 + IndexOfQuotes1);
                        //NewLogObj.WriteLogFile(LogFilePath, "Failure found in GUIZARD at "+line, "fail");

                        //Have to copy the fail screen shots to some loctaion
                        string FolderName = ExtractFailFolderName(line);
                        if (FolderName != null)
                        {
                            //Copying the files to a common folder
                            string FailFolderPath = GuizardResultsPath + "//" + FolderName;
                            NewLogObj.WriteLogFile(LogFilePath, "Failure found in GUIZARD at " + WindowCaption + ". Screenshots path " + FailFolderPath, "fail");
                            string DestinationFolderPath = "C:\\GuizardResults\\" + TestName;
                            ResultsFolderPath = DestinationFolderPath;

                            if (!(Directory.Exists(DestinationFolderPath)))
                            {
                                Directory.CreateDirectory(DestinationFolderPath);
                            }
                            //Copying the xml file
                            if (FirstCopyFlag == 0)
                            {
                                System.IO.File.Copy(GuizardSummaryResults, DestinationFolderPath + "\\SummaryData.xml", true);
                            }
                            FirstCopyFlag         = 1;
                            DestinationFolderPath = DestinationFolderPath + "\\" + FolderName;
                            if (!Directory.Exists(DestinationFolderPath))
                            {
                                Directory.CreateDirectory(DestinationFolderPath);
                            }
                            //Extract the failed screen shot file name
                            int IndexOfScreenshot = line.IndexOf("screenshot");
                            //14 - removing screenshot="\
                            temp = line.Substring(IndexOfScreenshot + 14);
                            //screenshot="\Overlapping\Overlapping_0011_'NewNetwork' Properties.jpg" />
                            int    IndexOfSlash   = temp.IndexOf("\\");
                            int    IndexOfQuotes  = temp.IndexOf("\"");
                            string ScreenShotName = temp.Substring(IndexOfSlash + 1, IndexOfQuotes - IndexOfSlash - 1);
                            string ScreenShotpath = FailFolderPath + "\\" + ScreenShotName;
                            if (File.Exists(ScreenShotpath))
                            {
                                //NewFileObj.CopyContentsOfAFolder(FailFolderPath, DestinationFolderPath);
                                NewFileObj.CopyFileToAFolder(ScreenShotpath, DestinationFolderPath);
                            }
                        }

                        FailFlag = 1;
                    }
                }
                if (FailFlag == 0)
                {
                    NewLogObj.WriteLogFile(LogFilePath, "No fails found in GUIZARD ", "pass");
                    //ResultsFolderPath = GuizardResultsPath;
                    ResultsFolderPath = "C:\\TestResults\\" + TestName;
                    return(ResultsFolderPath);
                }
                else
                {
                    //NewLogObj.WriteLogFile(LogFilePath, "Fails found in GUIZARD ", "fail");
                    return(ResultsFolderPath);
                }
            }
            else
            {
                NewLogObj.WriteLogFile(LogFilePath, GuizardSummaryResults + "GuizardSummaryResults file not found ", "fail");
                return("-1");
            }
        }
        public int GenerateRUFile()
        {
            Logger         NewLogObj   = new Logger();
            string         LogFilePath = NewLogObj.GetLogFilePath();
            FileOperations FileObj     = new FileOperations();

            Console.WriteLine("\n \n Generating Test Data Generator files. Please wait ...\n ");

            string CurrentLocale       = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
            string OutPutFilePath      = Directory.GetCurrentDirectory() + "\\TestGeneratorFiles\\Output_Inputs_" + CurrentLocale + ".xml";
            string OutPutFilePath1     = "C:\\Output_Inputs_" + CurrentLocale + ".xml";
            string FileNameAfterRename = "Inputs_" + CurrentLocale + ".xml";
            string DestinationFilePath = Directory.GetCurrentDirectory() + "\\Inputs\\" + FileNameAfterRename;

            if (File.Exists(OutPutFilePath))
            {
                File.Delete(OutPutFilePath);
            }
            if (File.Exists(OutPutFilePath1))
            {
                File.Delete(OutPutFilePath1);
            }
            if (File.Exists(DestinationFilePath))
            {
                File.Delete(DestinationFilePath);
            }
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

            string InputFileName = "Inputs_" + CurrentLocale + ".xlsx";
            string InputFilePath = Directory.GetCurrentDirectory() + "\\TestGeneratorFiles\\Inputs_" + CurrentLocale + ".xlsx";


            string FileName = Directory.GetCurrentDirectory() + "\\TestGeneratorFiles\\TestDataGenerator.exe";
            string Command  = FileName + " " + InputFilePath;

            System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + Command);

            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute        = false;
            // Do not create the black window.
            procStartInfo.CreateNoWindow = true;

            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            Thread.Sleep(20000);
            // proc.WaitForExit();
            string result = proc.StandardOutput.ReadToEnd();

            NewLogObj.WriteLogFile(LogFilePath, "Result of execution of cmd " + Command + " : *" + result + "*", "info");

            if (File.Exists(OutPutFilePath))
            {
                NewLogObj.WriteLogFile(LogFilePath, "Test generator file " + OutPutFilePath + " generated successfully", "info");
                FileObj.RenameFile(OutPutFilePath, DestinationFilePath);
                //FileObj.CopyFileToAFolder(OutPutFilePath, DestinationFilePath);
                return(1);
            }
            else
            {
                NewLogObj.WriteLogFile(LogFilePath, "Test generator file " + OutPutFilePath + " generation failed", "warn");
            }

            if (File.Exists(OutPutFilePath1))
            {
                NewLogObj.WriteLogFile(LogFilePath, "Test generator file " + OutPutFilePath1 + " generated successfully", "info");
                FileObj.CopyFileToAFolder(OutPutFilePath1, DestinationFilePath);
                return(1);
            }
            else
            {
                NewLogObj.WriteLogFile(LogFilePath, "Test generator file " + OutPutFilePath1 + " generation failed", "warn");
            }
            NewLogObj.WriteLogFile(LogFilePath, "Test generator file generation failed. Trying to copy the default test data generator files", "warn");

            //Using the default test data generator files
            string DefaultTestDataGenFilePath = Directory.GetCurrentDirectory() + "\\TestGeneratorFiles\\DefaultTestdataGeneratorFiles" + InputFileName;

            if (File.Exists(DefaultTestDataGenFilePath))
            {
                FileObj.CopyFileToAFolder(DefaultTestDataGenFilePath, DestinationFilePath);
                if (File.Exists(DestinationFilePath))
                {
                    NewLogObj.WriteLogFile(LogFilePath, "Default Test generator file copied successfully", "warn");
                }
                else
                {
                    Console.WriteLine("****Test generator file generation failed. Exiting ****");
                    FileObj.ExitTestEnvironment();
                    return(-1);
                }
            }
            else
            {
                Console.WriteLine("****Test generator file generation failed. Exiting ****");
                FileObj.ExitTestEnvironment();
                return(-1);
            }
            return(-1);
        }