【问题标题】:Selenium C# Extent Report using multiple ClassesSelenium C# 范围报告使用多个类
【发布时间】:2020-12-05 17:27:42
【问题描述】:

我正在创建 selenium C# frameworke 并在其中添加了 Extent Report。当我运行我的代码时,我有两个类,我的第一类测试报告被第二类测试报告覆盖。如何在单个报告中生成多个类范围报告。我知道我的 ExtentTest 测试变量在执行新类时被覆盖,但我不知道如何修复它。我知道在 Java 中我们可以使用 ITestReport,但在 C# 中没有这样的功能。

我的基类:

    {
        public IWebDriver driver;
        public static ExtentReports extent;
        public static ExtentTest test ;
        public static ExtentHtmlReporter htmlReporter;


        [OneTimeSetUp]
        public void ExtendStart()
        {
        
                extent = new ExtentReports();
                 htmlReporter = new ExtentHtmlReporter("D:\\TitleHoundEndToEndTesting\\TitleHoundEndToEndTesting\\ExtentReports\\Current-SeleniumRepprt.html");
                extent.AttachReporter(htmlReporter);

        }
        [SetUp]
        public void startBrowser()
        {
            driver = new ChromeDriver("D:\\");
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
        }
        public MediaEntityModelProvider CaptureScreenShot()
        {
            var screenshot = ((ITakesScreenshot)driver).GetScreenshot().AsBase64EncodedString;
            return MediaEntityBuilder.CreateScreenCaptureFromBase64String(screenshot).Build();

        }
    
        [TearDown]
        public void closeBrowser()
        {
           
            driver.Close();
        }```


**My Login Class**

  ```      [Test]
        public void BLoginTest()
        {
            try
            {
                test = extent.CreateTest("Login Test Is Getting Exectuted");
                driver.Url = "https://test.line.com/";
                driver.Manage().Window.Maximize();

                var login = new Login(driver);
                login.LoginMethod();
                test.Log(Status.Pass, "Login Test Method is Passed");
            }
            catch (Exception e)
            {
                if (attempts <= 3)
                {
                    attempts++;
                    Thread.Sleep(8000);
                    BLoginTest();
                }
                else
                {
                    var ss = CaptureScreenShot();
                    test.Log(Status.Fail, "Login Test Method is Failed" + e, ss);
                    Assert.Fail();
                }
            }
        }```

**My NewQuote Class**

```  [Test]
        public void ANewQuoteTest()
        {
            try
            {
                test = extent.CreateTest("NewQuote Test Is Getting Exectuted");
                driver.Url = "https://test.titlehoundonline.com/";
                driver.Manage().Window.Maximize();
                var newqoute = new NewQuote(driver);
                newqoute.GetQouteMethod();
                test.Log(Status.Pass, "Login Test Method is Passed");

            }
            catch(Exception e)
            {

                if (attempts <= 3)
                {
                    attempts++;
                    Thread.Sleep(8000);
                    ANewQuoteTest();
                }
                else
                {
                    var ss = CaptureScreenShot();
                    test.Log(Status.Fail, "LogOutTest Test Method is Failed" + e, ss);
                    Assert.Fail();
                }
            }
        }```

【问题讨论】:

    标签: c# selenium extentreports


    【解决方案1】:

    我看不到 EndTest、Flush、Close 方法调用范围对象。仅当您调用 flush 时才会写入报告。要将所有测试用例结果添加到报告中,请使用适当的方法(例如,Aftermethod/after class)在范围报告上写入。并在拆卸、Aftersuite 中使用 flush/close。

    【讨论】:

    • ` [TearDown] public void closeBrowser() { driver.Close(); } [OneTimeTearDown] public void ExtentReprot() { extent.Flush(); }`
    • 我正在使用,但仍然会覆盖每个班级报告
    猜你喜欢
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    相关资源
    最近更新 更多