
This post is focusing on extent report version 2 but we have new version of extent report 3 and 4 which you can refer using below post.
If you still want to use an older version then you can follow this post.
You can check the detailed description about extent report from here- Extent Report Documentation
I created a detailed Youtube video on this that will help you to achieve the same.
But before moving forward you should know some of the features that we are going to use in this video.
How to capture screenshot in Selenium
How to capture screenshot in failure only
Advance reporting Selenium with Screenshots
Download Extent report
1- Open http://extentreports.com/docs/versions/2/java/ and use maven dependency
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
2- If you are not using maven then you can use jars directly but I would highly recommend you to use maven dependency.
Now once you are done with above two Video’s now start implementing Version 2
Please refer the code which we discussed in above video
Advance reporting Selenium with Screenshots Part 2
package SmokeTest;
import library.Utility;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class VerifyTitle
{
ExtentReports report;
ExtentTest logger;
WebDriver driver;
@Test
public void verifyBlogTitle()
{
report=new ExtentReports("C:\\Report\\LearnAutomation.html");
logger=report.startTest("VerifyBlogTitle");
driver=new FirefoxDriver();
driver.manage().window().maximize();
logger.log(LogStatus.INFO, "Browser started ");
driver.get("http://www.learn-automation.com");
logger.log(LogStatus.INFO, "Application is up and running");
String title=driver.getTitle();
Assert.assertTrue(title.contains("Google"));
logger.log(LogStatus.PASS, "Title verified");
}
@AfterMethod
public void tearDown(ITestResult result)
{
if(result.getStatus()==ITestResult.FAILURE)
{
String screenshot_path=Utility.captureScreenshot(driver, result.getName());
String image= logger.addScreenCapture(screenshot_path);
logger.log(LogStatus.FAIL, "Title verification", image);
}
report.endTest(logger);
report.flush();
driver.get("C:\\Report\\LearnAutomation.html");
}
}
I have not written much for this post because already we have covered the same in past.
For More updates Learn Automation page
For any query join Selenium group- Selenium Group
Hi Mukesh,
Is there any way we can provide more details related to test case in Extent report? Like I have a test case ID (in a test management tool) corresponding to test case I have automated which I need to display in automated test report…
Please let me know more on this.
Hi Niranjan,
Yes, you can achieve it. You need to call desired API call provided by corresponding Test Management tool in order to fetch test case id while your test execution and use same id into ExtentTest logger or you have to pass it every time manually which is tiresome job.
Hi Mukesh
We have implemented Keyword Driven Framework in our Product and is working fine. We want Extent Reports in our framework, is it possible to use Extent Reports in Keyword Driven Framework?
Hi Amandeep,
First of all, Extent reports API doesn’t depend upon any kind of framework. You can integrate it to your existing framework after adding it to project build path.
Thanks Mukesh for your reply!
Extent Reports API integrated to framework. Is it compulsory to use TestNG for Extent Reports, as of now we are not using TestBG in our framework?
Hi Amandeep,
Extent Report APIs works without TestNG also.
Thanks Mukesh, I will try at my end. In case of any issue, I will ping for help again 🙂
Sure Amandeep 🙂
Hi Mukesh
I would like to leern ANT ,when you upload …..I’m waiting..
Hi Shaik,
I am planning for it and will upload soon.
Hi Mukesh,
Will extent reports provide consolidated report. like when I use selenium grid concept of hub to node1 and node2 execution consolidated reports in same html file ?
Hi Triveni,
Yes, extent report consolidate the test execution being executed in grid. Because you will be triggering execution from Hub not from node. So all report can be made available on hub machine.
Hi Mukesh,
I have multiple tests in different classes.when i execute testng.xml only the last test result is getting updated.
What should i do to get the status of all the tests to get updated
Hi Dilip,
Are you telling about the result coming up in extent report ? Please make it clear.
Hi Mukesh,
I want to use extent report for my project, wherein I have used page object model approach and I want to show the screenshots that I have taken to verify the UI as well as the failed test cases screenshots in the extent report.
And I want to generate extent report at the Suite level. Any idea about how to achieve this.
Hi Sameer,
You can achieve this in many ways, one way is that initialize report object in another class with @BeforeSuite method and extent this class to all your test classes so that same report object can be accessed by all your test methods.
Hello, In your video, against the screenshot in report, I cannot see the text ‘Title verification’ which is mentioned in below line of code. In large frameworks we wont be able to make out which screenshot is for which failure.
logger.log(LogStatus.FAIL, “Title verification”, image);
Hi Nikhil,
Extent report and logger don’t depend on WebDriver object. You can take the screenshot of page where your test case is getting fail. Other things you need to handle from your framework.
Hi Mukesh, I followed all steps as you mentioned in video ” but on executing it throws NullPointerException. please help me to solve this problem.
public class extentReport_Demo1 {
public WebDriver driver;
ExtentReports report;
ExtentTest logger;
@Test
public void Launch_Browser(){
report=new ExtentReports(“C:\\Extent Report\\Atulvani.html”);
logger = report.startTest(“verifyGoogleTitle”);
System.setProperty(“webdriver.chrome.driver”, “C:\\Appium Setup\\Browser Driver\\chromedriver.exe”);
driver=new ChromeDriver();
logger.log(LogStatus.INFO, “Browser is Launched”);
driver.get(“http://google.co.in”);
logger.log(LogStatus.INFO, “Application is Up and Running”);
driver.manage().window().maximize();
logger.log(LogStatus.INFO, “Browser is Maximized”);
String title = driver.getTitle();
System.out.println(“Title of the page is = “+title);
logger.log(LogStatus.INFO, “Getting Title of the page successfully”);
Assert.assertTrue(title.contains(“selenium”));
logger.log(LogStatus.PASS, “Title is verified”);
}
@AfterMethod
public void tearDown(ITestResult result){
if(result.getStatus()==ITestResult.FAILURE)
{
String screenshot_path=Utility.captureScreenshot(driver, result.getName());
String image = logger.addScreenCapture(screenshot_path);
logger.log(LogStatus.FAIL, “Title verification”, image);
}
report.endTest(logger);
report.flush();
driver.get(“C:\\Extent Report\\Atulvani.html”);
}
}
And For Utility Class….
public class Utility {
public static String captureScreenshot(WebDriver driver, String screenshotName){
try {
TakesScreenshot ts=(TakesScreenshot)driver;
File source=ts.getScreenshotAs(OutputType.FILE);
String dest = “C:\\Extent Report\\ScreenShots\\”+screenshotName+”.png”;
File destination = new File(dest);
FileUtils.copyFile(source, destination);
System.out.println(“ScreenShot Taken”);
return dest;
} catch (Exception e) {
System.out.println(“Exception while taking Screenshot”+e.getMessage());
return e.getMessage();
}
}
}
Hi Atul,
Please check this statement String screenshot_path=Utility.captureScreenshot(driver, result.getName())
Hi Mukesh,
In my report the screenshot is not displayed. What should i do ?
It is working now. Thanks
Hi there,
Happy to hear it worked.
Hi there,
Kindly check the path of your report and path for screenshot files.
In my repot also screenshot not displayed
Hi Richa,
make sure you are using Java 8
how we can use extend reports in page object model framework
Hi Asha,
Yes, you can. Extend report doesn’t restrict itself to any particular framework.
Hi Mukesh,
Very nice tutorial. Tried implementing extent reports in my project but when using
logger.log(LogStatus.PASS,”Element Clicked”,image_1);
I’m just getting the screenshot not getting the message “Element CLicked along with it.
is this Fixed Nidhi?
Hi Mukesh,
This is Nidhi , I want to use this extentreport API for the protractor framework. So is it possible to call this library using javascript as protractor uses javascripts for writing the scripts.
Hi Nidhi,
Extent report does not support Protractor framework as of now.
Hi Mukesh,
This is satish
I am working with extent reports.Can i know we can change the report name dynamically which is saved in output folder.
Ex:Can we add test cases status ie PASS/FAIL to report name after execution .
Could you help me on this
Yes Satish you can change the name at runtime based on timestamp or any other logic as well. We can add any status as well for test cases.
Hi Mukesh,
Thanks very much for the great tutorials, learning a lot. I pretty much followed your example to use extent reports, I keep getting this error. I used maven to download the jars, code is almost the same. I would appreciate some tips on how to solve this. Thanks again for your great service.
is this fixed Shobana?
No Mukesh, I retried it still doesn’t work, I can’t make out what is wrong. Any input would be appreciated
Hope this is fixed now.
Hi Mukesh,
Thanks for the detailed explanation.
But I am getting a broken html report. Can you please suggest how can that be fixed.
I have tried using extentreports-2.05.jar as well as extentreports-2.40.jar.
Try with 2.41
Hi Mukesh,
I am not able to download the report from the given link as the link is not working. Did you update the link?
Hi Pulkit,
Here is the new link http://extentreports.relevantcodes.com/
What are steps in report
Steps in Automation is similar to Step is manual testing.
It works, thanks 🙂
Cheers Fion 🙂
Hi Mukesh,
is this possible to launch the report automatically to the web browser after executing the test
Hi Ether,
You can follow below post http://learn-automation.com/send-report-through-email-in-selenium-webdriver/
Hi Mukhesh ,
Can you tell me which firefox version we can use for selenium webdriver java jar file 2.53?
Hi,
Kindly follow below guide and video http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
Hi Mukesh,
Currently i am getting report for individual test cases, but i want to get the report for the entire suite, suppose if there are 20 testcases in suite, it should show the results for 20 testcases (Like 15 passed and 5 failed) and a corresponding graph which shows 15 passed and 5 failed, is there any way of doing this
Thanks
Raghavendra
Hey Raghavendra,
below link will help http://extentreports.relevantcodes.com/java/#parallel-runs
Hi Mukesh, Just want to know one thing if I have teste cases in diff class files and then i create one testng suite then how can i use this extent report concepts, when i try to use as per your blog, in that case only the report is shown with only cases from one class file. Could you please help here.
Hi Ashutosh,
Kindly check below link http://extentreports.relevantcodes.com/java/#parallel-runs
Hey, Mukesh.
How can I use ExtentReports when I am running multiple classes using TestNG framework, Do I need to write the below code in all test classes.
ExtentReports extent;
ExtentTest logger;
Hi Akhil,
StartTest and EndTest you can call for every test and make sure flush method should come at last
Thanks alot Mukesh.
So we no need to add Flush after method right.
yes
Hi Mukesh,
Your blog is really awesome. I’ve a doubt. I tried to attach extent report output as a .html file in mail. when i receive mail it’s missing all css. And i tried to convert .html to .pdf and nothing didn’t work. Is there any possiblility to attach the extent report output in mail
Hi Devi,
I have shared one post and I have specified some points as well kindly check http://learn-automation.com/send-report-through-email-in-selenium-webdriver/
After executing extent reports are displaying broken image. Can u help me with this
Hi Rahul,
The issue is the path of images is not correct so it will show broken icon. Kindly recheck the screenshot path.
Hi Mukesh,
Is it possible to use extent reports for batch execution. ?
Hi Ruth,
Yes we can do that but its tricky check below url for more details http://extentreports.relevantcodes.com/java/#parallel-runs
I’m unable to zoom screenshot, which was includes into report in Firefox, but working fine in Chrome.
Seems extent report issue.Not sure on this.
Hi Mukesh,
Just wanted to know weather it is possible for us to add expected and actual result in the extent and report look quite impressive 🙂
Yes you can add them in logger.log to get into HTML report.
Dear Mukesh,
Thank you very much for the great tutorial. Would it be possible to share some information on how to configure ExtentReports in Jenkins CI?
Best Regards,
Anandhi
Hi Anandhi,
It is same like normal process no other changes in Jenkins.
Hi Mukesh,
in my selenium test project i’m using Page object model where i have different classes for each page and there is one testNG class which has all the test methods/cases. extent reporting works correctly within test methods but i want to add the logs in to same report file from the page classes as well when that particular method is called from testNG test methods.
e.g. below is my testNG test method which calls login method
@Test
public void VerifyLoginSuccess() throws Exception {
extent= new ExtentReports(“E:\\Report\\MyReport.html”);
logger=extent.startTest(“VerifyLoginSuccess”);
driver = new FirefoxDriver();
LoginPage login = new LoginPage(driver);
logger.log(LogStatus.INFO, “Browser started “);
Dashboard dashboard = new Dashboard(driver);
CommonFunctions cfunction = new CommonFunctions(driver);
dashboard = login.LoginToHRM(“username”, “password”);
String ActualText = dashboard.GetDashboardText();
Assert.assertEquals(ActualText, “Dashboard”,”Successfully logged in”);
cfunction.LogOut();
logger.log(LogStatus.INFO, “Portal Log out “);
}
You forgot to call endTest and flush method
Hi Mukesh,
Thank you so much for writing this blog and guiding us through automation using Selenium . The info and videos are really helpful even for a person who is new to automation.
Hey I used the Extent Report in my case but getting error. So I copied your code and tried again but getting similar error. Could you please suggest if any changes are needed?
Here is the error:
FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=verifyBlogTitle status=FAILURE method=VerifyTitle.verifyBlogTitle()[pri:0, instance:advancedReport.VerifyTitle@c0edeb] output={null}])
java.lang.NullPointerException
at advancedReport.Utility.captureScreenshot(Utility.java:15)
at advancedReport.VerifyTitle.tearDown(VerifyTitle.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:703)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
FAILED: verifyBlogTitle
java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:85)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:419)
at advancedReport.VerifyTitle.verifyBlogTitle(VerifyTitle.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateModelException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 27 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
Hi Padmaj,
Thanks for nice feedback. I can see null pointer exception in Utility. Have you created this library for screenshot ? If not then first create this lib and then try once again.
Hi Mukesh,
i am using extentreports in my sample test as shown in below code, the test is running without errors but it is not creating the html report file, though it creates only empty folder.
what is missing here?
Any help on this much appreciated.!!
Thanks,
Yogiraj
public class MyTests {
ExtentReports extent;
ExtentTest logger;
WebDriver driver;
@Test
public void VerifyLoginSuccess() throws Exception {
extent= new ExtentReports(“E:\\Report\\MyReport.html”);
logger=extent.startTest(“VerifyLoginSuccess”);
driver = new FirefoxDriver();
LoginPage login = new LoginPage(driver);
logger.log(LogStatus.INFO, “Browser started “);
Dashboard dashboard = new Dashboard(driver);
CommonFunctions cfunction = new CommonFunctions(driver);
dashboard = login.LoginToHRM(“username”, “password”);
String ActualText = dashboard.GetDashboardText();
Assert.assertEquals(ActualText, “Dashboard”,”Successfully logged in”);
cfunction.LogOut();
logger.log(LogStatus.INFO, “Portal Log out “);
}
@AfterTest
public void afterTest() {
extent.endTest(logger);
driver.close();
driver.quit();
}
}
Hi Yogiraj,
I got the issue. You missed to call flush method after endTest 🙂
Kindly refer the post again and let me know if still issue persist.
Thanks Mukesh, that solved the issue, Thanks again and keep up the good work
Cheers
Hi Mukesh- I am getting ExtentReports link which navigates to “http://extentreports.relevantcodes.com/” in the automation test report. How to avoid displaying this in my automation test report. I have searched different config but no luck. Could you please let me know how to hide that link in my test report. I am using the version 2.41.1
Hi Raghavendra,
You can only make these changes to report http://extentreports.relevantcodes.com/java/#configuration
Hey ,
This is very informative . I really like your videos .
I have a question hope you can help me with it.
Extent reports are email-able reports so when you take a screenshot on failure and save it on your local machine how can you send the full report with the screenshot to someone by email i mean what if i want to send the extent report to someone in my team , they wont get the image on the failed testcase screen as its on my local .
Can you please advise.
Thanks
Salwa
Hi Salwa,
In this case store all the screenshot in shared driver and then access and send email http://www.assertselenium.com/java/emailable-reports-for-selenium-scripts/
Thanks a lot Mukesh… for introducing such wonderful method for advanced reporting.
Found really helpful and on basis of this article , i have created combined report for multiple Test(s)
just declared report interface as :
private static ExtentReports report = new ExtentReports (“G:\\Selenium\\AdvancedReports\\MyReports.html”);;
private static ExtentTest logger ;
and started logger = report.startTest(“TC Name”)
and ended report.endTest and Flush operation under @AfterClass Annotation.
which worked successfully for me and very impressive combined report has been generated..
Thanks A lot for this..Great Job!!
Hey Vishnu,
Cheers 🙂
Awesome Mukesh.
Your videos really help. And i prefer your stuff than any other information from GOOGLE.
They are really good, informative, clear, interesting, to the point, in sync with up-comming requirements.
Continue the good work, and share the knowledge with us.
Hey Venkatesh,
Thank you mate yes I will continue the same. Your comment related to Google has boosted my energy.
Hi Mukesh
I want to implement this reporting with Apache ANT Build.xml file, previously i used Report NG to generate the report now i want to use this Extent reports jar. Please tell me what modifications should i do to my Apache ANT build.xml. I use TestNG.xml to schedule tests.
Thank u in advance
Hey Angira,
You can download jar and keep in lib folder where other files are located. Remaining process will be same.
I will still suggest you to use maven rather then ant.
Hi Mukesh,
I am getting below exception in my console upon trying to implement extent reports.
Kindly suggest what shall i do to get rid of this exception:
java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:85)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:374)
at com.cgi.tests.reports.REG_TCT1001.beforeMethod(REG_TCT1001.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:589)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:822)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1130)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateModelException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Hey Shantnu,
Please download latest jars and add in project. It is due to some jar missing from extent report.
[TestNG] Running:
C:UsersAR2104AppDataLocalTemptestng-eclipse-1272743253testng-customsuite.xml
screenshot taken
FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=verifySeleniumBlog status=FAILURE method=ExtentReportsEx.verifySeleniumBlog()[pri:0, instance:appium.ExtentReportsEx@6a41eaa2] output={null}])
java.lang.NullPointerException
at appium.ExtentReportsEx.tearDown(ExtentReportsEx.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
FAILED: verifySeleniumBlog
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.relevantcodes.extentreports.Configuration.getConfigurationMap(Configuration.java:38)
at com.relevantcodes.extentreports.Report.loadConfig(Report.java:470)
at com.relevantcodes.extentreports.Report.(Report.java:607)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:72)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:373)
at appium.ExtentReportsEx.verifySeleniumBlog(ExtentReportsEx.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 52 more
im getting the above error
herre is my code
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import egs.trailblazer.baseutils.Constants;
public class ExtentReportsEx {
ExtentReports report;
ExtentTest logger;
WebDriver driver;
@Test
public void verifySeleniumBlog(){
report=new ExtentReports(“F:\SeleniumWorkSpace\TrailBlazer\Reports\LearnAutomation.html”,true);
logger=report.startTest(“verifySeleniumBlog”);
driver=new FirefoxDriver();
driver.manage().window().maximize();
logger.log(LogStatus.INFO, “Browser started “);
driver.get(“http://www.learn-automation.com”);
logger.log(LogStatus.INFO, “Application is up and running”);
String title=driver.getTitle();
Assert.assertTrue(title.contains(“Google”));
logger.log(LogStatus.PASS, “Title verified”);
}
@BeforeMethod
public void before(){
}
@AfterMethod
public void tearDown(ITestResult result) throws IOException
{
if(result.getStatus()==ITestResult.FAILURE)
{
TakesScreenshot ts = (TakesScreenshot)driver;
//File source = ts.getScreenshotAs(OutputType.FILE);
String dest = Constants.screenshotFilePath+”\”+result.getName()+”__”+”.png”;
File destination = new File(dest);
//FileUtils.copyFile(source,destination);
System.out.println(“screenshot taken”);
String image= logger.addScreenCapture(dest);
logger.log(LogStatus.FAIL,image, “Title verification”);
report.flush();
}
}
// driver.get(“..\Report\LearnAutomation.html”);
}
please add
report.endTest(logger);
Hi Mukesh,
Am running one @Test method on multiple browser parallel using XML.
now am saving results in different folder like chrome,mozilla
is it possible to store/get result of the same @test case on diffrent browser using Extent reporting
public ExtentReports report;
public ExtentTest logger;
@Parameters(“MyBrowser”)
@Test
public void IB(String MyBrowser) throws Exception{
WebDriver driverThread=openBrowser(MyBrowser);
report=Reporter(MyBrowser,report);
logger=report.startTest(” test started”);
}
//——————–
public ExtentReports Reporter(String MyBrowser,ExtentReports report){
switch (MyBrowser) {
case “Firefox”: case “F”: case “FF”: case “remote_firefox”:
report=new ExtentReports(“HtmlOutput\\FireFox\\TC001.html”);
return report;
case “Chrome”: case “C”: case “remote_chrome”:
report=new ExtentReports(“HtmlOutput\\chrome\\TC001.html”);
return report;
case “Internet Explorer”: case “IE”: case “remote_ie”:
report=new ExtentReports(“HtmlOutput\\InternetExplorer\\TC001.html”);
return report;
case “Safari”: case “S”: case “remote_safari”:
report=new ExtentReports(“HtmlOutput\\Safari\\TC001.html”);
return report;
default :
return report;
}
}
can you please tell me how to save results of same test cases on multiple browser using extent reporting
Thank you in advance
note:sorry my previous email Id was wrong
you can use timestamp for this.
Hi Mukesh,
Thank you for the beautiful explanation.
I used the same code for generating the report but it does not create the report in destination folder.
Test scripts are executed and no errors are generated..
Below is my code:
package com.learnTestNG;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
/*import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;*/
//import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
//import org.testng.annotations.Optional;
//import com.beust.jcommander.Parameter;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class TestRedBus
{
/*public static*/ static WebDriver driver;
private static String baseUrl;
ExtentReports report;
static ExtentTest logger;
private String filePath=”C:\\Script Report\\RedBusReport.html”;
@BeforeTest
public void beforeTest()
{
report=new ExtentReports(filePath);
logger=report.startTest(“Verify Home page for RedBus.in”);
driver = new FirefoxDriver();
FirefoxProfile fxprofile=new FirefoxProfile();
fxprofile.setAssumeUntrustedCertificateIssuer(true);
fxprofile.setAcceptUntrustedCertificates(true);
//driver.manage().window().maximize();
logger.log(LogStatus.INFO, “Browser is up and running”);
baseUrl= “https://www.redbus.in/”;
driver.get(baseUrl);
logger.log(LogStatus.INFO, “Application is up and running”);
System.out.println(“Current URL is ” +driver.getCurrentUrl()) ;
System.out.println(driver.getTitle());
logger.log(LogStatus.INFO, “Got the title of application home page”);
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
}
@Test
/*Enter source destination and
* click on datepicker icon and then click on next button from calendar*/
public void TestHomePage() throws InterruptedException
{
driver.findElement(By.id(“txtSource”)).sendKeys(“Mumbai”);
driver.findElement(By.id(“txtDestination”)).sendKeys(“pune”);
logger.log(LogStatus.INFO, “Entered Source and destination”);
}
@Test
public static void testSelectOnwardDate() throws InterruptedException
{
System.out.println(“——————Staring with onward journey—————“);
driver.findElement(By.id(“txtOnwardCalendar”)).click();
driver.findElement(By.xpath(“.//*[@id=’rbcal_txtOnwardCalendar’]/table[2]/tbody/tr[1]/td[3]/button”)).click();
Thread.sleep(3000);
String date =”13-Jun 2016″;
String splitter[]= date.split(“-“);
System.out.println(splitter);
String CheckInDay= splitter[0];
String CheckInMonth_Year= splitter[1];
System.out.println(CheckInDay);
System.out.println(CheckInMonth_Year);
//to get the month and year from Onward calendar
List elements = driver.findElements(By.xpath(“.//div[@class=’Calendar’]/table/tbody/tr[@class=’monthHeader’]/td[@class=’monthTitle’]”));
for (int i=0; i<elements.size(); i++)
{
System.out.println(elements.get(i).getText());
if(elements.get(i).getText().equals(CheckInMonth_Year))
{
System.out.println("————————");
//selecting the date
List days = driver.findElements(By.xpath(“.//*[@id=’rbcal_txtOnwardCalendar’]/table[contains(@class ,’month’)][2]/tbody/tr/td[contains(@class, ‘day’)]”));
for(WebElement d : days)
{
System.out.println(d.getText());
if(d.getText().equals(CheckInDay))
{
d.click();
Thread.sleep(3000);
break;
}
}
logger.log(LogStatus.INFO, “Selected onward journey date”);
}
}
}
@Test
public static void testSelectReturnDate() throws InterruptedException
{
//Exception e= new Exception();
System.out.println(“———-Staring function for return journey————–“);
driver.findElement(By.id(“txtReturnCalendar”)).click();
//driver.findElement(By.xpath(“.//*[@id=’rbcal_txtReturnCalendar’]/table[2]/tbody/tr[1]/td[3]/button”)).click();
String Return_date =”14-Jun 2016″;
String splitter_Date[]= Return_date.split(“-“);
System.out.println(splitter_Date);
String CheckOutDay= splitter_Date[0];
String CheckOutMonth_Year= splitter_Date[1];
System.out.println(CheckOutDay);
System.out.println(CheckOutMonth_Year);
try
{
//Selecting month and year from return calendar
List elements = driver.findElements(By.xpath(“.//div[@id=’rbcal_txtReturnCalendar’]/table[contains(@class, ‘monthTable’)]/tbody/tr[@class=’monthHeader’]/td[@class=’monthTitle’]”));
System.out.println(“—————Starting calculation for date/moth/year selection from calendar————-“);
for(int j=0; j<elements.size(); j++)
{
System.out.println(elements.get(j).getText());
Thread.sleep(3000);
if(elements.get(j).getText().equals(CheckOutMonth_Year))
{
System.out.println("————————");
//selecting the dates from return calendar
List Returndays = driver.findElements (By.xpath(“.//*[@id=’rbcal_txtReturnCalendar’]/table[contains(@class ,’month’)][1]/tbody/tr/td[contains(@class, ‘day’)]”));
for(WebElement d : Returndays)
{
System.out.println(d.getText());
if(d.getText().equals(CheckOutDay))
{
d.click();
Thread.sleep(3000);
break;
}
}
}
}
}
catch(StaleElementReferenceException e)
{
e.printStackTrace();
e.toString();
System.out.println(“Trying to recover from Stale element ” +e.getMessage());
}
logger.log(LogStatus.INFO, “Selected return journey date”);
driver.findElement(By.id(“searchBtn”)).click();
logger.log(LogStatus.INFO, “Clicked on search buses”);
System.out.println(driver.getTitle());
logger.log(LogStatus.PASS, “Navigated to search buses page.”);
}
@AfterTest
public void afterTest()
{
/* report.endTest(logger);
report.flush();
driver.close();
driver.quit();*/
//driver.get(“C:\\Script Report\\RedBusReport.html”);
}
}
Hi,
EndTest will generate report.
Hi Mukesh,
I followed all the steps exactly as you have mentioned in the video and downloaded the jar from http://mvnrepository.com/. But still I am getting below error when I run my tests.
FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=tc1 status=FAILURE method=ReportTest.tc1()[pri:0, instance:testScripts.ReportTest@36b98809] output={null}])
java.lang.NullPointerException
at testScripts.ReportTest.tearDown(ReportTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:786)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
FAILED: tc1
java.lang.NoClassDefFoundError: freemarker/template/TemplateException
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:84)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:230)
at testScripts.ReportTest.tc1(ReportTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 27 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
++++++++++++++++++++++++++++++++++++++++++++++++
this is my code
package testScripts;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class ReportTest {
ExtentReports report;
ExtentTest extentre;
WebDriver driver;
@Test
public void tc1()
{
report = new ExtentReports(“C:\\Report.html”);
extentre = report.startTest(“Verify the title”);
driver = new FirefoxDriver();
driver.get(“http://www.google.com”);
driver.manage().window().maximize();
extentre.log(LogStatus.INFO, “Browser Launched”);
driver.manage().timeouts().implicitlyWait(5000 ,TimeUnit.SECONDS);
String name = driver.getTitle();
Assert.assertTrue(name.contains(“Google”));
extentre.log(LogStatus.PASS, “Title verified”);
}
@AfterMethod
public void tearDown(ITestResult result)
{
if(result.getStatus()==ITestResult.SUCCESS)
{
extentre.log(LogStatus.INFO, “Inside Success”);
}
report.flush();
report.close();
//driver.get(“D:\\ExtentReport\\Report.html”);
}
}
Hi Kumar,
Make sure all four jars added as I mentioned the above post.
Please end the test then only it will create report.
Add below code
report.endTest(logger);
remove this code
report.close();
Hi Mukesh,
Despite failing the TC, it is not able to upload screenshot on Extent Report Path [C:\\Reports\\Learn-Automation.html].
It seems the code String image = logger.addScreenCapture(screenshot_path); does not work anymore and they may have modified the same or maybe am missing something.
Please clarify.
Thank you,
Nitin
Hi Nitin,
Its working fine I just checked Cheers 🙂
hi Mukesh i added all jars show in snapshot then its working as expected.
Thanks alot
Hey Vikaram,
Cheers for new report.
Hi Mukesh,
I am trying to use relative path for adding a screenshot in my report but not sure why its not working-
Here is how i am adding taking a screenshot –
public static String captureScreenshot(WebDriver driver, String screenshotName)
{
try {
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String destold = “./target/runscreenshots/”;
String dest = destold + screenshotName + “.png”;
File destination = new File(dest);
FileUtils.copyFile(source,destination);
System.out.println(“screenshot taken”);
return dest;
}
catch (Exception e)
{
System.out.println(“Exception while taking a screensht” +e.getMessage());
return e.getMessage();
}
}
and here is how i am adding to report
logger.log(LogStatus.PASS, methodname + ” Add Attempt Success“);
String image = this.captureScreenshot(driver, methodname + “Success”);
System.out.println(“After capture”);
String image1 = logger.addScreenCapture(image);
System.out.println(“after image 1″ +image1);
logger.log(LogStatus.INFO, methodname + ” Screenshot: “, image1);
System.out.println(“after log” +image1);
report.flush();
Absolute paths are working fine but not sure why screenshot does not get attached using relative path. Any help would be appreciate. Thanks!
Hi Garima,
Ideally relative path also should work I will try in my machine and will let u know.
Have a nice weekend.
Am really after using your report but am also facing the same problem
Thanks 🙂 what issue u r facing?
Hi Mukesh,
I want to add Extent report at listeners and logging level on my project such that test logging that i input at test scripts and listeners output both will be available after execution of the test suite. Basically i want to mix extent report at listeners and logging level simultaneously. Currently while trying to add testng is executing single method twice from logging and from extent report but I want that to execute single method only and both logging and result any exception comes in a single method.
Please help.
Cheers!!
-Rahul
Hi Rahul,
Can you send me ur code so that I can check and modify accordingly as per requirements.
Hi How you have added import library.Utility in “Advanced Selenium Reporting with Screenshots Part 2”.
Dow we need any separate jar file for this?
Thanks
HI Manu,
We have created this Utility to read excel refer below link for more details https://www.youtube.com/watch?v=sbBdj4zIMqY
Hi Mukesh,
i had written the below code,
@Test
public void highestFareTest() throws IOException {
String Path = “F:\\MyProject\\redbus\\test-output\\Extent.html”;
ExtentReports extent = new ExtentReports(Path);
ExtentTest test=extent.startTest(testName);
new homePage(driver).searchBus(td.getData());
test.log(LogStatus.PASS, “Site launched”);
extent.endTest(test);
}
problem is test is getting executed , but extent.html file is not generated in the given path.
Am using 2.40 jar of extent report.
PLease add flush method after endtest
Hi Mukesh,
Subramanya here. Would like to know how to share this extent report with screenshot to clients ? I did go through your comments section and came across a solution to keep screenshots in shared folder. Is there any other alternative solution for this ?
HI Subramanya,
I would recommend shared folder only because we are also using the same approach.
Hi, It is very useful to me and i implemented in my project. But in the report i am not seeing the screenshot picture taken. I used the same code from your blog. Could you please let me know what should i do?
Hi Divman,
Please make sure that screenshot path is absolute (exact path relative path wont work).
Let me know if still not fixed.
Hello Mukesh,
I am not able to fetch screenshot using the above code , in Extent Report html file a, i am getting blank page screenshot. Can you please guide where i am going wrong ?
Here is my code :-
public class Login_To_Force
{
ExtentReports extent;
ExtentTest test;
WebDriver driver;
@BeforeTest
public void base()
{
extent = ExtentManager.Instance();
// extent = new ExtentReports(“./ExtentReport.html”, true);
driver = new FirefoxDriver();
driver.get(“https://test.salesforce.com/”);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@Test(priority=1)
public void LogintoSalesForce() throws InterruptedException
{
ExcelUtils Exceldata = new ExcelUtils(“TestData-SF.xls”, “Login”);
//Actions myaction = new Actions(driver);
Login loginsalesforce = PageFactory.initElements(driver,Login.class);
test = extent.startTest(“Login Page”, “Verify login to Sales Force”);
loginsalesforce.enterUserName(Exceldata.getCell(3, 0));
test.log(LogStatus.PASS,”Enter Username”);
loginsalesforce.enterPassWord(Exceldata.getCell(3, 1));
test.log(LogStatus.PASS, “Enter Password”);
loginsalesforce.clickSignin();
test.log(LogStatus.PASS, “Click on Sign in button”);
}
@AfterMethod
public void sShot(ITestResult result)
{
if(result.getStatus()==ITestResult.SUCCESS)
{
String screenshot_path=ExtentManager.CaptureScreen(driver, result.getName());
String image= test.addScreenCapture(screenshot_path);
test.log(LogStatus.PASS, “XYZ”, image);
}
}
@AfterClass
public void tear()
{
extent.endTest(test);
extent.flush();
extent.close();
driver.quit();
}
Change below line
before
test.log(LogStatus.PASS, “XYZ”, image);
After
test.log(LogStatus.PASS, image,“XYZ”);
It works !!! 😉
Thank you very much for your help . *hug* ;-)))
Cheers
Loren
Hey Loren,
Great Cheers 🙂
Hi Mukesh,
How will i used extent report in key word-driven frame work? .
As in framework there are 3 or more step against each test cases. so will i implement this in such a way that each test case content it test steps in hierarchy way.
below piece of code return the result for test cases parent0 only. not for parent 1 and parent 2.
public static void main(String arg[])
{
ExtentReports extent=new ExtentReports(“./demo.html”);
ExtentTest parent=null;
for(int i=0;i<3;i++){
parent = extent.startTest("Parent"+i);
for(int j=i;i<3;i++){
ExtentTest child1 = extent.startTest("Child 1");
child1.log(LogStatus.INFO, "Info from method"+j);
parent
.appendChild(child1);
}
extent.endTest(parent);
extent.flush();
}
}
Please have a look.
Thank,
Puneet Jain
Hi Puneet,
Please follow below link to perform ur task
http://extentreports.relevantcodes.com/java/version2/docs.html#parallel-classes
Hello,
it seems that my last comment is deleted. 🙁
Anyway, maybe I can ask once again.
Question: How can I use only ONE “myReport.html” for two TestClassess ?
E.g. I have two test classes, which I will execute via testng.xml …
How should I configure the path to the myReport.html in my test class ?
public class TestClass1() {
@Test
public void verifyBlogTitle() {
report=new ExtentReports(“C:\\Report\\myReport.html”);
….
}
}
public class TestClass2() {
@Test
public void verifyBlogTitle() {
report=new ExtentReports(“C:\\Report\\myReport.html”);
….
}
}
Thank you in advance.
Cheers
Loren
Hi Loren,
Here you go
http://extentreports.relevantcodes.com/java/version2/docs.html#parallel-classes
Hello Mukesh,
great tutorial and example 😉 Thank you for that.
I have two questions, please:
1) When I execute the 2 classes in testng.xml, e.g.
…
…
My report is generate but it shows only test results from MyTestExample2 .
Question: How to get only 1 myReport.html for 2 running MyTestExample1 & MyTestExample2 ?
————————————————————————–
public class MyTestExample1 () {
ExtentReports report = new ExtentReports(“C:\\\\Report\\myReport.html”);
ExtentTest logger;
@Test
public void tc1() {}
@Test
public void tc2() {}
…
}
public class MyTestExample2 () {
ExtentReports report = new ExtentReports(“C:\\\\Report\\myReport.html”);
ExtentTest logger;
@Test
public void tc1() {}
@Test
public void tc2() {}
…
}
2) Currently when I execute the test in eclipse I get this warning or error in console
Jan 14, 2016 4:02:04 PM com.relevantcodes.extentreports.Configuration
INFORMATION: Configurating report from file:/C:/MyEclipseIDEForJavaDev/MYARCHIVES/extentreports-2.40.0/extentreports-java-2.40.0.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
Question: What does it mean and how can I solve it, please?
Thank you for your help in advance.
Cheers
Loren
Hi Loren,
This is just some warning which is giving some information about template.
I have sent a link in last comment please check and try the same.
hi manish i am getting below mentioned error while executing the same code
com.relevantcodes.extentreports.Configuration
INFO: Configurating report from file:/D:/selenium/extentreports-java-v2.40%20(1)/extentreports-2.40.0/extentreports-java-2.40.0.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
FAILED CONFIGURATION: @AfterMethod teardown([TestResult name=verifytitle status=FAILURE method=ExtentReport.verifytitle()[pri:0, instance:ExtentReport@18aecf1] output={null}])
please let me know the solution to come oot from this error. I have used 2.40 latest version
Hi Sonam,
Actually it known issue please download all jars from below link and add into project.
Try again and let me know if still issue exist.
In this video, we will use extent version 2 and will create advanced Selenium reporting with screenshot adding on failure.
Download Jars from below location
http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=17
Hi Mukesh,
I followed all the steps exactly as you have mentioned in the video. But I am getting below error when I run my tests.
Dec 22, 2015 9:28:50 AM com.relevantcodes.extentreports.Configuration
INFO: Configurating report from file:/C:/Users/skara1/Desktop/lib/extentreports-2.40.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
FAILED CONFIGURATION: @BeforeMethod init
java.lang.NoClassDefFoundError: freemarker/template/TemplateException
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:84)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:230)
at SmokeTest.SampleTests.init(SampleTests.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Hi Sree,
is it fixed now ?
Great tutorial but I am getting the error as shown below.
[TestNG] Running:
/private/var/folders/nf/yn_rmw7n0_5b08g50whn4jw80000gn/T/testng-eclipse-1248709115/testng-customsuite.xml
Dec 24, 2015 7:19:50 PM com.relevantcodes.extentreports.Configuration
INFO: Configurating report from file:/Users/Xavier/Documents/workspace/extentreports-2.40.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
Expection while taking a screenshotnull
FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=verifyTitle status=FAILURE method=VerifyTitle.verifyTitle()[pri:0, instance:SmokeTest.VerifyTitle@6b71769e] output={null}])
java.lang.NullPointerException
at SmokeTest.VerifyTitle.tearDown(VerifyTitle.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:708)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
FAILED: verifyTitle
java.lang.NoClassDefFoundError: freemarker/template/TemplateException
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:84)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:230)
at SmokeTest.VerifyTitle.verifyTitle(VerifyTitle.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
… 27 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
=============================================
Hi Jessy,
I have noticed the same issue if you will download jar then it issue will come.
Option 1- Download below jars to support extent report.
Please find the attachment and download jar from maven repo http://mvnrepository.com/
Option 2- Use Maven project and use below dependency in POM.xml
Thanks
Mukesh
Hi Mukesh
I have to say that I had extentreports-2.40.jar already added to the project. I changed it to extentreports-2.05.jar and now it works.
This tutorial would not work with the new version.
Regards,
Jessy
Great Jessy Cheers.
And option two works fine for Maven project.
Ok Great Jessy
my test didn’t work,although i follow your instruction precisely
Have you gone through video 1 and video 2 ?
Hi,Mukesh!I did exactly as you did but my program is not runniing it just showing an error
Hi Shah,
What error is coming?
how to send this report to client?
Hi Jeevan,
First of all sorry for late reply. You can send this report without CSS. Screenshot will not be visible because location will change.
You can store all screenshot to a separate shared folder where everyone have access and make the changes in screenshot path.
Thanks
Mukesh