New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start and End time for tests are not updating #1

Closed
qamadhu opened this Issue Dec 5, 2018 · 11 comments

Comments

Projects
None yet
3 participants
@qamadhu
Copy link

qamadhu commented Dec 5, 2018

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);

}
@anshooarora

This comment has been minimized.

Copy link
Member

anshooarora commented Dec 5, 2018

@qamadhu This was resolved in extentreports-4.0.2. Let me bump the version here, but you can test by adding the latest extentreports version in your pom.xml and check once.

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports-testng-adapter</artifactId>
    <version>1.0.2</version>
</dependency>
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.0.5</version>
</dependency>
@anshooarora

This comment has been minimized.

Copy link
Member

anshooarora commented Dec 5, 2018

@qamadhu are you adding the code you've shared with me in your project? With this adapter, you only need to add the relevant listener to your base class; no extra settings required. See here.

Once you've done this, simply add a extent.properties file under src/test/resources with the required configuration paths and the service will automatically pick it so you do not need to add any extra code in your project besides the @Listener.

I have created a few examples here

https://github.com/extent-framework/examples/blob/master/extentreports-testng-adapter-example/src/test/java/com/aventstack/extentreports/adapter/testng/tests/SimpleAssertTests.java

Configuration for above: https://github.com/extent-framework/examples/tree/master/extentreports-testng-adapter-example/src/test/resources

Refer readme: https://github.com/extent-framework/extentreports-testng-adapter/blob/master/Readme.md

anshooarora added a commit that referenced this issue Dec 5, 2018

@qamadhu

This comment has been minimized.

Copy link

qamadhu commented Dec 7, 2018

Hi Anshooarora,
Thank you for the update.
I used ExtentIReporterSuiteListenerAdapter at suite level and it was working fine but I couldn't able to solve below points in that

  1. Attach screenshot for failed test
  2. Add INFO into to test results ( E.g: description of @BeforeClass/@BeforeMethod etc)
    So I used above code.
    Please let me know is there any way to add those details using ExtentIReporterSuiteListenerAdapter

Thank you for helping

@foursyth

This comment has been minimized.

Copy link

foursyth commented Dec 7, 2018

Well, the IReporter runs after suite completion so having access to realtime events is not possible. You need ITestListener. See here for options:

http://extentreports.com/docs/versions/4/java/testng.html#listeners

@qamadhu

This comment has been minimized.

Copy link

qamadhu commented Dec 7, 2018

Thank you,
Anshooarora, still issue exists for time updating
I have update the latest latest version in pom.xml
PFA
time update issue

@foursyth

This comment has been minimized.

Copy link

foursyth commented Dec 7, 2018

Is this a regression?

anshooarora added a commit that referenced this issue Dec 7, 2018

@anshooarora

This comment has been minimized.

Copy link
Member

anshooarora commented Dec 7, 2018

@foursyth yeah, but also a bug in the IReporter listeners.

anshooarora added a commit to extent-framework/extentreports-java that referenced this issue Dec 7, 2018

@anshooarora

This comment has been minimized.

Copy link
Member

anshooarora commented Dec 7, 2018

@qamadhu Please check with extentreports-testng-adapter:1.0.3-SNAPSHOT.

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports-testng-adapter</artifactId>
    <version>1.0.3-SNAPSHOT</version>
</dependency>
@qamadhu

This comment has been minimized.

Copy link

qamadhu commented Dec 10, 2018

@anshooarora
I'm not able to add the maven dependency with above version.
It's giving me missing me error "Missing artifact com.aventstack:extentreports-testng-adapter:jar:1.0.3-SNAPSHOT" in pom.xml

I tried deleting the files in .m2 and updated the maven project, But it's not updating with new version
Could you please let me know anything need to be updated

Thanks,
extentdependency

@anshooarora

This comment has been minimized.

Copy link
Member

anshooarora commented Dec 10, 2018

@qamadhu

This comment has been minimized.

Copy link

qamadhu commented Dec 11, 2018

Thank you

@qamadhu qamadhu closed this Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment