Search code examples
javaseleniumextentreports

how to get the details on each step in tests?


i want to add to each and every step at the extent report (4), the details on it so i won't get it empty like now, my code have an extent class and an ITestListener (TestNG) so the class looks like that (below) and where it written Test pass, these is the details for now, and i want something like that these

    public void onTestStart(ITestResult result) {
        create_test(result.getName());
    }

    @Override
    public void onTestSuccess(ITestResult result) {
        System.out.println("The success test name is: "+result.getTestName());
        test.log(test.getStatus(), "Test pass");
        try {
            test.pass(result.getTestName(),MediaEntityBuilder.createScreenCaptureFromPath(CaptureScreen()).build());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onTestFailure(ITestResult result) {
        System.out.println("The failed test name is: "+result.getName());

        try {
            test.fail(result.getTestName(), MediaEntityBuilder.createScreenCaptureFromPath(CaptureScreen()).build());
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }

    @Override
    public void onTestSkipped(ITestResult result) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStart(ITestContext context) {
        init();

    }

    @Override
    public void onFinish(ITestContext context) {
        extent.flush();

    } ```

and test looks like :

@Test (priority = 1 ,groups= "OpenWebSite-test")
    public void upFooterOpenWebSite() {
        MapsPage.getWebSite(siteURL);
    }

Solution

  • Use test.log(Status.INFO,"login using a valid IsoMetrix username and password"); basically you have to add Status.INFOof each steps and it will be available in the report.