Пример #1
0
        //[OneTimeSetUp]
        //public void RunBeforeAnyTests()
        //{
        //    //// The below condition is used to delete all html files before the suite is run.
        //    this.driverContext.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
        //    if (BaseConfiguration.ReportOutsideBin == "Yes")
        //    {
        //        FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.ExtentReportOutBinFolder, "*.html", true);
        //    }

        //    JsonContext.DefectAttachmentFilePath = new List<string>();
        //    // if (BaseConfiguration.JiraResult == "SuiteLevel" && BaseConfiguration.PublishJira == "No")
        //    if (BaseConfiguration.PublishJira == "No")
        //    {
        //        var filename = TestContext.CurrentContext.TestDirectory;
        //        if (BaseConfiguration.ReportOutsideBin == "Yes")
        //        {
        //            DirectoryInfo direc = Directory.GetParent(TestContext.CurrentContext.TestDirectory).Parent.Parent;
        //            string dirPath = direc.FullName;
        //            filename = dirPath + "\\Reports\\" + "SuiteExecutionReport " + DateHelper.CurrentTimeStamp + ".html";
        //        }
        //        else
        //        {
        //            var dir = TestContext.CurrentContext.TestDirectory + "\\";
        //            filename = dir + "ExtentReportResults\\" + "SuiteExecutionReport " + DateHelper.CurrentTimeStamp + ".html";
        //        }

        //        // this.filename = this.dir + this.GetType().ToString() + "NSBMOUApp.html";
        //        SuiteLevelConfiguration.SuiteExtent = new ExtentReports(filename, true);
        //    }

        //    JsonContext.InfoStartDate = DateHelper.CurrentDateTimeZoneStamp;
        //    this.DriverContext.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.ExtentReportFolder, "*.html");
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.ExtentReportOutBinFolder, "*.html");
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.DownloadFolder, "*.pdf");
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.MethodJsonFolder, "*.json", true);
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.SuiteJsonFolder, "*.json", true);
        //}
        //public void RunBeforeAnyTests()
        //{
        //    JsonContext.DefectAttachmentFilePath = new List<string>();
        //    this.Filename = TestContext.CurrentContext.TestDirectory;

        //    if (BaseConfiguration.ReportOutsideBin == "Yes")
        //    {
        //        if (BaseConfiguration.JiraResult == "SuiteLevel")
        //        {
        //            DirectoryInfo direc = Directory.GetParent(TestContext.CurrentContext.TestDirectory).Parent.Parent;
        //            string dirPath = direc.FullName + "\\SuiteLevelReport\\";
        //            ////DirectoryInfo direc = Directory.GetParent(TestContext.CurrentContext.TestDirectory);
        //            ////string dirPath = direc.FullName + BaseConfiguration.ExtentReportFolder;
        //            foreach (var file in Directory.EnumerateFiles(dirPath, "*.html"))
        //            {
        //                File.Delete(file);
        //            }

        //            this.Filename = dirPath + "SuiteExecutionReport_" + DateHelper.CurrentTimeStamp + ".html";
        //            SuiteLevelConfiguration.SuiteExtent = new ExtentReports(this.Filename, true);
        //        }
        //        else
        //        {
        //            DirectoryInfo direc = Directory.GetParent(TestContext.CurrentContext.TestDirectory).Parent.Parent;
        //            string dirPath = direc.FullName + "\\MethodLevelReport\\";
        //            ////DirectoryInfo direc = Directory.GetParent(TestContext.CurrentContext.TestDirectory);
        //            ////string dirPath = direc.FullName + BaseConfiguration.ExtentReportFolder;
        //            foreach (var file in Directory.EnumerateFiles(dirPath, "*.html"))
        //            {
        //                File.Delete(file);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        DirectoryInfo direc = Directory.GetParent(TestContext.CurrentContext.TestDirectory);
        //        string dirPath = direc.FullName + BaseConfiguration.ExtentReportFolder;
        //        foreach (var file in Directory.EnumerateFiles(dirPath, "*.html"))
        //        {
        //            File.Delete(file);
        //        }

        //        this.Filename = dirPath + "SuiteExecutionReport_" + DateHelper.CurrentTimeStamp + ".html";
        //        SuiteLevelConfiguration.SuiteExtent = new ExtentReports(this.Filename, true);
        //    }

        //    JsonContext.InfoStartDate = DateHelper.CurrentDateTimeZoneStamp;
        //    this.DriverContext.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.ExtentReportFolder, "*.html");
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.DownloadFolder, "*.pdf");
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.MethodJsonFolder, "*.json", true);
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.SuiteJsonFolder, "*.json", true);
        //    FilesDeletionExtension.DeleteFilesWithExtension(this.DriverContext.DownloadFolder, "*.*", true);
        //}

        //[OneTimeTearDown]
        //public void RunAfterAnyTestsAsync()
        //{
        //    if (BaseConfiguration.JiraResult == "SuiteLevel")
        //    {
        //        SuiteExtent.EndTest(DriverContext.ExtentStepTest);
        //        SuiteExtent.Flush();
        //        TestContext.AddTestAttachment(this.Filename);
        //        JsonContext.InfoFinishDate = DateHelper.CurrentDateTimeZoneStamp;
        //        this.GetJSONStringforSuite();
        //        if (BaseConfiguration.PublishJira == "Yes")
        //        {
        //            SuiteLevelConfiguration.PostToJIRA();
        //        }


        //    }
        //    if (BaseConfiguration.SendEmail == "yes")
        //    {
        //        if (BaseConfiguration.JiraResult == "SuiteLevel")
        //        {
        //            string reportFilePath = ZipReportFiles("SuiteLevelReport");
        //            EmailHelper.SendEmailFunctionality("Cigniti", "Body", "Test rport", reportFilePath);

        //        }
        //        else if (BaseConfiguration.JiraResult == "MethodLevel")
        //        {
        //            string reportFilePath = ZipReportFiles("MethodLevelReport");
        //            EmailHelper.SendEmailFunctionality("Cigniti", "Body", "Test rport", reportFilePath);
        //        }
        //    }
        //}

        private static string ZipReportFiles(string level)
        {
            var    filename     = TestContext.CurrentContext.TestDirectory;
            string reportFolder = Path.GetFullPath(Path.Combine(filename, @"..\..\..\"));

            if (File.Exists(reportFolder + level + ".zip"))
            {
                File.Delete(reportFolder + level + ".zip");
            }
            string zipFileName = string.Empty;
            string newPath     = reportFolder + level;

            using (var zip = new Ionic.Zip.ZipFile())
            {
                zip.AddSelectedFiles("*.html", newPath, reportFolder);

                zip.Save(string.Format("{0}{1}.zip", reportFolder, level));
                zipFileName = reportFolder + level + ".zip";
            }

            return(zipFileName);
        }