Skip to content

Start and End time for tests are not updating #1

Closed
@qamadhu

Description

@qamadhu

Hi Anshoo Arora,
If you notice, the duration for individual test cases is updated correctly whereas the overall duration of whole test suite is not updating
I tried with extentreports-testng-adapter- ExtentIReporterSuiteListenerAdapter listener as well as below code and it's giving me same result.
Please guide me if anything mistake I did.
timeupdate issue

public class ExtentIReporterSuiteListenerAdapter implements IReporter {
private static final Calendar CALENDAR = Calendar.getInstance();
private ExtentReports extent;
public void generateReport(List xmlSuites, List suites, String outputDirectory) {

	init(outputDirectory);
	for (ISuite suite : suites) {
		Map<String, ISuiteResult> result = suite.getResults();
		for (ISuiteResult r : result.values()) {
			
			ITestContext context = r.getTestContext();
			ExtentTest suiteTest = extent.createTest(r.getTestContext().getCurrentXmlTest().getName());
			
			buildTestNodes(suiteTest,context.getPassedTests(), Status.PASS);
			buildTestNodes(suiteTest,context.getFailedTests(), Status.FAIL);
			buildTestNodes(suiteTest,context.getSkippedTests(), Status.SKIP);
		
			
		}
	}
	//To print the TestRunner Logs
	for (String s : Reporter.getOutput()) {
		extent.setTestRunnerOutput(s);

	}

	extent.flush();
	
}

private void buildTestNodes(ExtentTest suiteTest,IResultMap tests, Status status) {
	ExtentTest test;

	if (tests.size() > 0) {

		for (ITestResult result : tests.getAllResults()) {  

			test = suiteTest.createNode(result.getMethod().getMethodName(), result.getMethod().getDescription());		
			test.getModel().setDescription("Test Description: " + result.getMethod().getDescription());	
			for (String group : result.getMethod().getGroups())
				test.assignCategory(group);

			if (result.getThrowable() != null){
				if (result.getThrowable() instanceof java.lang.AssertionError) {
					test.log(status,  result.getThrowable().getMessage());
					//Attach screenshot
					try {
						test.log(status,
								"Exception/Assertion screenshot:"+test.addScreenCaptureFromPath(".\\screenshots\\"+result.getMethod().getXmlTest().getName()+result.getMethod().getMethodName()+".png","ExceptionScreenshot"));
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					if(result.getMethod().getTestClass().getAfterTestMethods().length>0) 
						test.log(status,result.getMethod().getTestClass().getAfterTestMethods()[0].getDescription());

				}else{
					//node.log(status, "Test " + status.toString().toLowerCase() + "ed");
					test.log(status, "Test " + status.toString().toLowerCase() + "ed"+": Due to Webdriver exception. Please re-run again\n"
							.concat("\n<a href='.\\index.html' target='_blank'><span class='label info'>DetailedException</span></a>"));
				}
				
			}         

			test.getModel().setStartTime(getTime(result.getStartMillis()));
			test.getModel().setEndTime(getTime(result.getEndMillis()));

			
		}
	}
}
private Date getTime(long millis) {
       
        CALENDAR.setTimeInMillis(millis);
		return CALENDAR.getTime();
    }



private void init(String dir) {
	
	ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(dir +  File.separator + "ExtentReport.html");

	htmlReporter.config().setDocumentTitle("Automation Report");
	htmlReporter.config().setReportName("Mobile-Automation -Summary Report");
	htmlReporter.config().enableTimeline(true);
	htmlReporter.config().setTheme(Theme.STANDARD);
	htmlReporter.setAnalysisStrategy(AnalysisStrategy.TEST);
	
	extent = new ExtentReports();
	extent.attachReporter(htmlReporter);
	extent.setReportUsesManualConfiguration(true);

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions