如何在C#中为测试的不同作者的扩展报告中添加作者名称



我可以将测试的作者名称添加到扩展数据块报告中吗?我正在与NUnit一起使用Playright。我使用NUnit的[Author]属性来编写测试用例中的作者名称。

//This is a test case      
 [Test(Author="abc")]
 public async Task Login(IPage _page)
        {
            UIFunctions uifunction = new UIFunctions(_page);
            await uifunction.Fill("input[name="username"]", ConfigurationManager.AppSettings["UserName"]);
            await uifunction.Fill("input[name="password"]", ConfigurationManager.AppSettings["Password"]);
            await uifunction.Click("input[name="login"]", "Not able to click Login Button");
            ReportingFunctionUI.logResults(_page, true, "Logged in", " successfully using Login Button");
        }

我正在使用[Setup]创建一个扩展测试报告,如所示

[Setup]
public async Task Setup()
        {
               this.testName = TestContext.CurrentContext.Test.MethodName;
               string classname = TestContext.CurrentContext.Test.ClassName;
               test = ReportingFunctionUI.startTest(extentReport, testclass, testName);
        }

以及内部ReportingFunctionUI

 public static ExtentTest startTest(ExtentReports extentReport, String className, String methodName)
        {
            ExtentTest test = extentReport.CreateTest(className + " :: " + methodName, methodName).AssignAuthor("Here");// Is there anyway to get the author Name specified for each test case and add it in AssignAuthor(authorName) here in extent report.
            return test;
        }

是否可以为每个测试用例指定作者名称,并将其添加到数据块报告中的AssignAuthor(authorName(中。是否有任何方法可以获得每个测试用例的作者名称,并将其分配到扩展报告中,而无需对其进行硬编码?

作者可通过以下途径获得:

var author = (string)TestContext.CurrentContext.Test.Properties.Get("Author");

如果有多个"作者"属性,这将检索第一个属性。如果你想看到它们,请使用

var authors = (IList)TestContext.CurrentContext.Test.Properties["Author"];

相关内容

最新更新