【发布时间】: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