简体   繁体   English

Extent 报告 V4 覆盖测试结果 Selenium C#

[英]Extent Reports V4 overwriting test results in Selenium C#

Im using Extent report v4 and I could only find my last test in the report when i try to run multiple tests from different classes.我使用的是 Extent 报告 v4,当我尝试从不同的类运行多个测试时,我只能在报告中找到我的最后一个测试。 For eg, if I got 10 tests that run in parallel, I would find only the one that has run the last.例如,如果我有 10 个并行运行的测试,我只会找到最后一个运行的测试。 I need to find all the 10 tests in the report.我需要在报告中找到所有 10 项测试。 I'm using Selenium 4 with c#.我正在使用 Selenium 4 和 c#。

Here's my code I used.这是我使用的代码。

public class DriverHelper
{
    //public static IWebDriver driver { get; set; }

    public ExtentReports extent;
    public ExtentTest test;
     

    [OneTimeSetUp]
    public void Setup()
    {
        String workingDirectory = Environment.CurrentDirectory;
        string projectDirectory = Directory.GetParent(workingDirectory).Parent.Parent.FullName;
        string reportPath = projectDirectory + "//index.html";
        var htmlReporter = new ExtentHtmlReporter(reportPath);
        extent = new ExtentReports();
        extent.AttachReporter(htmlReporter);
        extent.AddSystemInfo("Host Name", "Gold end to end");
        extent.AddSystemInfo("Tester", "Arshad");

    }

    public ThreadLocal<IWebDriver> driver = new ThreadLocal<IWebDriver>();
    [SetUp]
    public void StartBrowser()
    {
        test = extent.CreateTest(TestContext.CurrentContext.Test.Name);

        var browserSetup = new BrowserSetup();
        driver.Value = browserSetup.SetupBrowser();
    }

    [TearDown]
    public void Test1()
    {

        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stackTrace = TestContext.CurrentContext.Result.StackTrace;

        DateTime time = DateTime.Now;
        string fileName = "Screenshot_" + time.ToString("h_mm_ss") + ".png";

        if (status == TestStatus.Failed)
        {
            test.Fail("Test failed", captureScreenshot(driver.Value, fileName));
            test.Log(Status.Fail, "Test failed with logtrace" + stackTrace);
        }
        else if (status == TestStatus.Passed)
        {
            test.Log(Status.Pass, "Test successful");

        }
        //extent.Flush();
        driver.Value.Quit();
    }

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

    public MediaEntityModelProvider captureScreenshot(IWebDriver driver, String screenShotName)
    {
        ITakesScreenshot ts = (ITakesScreenshot)driver;
        var screenshot = ts.GetScreenshot().AsBase64EncodedString;

        return MediaEntityBuilder.CreateScreenCaptureFromBase64String(screenshot, screenShotName).Build();
    }
}

} }

I could see you have commented out extent.Flush in TearDown.我可以看到你已经在 TearDown 中注释掉了 extent.Flush。 Could you please confirm why is that?你能确认这是为什么吗? have you tried doing flush in TearDown?你试过在 TearDown 中冲洗吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM