Extent Reports V4覆盖Selenium C#中的测试结果



我使用Extent报告v4,当我尝试从不同的类运行多个测试时,我只能在报告中找到我的最后一个测试。例如,如果我有10个并行运行的测试,我只会找到最后一个运行的测试。我需要找到报告中所有的10项测试。我使用的是带有c#的Selenium 4。

这是我用过的代码。

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();
}
}

}

我可以看到您已经注释掉了范围。在TearDown中冲洗。你能确认一下为什么吗?你试过在TearDown做同花顺吗?

最新更新