Can I add author name of the test to the extent report? I am using Playright with NUnit. I am using [Author] attribute of NUnit to write the author Name in the test case.
//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");
}
And I am creating a extent test report using [Setup] as shown
[Setup]
public async Task Setup()
{
this.testName = TestContext.CurrentContext.Test.MethodName;
string classname = TestContext.CurrentContext.Test.ClassName;
test = ReportingFunctionUI.startTest(extentReport, testclass, testName);
}
And inside 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;
}
Is there anyway to get the author Name specified for each test case and add it in AssignAuthor(authorName) here in extent report. Is there any way to get the author Name for each test case and assign it to extent report without hard-coding it?
CodePudding user response:
The author is available via:
var author = (string)TestContext.CurrentContext.Test.Properties.Get("Author");
If there are multiple Author attributes, this will retrieve the first one. If you want to see them all, use
var authors = (IList)TestContext.CurrentContext.Test.Properties["Author"];