Selenium 有人能帮我用C实现ExtentV3HtmlReporter吗#
我正在项目中使用extend report。为了获得良好的外观和感觉,我尝试合并ExtentV3HtmlReporter,但这不起作用 我的代码是Selenium 有人能帮我用C实现ExtentV3HtmlReporter吗#,selenium,Selenium,我正在项目中使用extend report。为了获得良好的外观和感觉,我尝试合并ExtentV3HtmlReporter,但这不起作用 我的代码是 ExtentLoggerReporter loggerReporter = new ExtentLoggerReporter(logPath); extentLog = new ExtentReports(); extentLog.AttachReporter(loggerReporter);
ExtentLoggerReporter loggerReporter = new ExtentLoggerReporter(logPath);
extentLog = new ExtentReports();
extentLog.AttachReporter(loggerReporter);
htmlReporter = new ExtentV3HtmlReporter(reportPath);
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
由于ExtentV3HtmlReporter(版本3)非常旧,因此不再提供。您可以改为使用ExtentHtmlReporter(版本4)。5版仍处于测试阶段 我的csproj与依赖项:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="90.0.4430.2400" />
<PackageReference Include="ExtentReports" Version="4.1.0" />
</ItemGroup>
</Project>
using System;
using System.IO;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace Selenium
{
public class Tests
{
public IWebDriver driver;
//declare the type of reporter
public ExtentHtmlReporter htmlReporter;
public ExtentReports extent;
//to be used for each of the tests
public ExtentTest test;
[OneTimeSetUp]
public void OneTimeSetUp()
{
// One time called before all the tests: create the ExtentReports instance and attach the html reporter
// It will create the report.html at the root base of the project
htmlReporter = new ExtentHtmlReporter("../../../report.html"); //change this path to a location that you want.
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
}
[SetUp]
public void Setup()
{
driver = new ChromeDriver(".");
}
[Test]
public void PassedTest()
{
//used to create a test entry in the report
test = extent.CreateTest("Passed Test", "Used just to navigate to an url");
driver.Navigate().GoToUrl("https://stackoverflow.com");
//log something
test.Log(Status.Info, $"After the url was accessed the page title was: {driver.Title}");
}
[Test]
public void FailedTest()
{
//used to create a test entry in the report
test = extent.CreateTest("Failed Test", "Used just to navigate to an url");
driver.Navigate().GoToUrl("https://stackoverflow.com");
//log something
test.Log(Status.Info, "Trying to get an element that will fail");
driver.FindElement(By.Id("invalid_Id"));
}
[TearDown]
public void TearDown()
{
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
{
test.Fail($"Test Failed Successfully with the stack error message: {TestContext.CurrentContext.Result.StackTrace} ");
}
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
{
test.Pass("Test Passed Successfully");
}
driver.Close();
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
//flush to create the report.html after the tests have ran
extent.Flush();
}
}
}