微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用C#在Selenium中创建范围报告4.1.0

如何解决无法使用C#在Selenium中创建范围报告4.1.0

我正在尝试创建扩展报告,但是我无法在C#中使用版本4.1.0创建扩展报告。 在这种情况下任何人都可以帮忙吗
这是报告类代码

'''
using AventStack.ExtentReports;
using AventStack.ExtentReports.MarkupUtils;
using AventStack.ExtentReports.Reporter;
using DocumentFormat.OpenXml.Drawing.ChartDrawing;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JGHTestAutomation.Report
{
    [TestFixture]
    class StatusReport
    {

         IWebDriver driver;
       public static  ExtentHtmlReporter htmlReporter;
       public static  ExtentReports extent = new ExtentReports();
       public static  ExtentTest test;

        [OneTimeSetUp]
        public string extentReportSetup()
        {
            string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
            string actualPath = pth.Substring(0,pth.LastIndexOf("bin"));
            string projectPath = new Uri(actualPath).LocalPath;
            string currentTime = DateTime.Now.ToString("hhmmssstt");
            string reportPath = projectPath + "Report\\ExecutionResult\\TestRunReport_" + currentTime + ".html";

            //location of the extent report
            htmlReporter = new ExtentHtmlReporter(reportPath);
              //create object of ExtentReports
            extent.AttachReporter(htmlReporter);
            
            // General information releated to application
            extent.AddSystemInfo("Application Name","JGH");
            extent.AddSystemInfo("User Name","Tarun");
            extent.AddSystemInfo("Envirnoment","Dev");

            return reportPath;
        }



        [TearDown]
        public void getResult(ExtentTest test)
        {

            var status = TestContext.CurrentContext.Result.Outcome.Status;
            var stackTrace = "" + TestContext.CurrentContext.Result.StackTrace + "";
            var errorMessage = TestContext.CurrentContext.Result.Message;


            if (status == TestStatus.Failed)
        {
            //MarkupHelper is used to display the output in different colors
            test.Log(Status.Fail,MarkupHelper.CreateLabel(errorMessage,ExtentColor.Red));

            //  String Scrnshot=TakeScreenshot.captuerScreenshot(driver,"TestCaseFailed");
            String screenshotPath = TakeSceenShot(driver);
        //To add it in the extent report 

        test.Fail("Test Case Failed Snapshot is below " + test.AddScreenCaptureFromPath(screenshotPath));


        }
        else if(status == TestStatus.Skipped){
            //logger.log(Status.SKIP,"Test Case Skipped is "+result.getName());
            test.Log(Status.Skip,MarkupHelper.CreateLabel("Test Case Skipped",ExtentColor.Orange)); 
        } 
        else if(status == TestStatus.Passed)
        {
                test.Log(Status.Skip,MarkupHelper.CreateLabel("Test Case Passed",ExtentColor.Green));
            }
        }



        public String TakeSceenShot(IWebDriver driver)
        {
            Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
            string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
            string actualPath = pth.Substring(0,pth.LastIndexOf("bin"));
            string projectPath = new Uri(actualPath).LocalPath;
            string title = TestContext.CurrentContext.Test.Name;
            string Runname = title + DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss");
            string reportPath = projectPath + "Report\\ExecutionResult\\screenshots\\" + Runname + ".jpg";
            ss.SaveAsFile(reportPath,ScreenshotimageFormat.Jpeg);
            return reportPath;
        }

        [OneTimeTearDown]
        public void EndReport()
        {
            extent.Flush();            

        }
    }
}

'''

这是一个测试用例文件

'''
using NUnit.Framework;
using JGHTest.BaseClasses;
using System.Collections;
using JGHTest.ComponentHelper;
using System.Text;
using System;
using AventStack.ExtentReports;
using AventStack.ExtentReports.MarkupUtils;
using AventStack.ExtentReports.Reporter;
using JGHTestAutomation.Report;

namespace JGHTest.TestCases
{
    [TestFixture]
    [Parallelizable]
    public class SmokeTest : ParallelTests
    {

        //Instance of extents reports
        public static ExtentReports extent;
        public static ExtentTest test;
        public static ExtentHtmlReporter htmlReporter;
        StatusReport rep = new StatusReport();


        [Test]
        [TestCaseSource(typeof(ParallelTests),"browserToRunWith")]
        public void AllSuiteTest(string browserName)
        {
            string reportPath = rep.extentReportSetup();
            extent.
            test = extent.CreateTest("Launch browser","");
            driver = Setup(browserName,driver);         

        }

        [TearDown]
        public void Closebrowser()
        {
            InitializeWebDriver objInit = new InitializeWebDriver(driver);
            //objEmailSend = new Mail.Email_Send();
            rep.getResult(test);
            objInit.TearDown(driver);
            //objEmailSend.Email_send();

        }
    }
}
'''

我是C#中硒的新手,因此,如果有人在此代码中为我提供帮助或在Visual Studio中提供最新范围版本4的代码,则Selenium c#报告未创建且显示空异常
这是我的项目要求

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。