21.4 C
New York
Thursday, September 19, 2024

selenium webdriver – The right way to generate report utilizing extent reviews in Web page Object Mannequin in C#


I’ve created a POM framework utilizing NUnit in C#. I’ve created Reporting.cs file which creates reviews for the take a look at in that class. How I can generate reviews for all exams in several lessons with out rewriting the reporting code.

BaseTest
- References
- package deal
- config
- tasks
|- project_name
 |- pages
 |- exams
|- utils
 |- reporting.cs

In exams folder recordsdata with TestLoginModule.cs have capabilities

[Test]
public void TestFirst()
{
    // take a look at code
}
[Test]
public void TestSecond()
{
    // take a look at code
}

In exams folder recordsdata with TestDashboardModule.cs have capabilities

[Test]
public void TestThird()
{
    // take a look at code
}
[Test]
public void TestFourth()
{
    // take a look at code
}

In Reporting.cs file

[OneTimeSetUp]
public void BeforeClass()
{
    // create a take a look at report listing and fasten reporter
    extent = new ExtentReports();
    var dir = AppDomain.CurrentDomain.BaseDirectory.Change("/bin/Debug","");
                    DirectoryInfo di = Listing.CreateDirectory(dir + "//Test_Execution_Reports");
    var htmlReporter = new ExtentHtmlReporter(dir + "//Test_Execution_Reports" + "//Automation_Report" + ".html");
    extent.AttachReporter(htmlReporter);
}

[TearDown]
public void AfterTest()
{
    var standing = TestContext.CurrentContext.End result.End result.Standing;
    var stacktrace = "" + TestContext.CurrentContext.End result.StackTrace + "";
    var errorMessage = TestContext.CurrentContext.End result.Message;
    Standing logstatus;

    swap(standing)
    {
        case TestStatus.Failed:
            logstatus = Standing.Fail;
            take a look at.Log(logstatus, "Check ended with" + logstatus + "-" + errorMessage);
            take a look at.Log(logstatus, "screenshot");
            break;
        case TestStatus.Skipped:
            logstatus = Standing.Skip;
            break;
        default:
            logstatus = Standing.Move;
            break;
    }

    SB.Driver.Shut();
    SB.Driver.Stop();
}

[OneTimeTearDown]
public void AfterClass()
{
    extent.Flush();
}

I wish to name Reporting.cs OneTimeSetUp and TearDown after each Check in several recordsdata

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles