Create your own HTML report from Selenium tests

Please note that this post was created before I first heard of ExtentReports. If you want to create nice-looking HTML reports for your (Selenium) tests, I highly recommend checking it out. It probably provides everything you're looking for. Don't forget: reuse is always better than creating something yourself..

I've written a couple of blog posts on ExtentReports, but you'd be even better off paying a visit to the ExtentReports homepage.

As I am learning more and more about using Selenium Webdriver efficiently (experiences I try to share through this blog), I’m slowly turning away from my original standpoint that user interface-based test automation is not for me. I am really starting to appreciate the power of Selenium, especially when you use proper test automation framework design patterns such as the Page Object pattern I wrote about earlier. However, Selenium by default lacks one vital aspect of what makes a good test automation tool to me: proper reporting options. Luckily, as Selenium is so open, there’s lots of ways to build custom reporting yourself. This post shows one possible approach.

My approach
Personally, I prefer HTML reports as they are highly customizable, relatively easy to build and can be easily distributed to other project team members. To build a nice HTML report, I use the following two step approach:

  • Execute tests and gather statistics about validations executed
  • Create HTML report from these statistics after test execution has finished

In this post I’ll use the following test script as an example. I created a page with five HTML text fields, for which I am going to validate the default text. Nothing really realistic, but remember it’s only used to illustrate my reporting concept.

public static void main (String args[]) {
		
	WebDriver driver = new HtmlUnitDriver();
	driver.get("http://www.ontestautomation.com/files/report_test.html");
		
	for (int i = 1; i <=5; i++) {
		WebElement el = driver.findElement(By.id("textfield" + Integer.toString(i)));
		Assert.assertEquals(el.getAttribute("value"), "Text field " + Integer.toString(i));
	}
		
	driver.close();	
}

When we run this script, one error is generated as text field 4 contains a different default value (go to the URL in the script to see for yourself).

Custom reporting functions
To be able to create a nice HTML report, we first need some custom reporting functions that store test results in a way we can reuse them later to generate our report. To achieve this, I created a report method in a Reporter class that stores validation results in a simple List:

public static void report(String actualValue,String expectedValue) {
	if(actualValue.equals(expectedValue)) {
		Result r = new Result("Pass","Actual value '" + actualValue + "' matches expected value");
		details.add(r);
	} else {
		Result r = new Result("Fail","Actual value '" + actualValue + "' does not match expected value '" + expectedValue + "'");
		details.add(r);
	}
}

The Result object is a simple class with three class variables: result (which is either Pass or Fail), a resultText (which is a custom description) and a URL for a screenshot (the use of which we will see later).

For every test we execute in our Selenium script, instead of using the standard TestNG / JUnit assertions, we use our own reporting function. You might want to throw an error as well when a validation fails, but I’m happy just to write it to my report and let test execution continue.

After test execution is finished, we are going to write the test results we gathered to a file. For this, I used an extremely simple HTML template (yes, I was too lazy even to indent it properly):

<html>
<head>
<title>Test Report</title>
<head>
<body>
<h3>Test results</h3>
<table>
<tr>
<th width="10%">Step</th>
<th width="10%">Result</th>
<th width="80%">Remarks</th>
</tr>
<!-- INSERT_RESULTS -->
</table>
</body>

In this template I am going to insert my test results, using a simple replace function

public static void writeResults() {
	try {
		String reportIn = new String(Files.readAllBytes(Paths.get(templatePath)));
		for (int i = 0; i < details.size();i++) {
			reportIn = reportIn.replaceFirst(resultPlaceholder,"<tr><td>" + Integer.toString(i+1) + "</td><td>" + details.get(i).getResult() + "</td><td>" + details.get(i).getResultText() + "</td></tr>" + resultPlaceholder);
		}
			
		String currentDate = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
		String reportPath = "Z:\\Documents\\Bas\\blog\\files\\report_" + currentDate + ".html";
		Files.write(Paths.get(reportPath),reportIn.getBytes(),StandardOpenOption.CREATE);
			
	} catch (Exception e) {
		System.out.println("Error when writing report file:\n" + e.toString());
	}
}

Finally, we need to use these custom reporting functions in our test script:

public static void main (String args[]) {
		
	WebDriver driver = new HtmlUnitDriver();
	Reporter.initialize();
	driver.get("http://www.ontestautomation.com/files/report_test.html");
		
	for (int i = 1; i <=5; i++) {
		WebElement el = driver.findElement(By.id("textfield" + Integer.toString(i)));
		Reporter.report(el.getAttribute("value"), "Text field " + Integer.toString(i));
	}
		
	Reporter.writeResults();
	driver.close();	
}

The initialize() method simply clears all previous test results by emptying the List we use to store our test results. When we run our test, the following HTML report is generated:

The HTML test report

Here, we can clearly see that our test results are now available in a nicely readable (though not yet very pretty) format. In one of my next posts, I am going to enhance these HTML reporting functions with some additional features, such as:

  • Screenshots in case of errors
  • Use of stylesheets for eye candy
  • Test execution statistics

Hopefully the above will get you started creating nicely readable HTML reports for your Selenium tests!

The Eclipse project used in the above example can be downloaded here. The HTML report template can be downloaded here (right click, save as).

159 thoughts on “Create your own HTML report from Selenium tests

  1. Great content!

    We’re working on deploying Selenium Grid in a VM environment with Jenkns and Maven. It would be great if we could incorporate custom reports and have them show up in Jenkins. Right now, I’m using Ant to build our projects. I found your blog while researching next steps for integrating these different pieces. If you know of some resources that may help in getting this worked out, please post the links. Thanka again for such well articulated information..I’ll be a regular visitory.

    • Hello Phil, thank you for your kind words! I’ll try and be as regular a writer as you’ll hopefully be a visitor.

      As for your question, have you tried the seleniumhtmlreport plugin? I’ve looked at it briefly but not enough to gauge whether it would fit your needs.

      I’ve been planning to experiment a little with this myself, so expect a post on creating Jenkins-parseable reports using Selenium in the near future.

          • I’d recommend using ExtentReports as a TestNG listener, it creates nicely readable HTML reports that are instantly emailable (so you can also have them automatically emailed from your CI solution if you use one). Read more about it here and here.

      • I am trying to find a solution for a problem asked. Is there anyway to create HTML report for cucumber project which shows only failed scenarios?

        • Hey Anand, you could combine Cucumber and TestNG and create a custom listener for TestNG that only shows the failed scenarios. Or you could create your own HTML report and simply skip the passed tests. But I’d recommend against doing either, because tests that pass give you valuable information about the application you’re testing, just as failed tests do.

          • Yes You are right. But someone asked me because he thinks that going through lots of user scenarios is waste of time and he wants to see only failed scenarios. Could you please provide me a link for customer listener if you have?

          • I don’t have that link. Another option is to try ExtentReports. It has a filter option (I think) so you can easily see only failed tests, or all tests.

      • Hello I am srikanth. Could you please help me with the coding to implement Extent reports to validate gmail login as I am a beginner.

        • Hey Srikanth, those two are completely separate concepts. ExtentReports is ‘just’ a logger that produces HTML reports, not a test tool or something that’s capable of verification (it’s probably not validation you want to do here).

          In short: I don’t understand what it is you want..

    • Hi Bas,

      Thank You for putting description in Depth.
      I am generating Junit report. I want to add screen shot for the failed test cases.

      Would you please help me on that.
      Here is my code
      ———————–

      ant run will execute the test

      <!– –>

    • Allure definitely seems to be the right thing BUT not able to figure out how to integrate Selenium with it.

      There are no direct and simple steps mentioned anywhere to do it. Most seems to suggest to do it with TestNG .

      There is no adapter also on Allure website for selenium.

      any pointers will greatly help !!

  2. Please remove the third parameter in the below example. It’s not in your code.

    Result r = new Result(“Pass”,”Actual value ‘” + actualValue + “‘ matches expected value”,””);

    Thanks,
    Ken

  3. Hello Sir,

    What is Selenium server-standalon-2.42.2.jar file and from where to download it.

    I tried throughout google but I didn’t get a proper link to download it and everywhere the size of download was approx 17 to 33 mb .

    • Hi Abhinav,

      that’s the core Selenium library I used. Without it, you will not be able to run Selenium tests. You can download it from here. Note that this is a link to Selenium release 2.43.0, which is the latest version.

  4. Hi Bas,

    Can you please update the code for capturing screenshots on failure?

    It will be great if you can include that code for having screenshots in HTML reports.

    Thanks,
    Himraj

  5. Hello Bas,
    Please can you tell me how these reports fit in with Jira or QC ie, how do you integrate automation test into say Jira or Test Director and then do test reporting.
    Appreciated.

    ML

    • Hi ML,

      these reports are not primarily meant to be used in combination with Jira or Quality Center, but as a standalone means of reporting on test results.

      If you want to report your test results from Selenium to Jira, first of all you need to ask yourself whether you want to report test results or just issues. Reporting issues from Selenium in Jira should be fairly straightforward using the Jira REST or SOAP API. How you would go about reporting test results (i.e., number of tests run / passed / failed / etc.) in Jira I don’t know.

      For integration with QC (currently HP ALM), take a look at http://automationtestingutilities.blogspot.nl/p/blog-page_11.html for example. I haven’t tested it myself as I haven’t used QC in ages.

      • Hi Bas,
        Jack here it would be grateful of you, just i want know how to integrate html report into Bugzilla
        can share me the code

        Thanks,
        S.B.Jack

        • Hi Jack,

          I’m not sure what you want to do. Do you want to upload the HTML report to BugZilla? I have no idea how that works, does BugZilla have an API you can use for that?

  6. Hello Bas,
    First, let me say thank you for this post! It’s really useful! ^^
    However, I wonder how can I use your code with Visual C#. Can you help me modify your code to do with C#? I’m just a newbie ^^~ (sorry for bad English)
    Thank you once again.

    Sincere,
    Julie Lee

    • Hi Julie,

      thank you too for your kind words. Unfortunately, I don’t really have any experience in C# myself, so I don’t think I can help you with the conversion of my code..

      Sorry!

    • I have done C# code, I hope it helps for .Net folks
      Reports Class: –

      using System;
      using System.Collections.Generic;
      using System.Globalization;
      using System.IO;
      using System.Drawing.Imaging;
      using System.Windows.Forms;
      using NUnit.Core;
      using OpenQA.Selenium;
      using System.Linq;
      using System.Text;

      namespace RFS_Automation_Specflow
      {
      public class Reporter
      {
      public static List details = new List();
      public static string ResultPlaceholder = ““;
      public static string TemplatePath = “D:\\Stock_Gap_Fix\\Automation_RFS\\RFS_Automation_Specflow\\report_template.html”;
      public static Boolean IncludeScreenshots = true;
      public static string ScreenshotPath = “D:\\Stock_Gap_Fix\\Automation_RFS\\RFS_Automation_Specflow\\screenshots\\”;

      public Reporter()
      {
      }

      public static void Report(IWebDriver driver,String actualValue, String expectedValue)
      {

      if (actualValue.Equals(expectedValue))
      {
      Result r = new Result(“Pass”, “Actual value ‘” + actualValue + “‘ matches expected value”,””);
      details.Add(r);
      }
      else
      {
      String ScreenshotPath = “”;

      if (IncludeScreenshots)
      {
      ScreenshotPath = GetScreenshot(driver);
      }
      Result r = new Result(“Fail”, “Actual value ‘” + actualValue + “‘ does not match expected value ‘” + expectedValue + “‘”, ScreenshotPath);
      details.Add(r);
      }
      }

      public static String GetScreenshot(IWebDriver driver)
      {
      String location = ScreenshotPath + GetCurrentDate() + “.Jpeg”;

      try
      {
      Screenshot sc = ((ITakesScreenshot) driver).GetScreenshot();
      sc.SaveAsFile(location, ImageFormat.Jpeg);
      }
      catch (IOException e)
      {
      MessageBox.Show(“Error while generating screenshot:-” + e.Message);
      }

      return location.Replace(“\\”, “\\\\”);
      }

      public static String GetCurrentDate()
      {
      return DateTime.Now.ToString(“yyyyMMdd_HHmmss”);
      }

      public static void WriteResults()
      {
      string reportIn = string.Empty;

      try
      {
      using (StreamReader reader = new StreamReader(@”D:\Stock_Gap_Fix\Automation_RFS\RFS_Automation_Specflow\report_template.html”))
      {
      String line = String.Empty;

      if((line = reader.ReadToEnd()) != null)
      {
      reportIn += line;
      }
      }

      for (int i = 0; i < details.Count(); i++)
      {
      if (details[i].getResultScreenshot().Equals(""))
      {
      reportIn = reportIn.Replace(ResultPlaceholder,
      "” + (i + 1).ToString() + “” +
      details[i].getResult() + “” +
      details[i].getResultText() + “” + ResultPlaceholder);
      }
      else
      {
      reportIn = reportIn.Replace(ResultPlaceholder,
      “” + (i + 1).ToString() + “” +
      details[i].getResult() + “” +
      details[i].getResultText() + “screenshot” + ResultPlaceholder);
      }
      }

      String reportPath = “D:\\Stock_Gap_Fix\\Automation_RFS\\RFS_Automation_Specflow\\report_template_” + GetCurrentDate() + “.html”;

      File.WriteAllText(reportPath, reportIn);

      }
      catch (Exception e)
      {
      MessageBox.Show(“Unable to Write Log” + e.Message);
      }
      }
      }
      }

      Result Class : –

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;

      namespace RFS_Automation_Specflow
      {
      public class Result
      {

      string result;
      string resultText;
      string resultScreenshot;

      public Result(string result, string resultText, string resultScreenshot)
      {
      this.result = result;
      this.resultText = resultText;
      this.resultScreenshot = resultScreenshot;
      }

      public void setResult(String result)
      {
      this.result = result;
      }

      public String getResult()
      {
      return this.result;
      }

      public void setResultText(String resultText)
      {
      this.resultText = resultText;
      }

      public String getResultText()
      {
      return this.resultText;
      }
      public void setResultScreenshot(String resultScreenshot)
      {
      this.resultScreenshot = resultScreenshot;
      }

      public String getResultScreenshot()
      {
      return this.resultScreenshot;
      }
      }
      }

  7. Hi Bas,

    Thanks very much for providing such a nice article. i have a requirement of sendind HTML reports through email.
    could you help me on this.

    thanks,
    saurabh.

    • Hi Saurabh,

      what mechanism do you use to start your Selenium tests? If you use a continuous integration tool like Jenkins, you could easily set up a step in your build job that sends the required files by email.

    • Hi Anshoo,

      I’ve been playing around with your reporting library and (after fixing the initial problem of it not working with JDK1.6) I must say I’m pretty impressed. It looks great..

      Do you mind if I create a blog post on my site to demonstrate its use with a demo Selenium test?

      • Bas,

        Thank you for taking time to test this library. Thanks for your feedback too. Please feel free to create a post on your website.

        To answer your questions: I created this library with jre 1.8 which may not be backward compatible upto 1.6. As I am quite new to Java (from C# world) I didn’t realize this bug popping up. Please share the new jar and I will replace it with what has been hosted.

        For the 2nd, we can configure it either way, so the oldest test can appear at the very top. I will add this feature in the next version and also learn how to compile it for backward compatibility so the issue with it not working with 1.6 is not there.

        Regards,

        Anshoo

  8. I see your reporting concept to be adaptable. While reviewing the code, I couldn’t map where the class the “details” is from. As it is used in details.Add(), etc. Please can you point to it? Appreciate.

  9. In loop, I am running multiple no. of TCs and not able to get the reports by using TestNG because I have only one test in that.

    Could you please provide the solution for that and which report is useful to use and provide me the sample code for that

    • Hi Pradeep,

      your best bet would be to try the ExtentReports library to create great looking custom HTML reports. It can be downloaded here. I have written a post describing most of the features here, you can also check out a sample report from there.

  10. Hey Bas,

    Today morning I was googling for custom reports and found your blog and you made my day.

    I checked ExtentReports and it worked like charm.I really appreciate your effort and once again thanks for reports.

    • Hi Mukesh,

      great to hear my blog could be of service. All credits go to Anshoo Arora though, he’s the creator of ExtentReports, I just happened to stumble upon it πŸ™‚

  11. Hi Bas,
    There are 4 import options for the Result.
    I imported :
    import javax.xml.transform.Result;

    But I get the error cannot instantiate the type result on this line
    public static void report(WebDriver driver, String actualValue,String expectedValue) {
    if(actualValue.equals(expectedValue)) {
    Result r = new Result(“Pass”,”Actual value ‘” + actualValue + “‘ matches expected value”,””);

    Could you please advice?

  12. Hi Bas,
    I am using c# for coding selenium scripts. Similar to testng reports, do we have anyway through which we can get the test reports in Nunit . Please revert at my mail id. Any suggestions would be greatly appreciated.

  13. Hi bas,
    You mind pointing out a small error.The r of report in Report.reporter inside main has to be uppercase.i got an error that is why so Report.Reporter correct?

  14. Hi bas,
    To be frank when i run this script i was actally expecting firefox browser to come up and go to the link you inserted.to my surprise i found out that didn’t happen but a new report was generated inside the folder which i suspect is because you gave the below code-
    WebDriver driver = new HtmlUnitDriver();
    Reporter.initialize();
    driver.get(“http://www.ontestautomation.com/files/report_test.html”);
    How did this work?

    • That report_test.html file is a simple HTML file I created to demonstrate the workings of the test. It’s a static file that is hosted on my own domain and is not created by your test.

      Could you please post your code so I can take a look?

      • ok no i didn’t change your code.i didn’t notice
        your below code.
        WebDriver driver = new HtmlUnitDriver();
        That was what i meant.you script ran without any problem and the report was generated.
        But can you please say what this HTmlUnitDriver does?it inserts information in htmal format?

        • Ah, now I get your question πŸ™‚

          The HtmlUnitDriver is a headless driver included in Selenium WebDriver. It runs browser tests in headless mode, which means that no browser window is visible, but all HTTP calls to the designated server are still made and responses are still captured, so tests can be carried out nonetheless. It has severe restrictions though, especially when it comes to JavaScript emulation. I wouldn’t recommend using it in any serious test automation effort.

          Anyway, that’s why you didn’t see a browser window opening up. Just replace

          WebDriver driver = new HtmlUnitDriver();

          by

          WebDriver driver = new FirefoxDriver();

          and you’ll see what happens.

          • πŸ™‚ yup now it showed on firefox browser.if you don’t mind are you working in some company as Test Engineer?

          • I don’t mind, it’s all on LinkedIn anyway!

            I’ve been a software test engineer for over 9 years now. Used to work for different companies, now I’m a freelancer.

          • ok i have a question.As i work in a small company i am in good relationship with all my work mates.I am the only tester there.But if what i heard is true in big companies and all one employee maynot know anything about other employees or like if there is a tester and development team,they will be in constant fights when errors mount up.will that help?i mean rather than be jealous or egoistic about each other,error finding can also be seen as a source to improve the quality of the product developed right?

          • Ah, the old tester versus developer debate.

            To be honest, I never really experienced that myself and I’ve worked for both large and small organizations. Most developers are humans too πŸ™‚ Of course, it’s never fun to be told you made a mistake but it happens all the time.

            Especially in Agile teams, you’re expected to collaborate. As long as everybody has that mindset, working side by side with developers can be a lot of fun, actually.

    • And anyway, ever since ExtentReports came to my attention I don’t like the solution I created myself anymore. If you want great HTML reports for your Selenium tests I’d highly recommend ExtentReports.

      • since you brought up ExtentReports i have a query.
        Anyway to check something say the title,we have to get the title using get.title() and use an assert function of either junit or testng to check if it matches the title we have given as “title” right?Then only the testing make sense right?
        so the output of the assert function a pass or a fail we have to pass onto ExtentReport and show it in the generated ExtentReport right?so we have to use framework(either junit or testng) along with ExtentReport to do our automated testing right?

  15. Hi Bas,

    I’m a young (23) Test Engineer. I’ve worked in testing since I graduated (2 years ago). I’m a more technical profile. My pleasure is to develop test framework.
    Currently, I’m developing (in my free time) a test platform based on Selenium and cucumber. Your paper helped me on my first implementation of my reporting. I give you kisses for that :p

    I don’t really know why I’m answering right know. It’s just that your papers helped me a lot.

    An other idea I have in my mind is to write tutorials to create a test framework step by step for beginners.

    Enough talked about me… have a nice day and thanks a lot πŸ˜‰

  16. HI Bash,
    Jack here can tell me how to integrate html report with Bugzilla if you share the code, it would be grateful of you.

    Thanks,
    S.B.Jack

  17. Hi,

    I am using jre1.6.System throws error in eclipse when providing below packages.Kindly suggest me the further step.

    import java.nio.file.Files;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;

  18. Hi Bas,

    The project for html report generation link you provided for download is not in proper format.Html file is missing nd below packages are not working.Kindly upload a proper one.
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;

  19. Just so great. Thanks for the post πŸ™‚

    Hey I was wondering if I want the screenshots and execution time as two columns in the report. How to achieve this πŸ˜€

  20. If I am running my project by using maven then is it possible to get above report or I need to run using testing only?

    • Hi Aliya, you should be able to generate a report like this no matter what tool you use to run your tests, so Maven should work fine. I recommend using ExtentReports instead of creating of your own HTML reports though!

      • Thanks Bas!! ExtentReport looks very nice but I want customized report which will give detailed information in script. So I am thinking to go with HTML report and will export html report into Excel.
        Apart from that is there any way to create customized report?

  21. i am in learing stage of java and automation and create html report using you code but i am getting nullpoint Exception at point detaIL.add(r) would you expain me what i do

    • Hi Jiya,

      I highly suggest taking a look at ExtentReports rather than creating HTML reports yourself. It’s a lot easier to setup and produces great reports. I have written a couple of blog posts on ExtentReports as well, you should be able to find these using the search function.

  22. Hi Bas,

    I’m opening Eclipse using one of the HTML page designed by me.Eclipse got open but is their anyway as eclipse opened it start running programme aswell automatically.I don’t want manually to click on Run or press F11.

    Can i do some setting my eclipse will start running my programmes automatically

  23. Files.readAllBytes(Paths.get(templatePath))) is failing.

    template path is showing in sysout, So any suggetions please

  24. An Empty report is generating with 0kb. where as the above line of code Files.readAllBytes(paths.get(template)) is showing some value as B@41fbdac4.

    • I highly recommend using ExtentReports rather than building your own HTML report (I wrote this post before I ever heard of it). ‘Reuse over rebuild’. If you really want to build your own HTML report, please share your code as I won’t be able to see what’s wrong otherwise.

  25. code is exactly same copy of your tests…On;y change is driver initiation.

    I used Firefoxdriver. Please find the code below: methods are calling the same code shared by you.

    public class ReportTest {

    public static void main (String args[]) {

    WebDriver driver;
    // System.setProperty(“webdriver.chrome.driver”, “C:\\Softwares\\chromedriver_win32\\chromedriver.exe”);
    driver=new FirefoxDriver();

    Reporter.initialize();
    driver.get(“http://www.ontestautomation.com/files/report_test.html”);

    for (int i = 1; i <=5; i++) {
    WebElement el = driver.findElement(By.id("textfield" + Integer.toString(i)));
    Reporter.report(driver, el.getAttribute("value"), "Text field " + Integer.toString(i));
    System.out.println("textfield"+i);
    }

    driver.findElement(By.id("textfield1"));
    Reporter.report(driver,"textfield" , "Text field " );

    Reporter.writeResults();
    driver.close();
    }

    }

    • What line of the code in which class is generating the error? It almost seems like there is some reference to an object or a file that does not exist. The code itself is pretty simple..

  26. package ck.report;

    import java.io.File;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;

    public class Reporter {

    private static List details;
    private static final String resultPlaceholder = ““;
    private static final String templatePath = “C:\\Tools\\report_template.html”;
    private static final Boolean includeScreenshots = true;
    private static final String screenshotPath = “C:\\Tools\\screenshots\\”;

    public Reporter() {
    }

    public static void initialize() {
    details = new ArrayList();
    }

    public static void report(WebDriver driver, String actualValue,String expectedValue) {
    if(actualValue.equals(expectedValue)) {
    Result r = new Result(“Pass”,”Actual value ‘” + actualValue + “‘ matches expected value”,””);
    details.add(r);

    } else {

    String screenshotPath = “”;

    if(includeScreenshots) {
    screenshotPath = getScreenshot(driver);
    }
    Result r = new Result(“Fail”,”Actual value ‘” + actualValue + “‘ does not match expected value ‘” + expectedValue + “‘”,screenshotPath);
    details.add(r);
    }

    System.out.println(“Details List values :”);
    if(details.iterator().hasNext()){
    System.out.println(details.iterator().next());
    }

    }

    private static String getScreenshot(WebDriver driver) {

    // generate screenshot as a file object
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

    String currentDateTime = getCurrentDate();
    String location = screenshotPath + currentDateTime + “.png”;

    try {
    // copy file object to designated location
    FileUtils.copyFile(scrFile, new File(location));
    } catch (IOException e) {
    System.out.println(“Error while generating screenshot:\n” + e.toString());
    }

    return location.replace(“\\”,”\\\\”);
    }

    private static String getCurrentDate() {

    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMdd_HHmmss”);
    return sdf.format(cal.getTime());
    }

    public static void writeResults() {
    try {
    // String reportIn = new String(Files.readAllBytes(Paths.get(templatePath)));
    /*System.out.println(“templatePath is : “+templatePath);
    System.out.println(“Paths.get(templatePath) is : “+Paths.get(templatePath));
    byte[] fileread = Files.readAllBytes(Paths.get(templatePath));

    String nex = new String(fileread);
    System.out.println(“nex is:”+ nex);
    System.out.println(“Files.readAllBytes(Paths.get(templatePath)) is : “+Files.readAllBytes(Paths.get(templatePath)));
    */
    String reportIn = new String(Files.readAllBytes(Paths.get(templatePath)));
    for (int i = 0; i < details.size();i++) {
    if(details.get(i).getResultScreenshot().equals("")) {
    reportIn = reportIn.replaceFirst(resultPlaceholder,"” + Integer.toString(i+1) + “” + details.get(i).getResult() + “” + details.get(i).getResultText() + “” + resultPlaceholder);
    } else {
    reportIn = reportIn.replaceFirst(resultPlaceholder,”” + Integer.toString(i+1) + “” + details.get(i).getResult() + “” + details.get(i).getResultText() + “screenshot” + resultPlaceholder);
    }

    }

    String currentDate = new SimpleDateFormat(“dd-MM-yyyy”).format(new Date());
    String reportPath = “C:\\Tools\\report_” + currentDate + “.html”;
    Files.write(Paths.get(reportPath),reportIn.getBytes(),StandardOpenOption.CREATE);

    } catch (Exception e) {
    System.out.println(“Error when writing report file:\n” + e.toString());
    }
    }
    }

    • That does not compile. Could you please send your whole project to bas@ontestautomation.com, not just one single file? There’s no way that I can make it work this way. Also, I notice that the paths you use in your code are exactly the same as mine, did you create the Tools directory in the root of the C disk and place the template in the correct location?

  27. Hi sir,

    am the one using selenium.. i tried to report on html page..
    But here my prblm is, how can i able to get dynamic data from xls sheet to report on html page. (the xls data is already existed one, how to show html repot on same xls sheet in sheet number 4).

    • Hi Gayatri,

      I’m sorry but I don’t think I understand your question.. Do you want to include a HTML report in an Excel sheet? Or do you want to read data from an Excel sheet and write that to HTML?

      • Actually what am doing is, am getting the data from xl sheet–> in that am validating (expected and actual result).–> In one scenario having many test cases–> each test case am verifying and validating–> here my problm is, where am validating in a paritcular row and column, there i have to exucte html page code to create result whether its passed or failed . here am facing like how to display my results in html page, which is already existed one in sheet 3 (existed one in the sense where am calling my xl data in that sheet i have to show in html page.

  28. Actually here the reqiurement is, when i am executing my tests, there i need to show pop up like which test case am doing like (login flow) –> if paased again i have to show pop up and passed or failed kind of information –> pop up messages are dynamical and have to call that data from xl sheet and it should appear and disappear. Is there any way like that to show information in pop up, if there how to show all my passed and failed test cases in html page.

  29. Still if you didnt get my case, i need attache my file, where i should attach.. and how to show my excel sheet and also… my code to you sir,

    If possible .. gayatri.satyaganga –> is my skype id , i may can share the screen. if possible ,…

  30. If we can Multiple Thread In Selenium then @Dataprovider [Test NG ] is not work ,Means We can run Multiple thread By using Dynamic sets of data, But its works only for one Thread Not For All Thread, Please Provide Solution for that.

  31. Yes Thanks for Your Suggestion , But My concern Is not That,
    if we have login script Here We can pass data Trough XML , Inside of test we can set @test(invocationcount=2 , Threadpoolsize=2), We can pass our Dynamic Data trough TestNG Xml, Here we want we can Execute Login script with different data sets.

    So Here One Test Is Execute With the parameter provided in XML.
    But we want to run Same test at same time with two different Thread, So how we can pass data trough XML.I Hope now you are getting my Point , Thanks

  32. Test data read from excel

    package com.tos.utilities;
    import org.apache.poi.hssf.usermodel.HSSFCellStyle;
    import org.apache.poi.hssf.usermodel.HSSFDateUtil;
    import org.apache.poi.hssf.util.HSSFColor;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.CellStyle;

    import org.apache.poi.ss.usermodel.IndexedColors;
    import org.apache.poi.xssf.usermodel.*;

    import java.io.*;
    import java.util.Calendar;

    public class ExcelUtil {

    public String path;
    public FileInputStream fis = null;
    public FileOutputStream fileOut =null;
    private XSSFWorkbook workbook = null;
    private XSSFSheet sheet = null;
    private XSSFRow row =null;
    private XSSFCell cell = null;

    public ExcelUtil(String path) {

    this.path=path;
    try {
    fis = new FileInputStream(path);
    workbook = new XSSFWorkbook(fis);
    sheet = workbook.getSheetAt(0);
    fis.close();
    } catch (Exception e) {
    System.out.println(“Xls file not found on path ” +path);
    e.printStackTrace();
    }

    }
    // returns the row count in a sheet
    public int getRowCount(String sheetName){
    int index = workbook.getSheetIndex(sheetName);
    if(index==-1)
    return 0;
    else{
    sheet = workbook.getSheetAt(index);
    int number=sheet.getLastRowNum()+1;
    return number;
    }

    }

    // returns the data from a cell
    public String getCellData(String sheetName,String colName,int rowNum){
    try{
    if(rowNum <=0)
    return "";

    int index = workbook.getSheetIndex(sheetName);
    int col_Num=-1;
    if(index==-1)
    return "";

    sheet = workbook.getSheetAt(index);
    row=sheet.getRow(0);
    for(int i=0;i<row.getLastCellNum();i++){
    //System.out.println(row.getCell(i).getStringCellValue().trim());
    if(row.getCell(i).getStringCellValue().trim().equals(colName.trim()))
    col_Num=i;
    }
    if(col_Num==-1)
    return "";

    sheet = workbook.getSheetAt(index);
    row = sheet.getRow(rowNum-1);
    if(row==null)
    return "";
    cell = row.getCell(col_Num);

    if(cell==null)
    return "";
    //System.out.println(cell.getCellType());
    if(cell.getCellType()==Cell.CELL_TYPE_STRING)
    return cell.getStringCellValue();
    else if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC || cell.getCellType()==Cell.CELL_TYPE_FORMULA ){

    String cellText = String.valueOf(cell.getNumericCellValue());
    if (HSSFDateUtil.isCellDateFormatted(cell)) {
    // format in form of M/D/YY
    double d = cell.getNumericCellValue();

    Calendar cal =Calendar.getInstance();
    cal.setTime(HSSFDateUtil.getJavaDate(d));
    cellText =
    (String.valueOf(cal.get(Calendar.YEAR))).substring(2);
    cellText = cal.get(Calendar.DAY_OF_MONTH) + "/" +
    cal.get(Calendar.MONTH)+1 + "/" +
    cellText;

    //System.out.println(cellText);

    }

    return cellText;
    }else if(cell.getCellType()==Cell.CELL_TYPE_BLANK)
    return "";
    else
    return String.valueOf(cell.getBooleanCellValue());

    }
    catch(Exception e){

    e.printStackTrace();
    return "row "+rowNum+" or column "+colName +" does not exist in xls";
    }
    }

    // returns the data from a cell
    public String getCellData(String sheetName,int colNum,int rowNum){
    try{
    if(rowNum <=0)
    return "";

    int index = workbook.getSheetIndex(sheetName);

    if(index==-1)
    return "";

    sheet = workbook.getSheetAt(index);
    row = sheet.getRow(rowNum-1);
    if(row==null)
    return "";
    cell = row.getCell(colNum);
    if(cell==null)
    return "";

    if(cell.getCellType()==Cell.CELL_TYPE_STRING)
    return cell.getStringCellValue();
    else if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC || cell.getCellType()==Cell.CELL_TYPE_FORMULA ){

    String cellText = String.valueOf(cell.getNumericCellValue());
    if (HSSFDateUtil.isCellDateFormatted(cell)) {
    // format in form of M/D/YY
    double d = cell.getNumericCellValue();

    Calendar cal =Calendar.getInstance();
    cal.setTime(HSSFDateUtil.getJavaDate(d));
    cellText =
    (String.valueOf(cal.get(Calendar.YEAR))).substring(2);
    cellText = cal.get(Calendar.MONTH)+1 + "/" +
    cal.get(Calendar.DAY_OF_MONTH) + "/" +
    cellText;

    // System.out.println(cellText);

    }

    return cellText;
    }else if(cell.getCellType()==Cell.CELL_TYPE_BLANK)
    return "";
    else
    return String.valueOf(cell.getBooleanCellValue());
    }
    catch(Exception e){

    e.printStackTrace();
    return "row "+rowNum+" or column "+colNum +" does not exist in xls";
    }
    }

    // returns true if data is set successfully else false
    public boolean setCellData(String sheetName,String colName,int rowNum, String data){
    try{
    fis = new FileInputStream(path);
    workbook = new XSSFWorkbook(fis);

    if(rowNum<=0)
    return false;

    int index = workbook.getSheetIndex(sheetName);
    int colNum=-1;
    if(index==-1)
    return false;

    sheet = workbook.getSheetAt(index);

    row=sheet.getRow(0);
    for(int i=0;i<row.getLastCellNum();i++){
    //System.out.println(row.getCell(i).getStringCellValue().trim());
    if(row.getCell(i).getStringCellValue().trim().equals(colName))
    colNum=i;
    }
    if(colNum==-1)
    return false;

    sheet.autoSizeColumn(colNum);
    row = sheet.getRow(rowNum-1);
    if (row == null)
    row = sheet.createRow(rowNum-1);

    cell = row.getCell(colNum);
    if (cell == null)
    cell = row.createCell(colNum);

    // cell style
    //CellStyle cs = workbook.createCellStyle();
    //cs.setWrapText(true);
    //cell.setCellStyle(cs);
    cell.setCellValue(data);

    fileOut = new FileOutputStream(path);

    workbook.write(fileOut);

    fileOut.close();

    }
    catch(Exception e){
    e.printStackTrace();
    return false;
    }
    return true;
    }

    // returns true if data is set successfully else false
    public boolean setCellData(String sheetName,String colName,int rowNum, String data,String url){
    //System.out.println("setCellData setCellData******************");
    try{
    fis = new FileInputStream(path);
    workbook = new XSSFWorkbook(fis);

    if(rowNum<=0)
    return false;

    int index = workbook.getSheetIndex(sheetName);
    int colNum=-1;
    if(index==-1)
    return false;

    sheet = workbook.getSheetAt(index);
    //System.out.println("A");
    row=sheet.getRow(0);
    for(int i=0;i<row.getLastCellNum();i++){
    //System.out.println(row.getCell(i).getStringCellValue().trim());
    if(row.getCell(i).getStringCellValue().trim().equalsIgnoreCase(colName))
    colNum=i;
    }

    if(colNum==-1)
    return false;
    sheet.autoSizeColumn(colNum); //ashish
    row = sheet.getRow(rowNum-1);
    if (row == null)
    row = sheet.createRow(rowNum-1);

    cell = row.getCell(colNum);
    if (cell == null)
    cell = row.createCell(colNum);

    cell.setCellValue(data);
    XSSFCreationHelper createHelper = workbook.getCreationHelper();

    //cell style for hyperlinks
    //by default hypelrinks are blue and underlined
    CellStyle hlink_style = workbook.createCellStyle();
    XSSFFont hlink_font = workbook.createFont();
    hlink_font.setUnderline(XSSFFont.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    hlink_style.setFont(hlink_font);
    //hlink_style.setWrapText(true);

    XSSFHyperlink link = createHelper.createHyperlink(XSSFHyperlink.LINK_FILE);
    link.setAddress(url);
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    fileOut = new FileOutputStream(path);
    workbook.write(fileOut);

    fileOut.close();

    }
    catch(Exception e){
    e.printStackTrace();
    return false;
    }
    return true;
    }

    // returns true if sheet is created successfully else false
    public boolean addSheet(String sheetname){

    FileOutputStream fileOut;
    try {
    workbook.createSheet(sheetname);
    fileOut = new FileOutputStream(path);
    workbook.write(fileOut);
    fileOut.close();
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    }
    return true;
    }

    // returns true if sheet is removed successfully else false if sheet does not exist
    public boolean removeSheet(String sheetName){
    int index = workbook.getSheetIndex(sheetName);
    if(index==-1)
    return false;

    FileOutputStream fileOut;
    try {
    workbook.removeSheetAt(index);
    fileOut = new FileOutputStream(path);
    workbook.write(fileOut);
    fileOut.close();
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    }
    return true;
    }
    // returns true if column is created successfully
    public boolean addColumn(String sheetName,String colName){
    //System.out.println("**************addColumn*********************");

    try{
    fis = new FileInputStream(path);
    workbook = new XSSFWorkbook(fis);
    int index = workbook.getSheetIndex(sheetName);
    if(index==-1)
    return false;

    XSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

    sheet=workbook.getSheetAt(index);

    row = sheet.getRow(0);
    if (row == null)
    row = sheet.createRow(0);

    //cell = row.getCell();
    //if (cell == null)
    //System.out.println(row.getLastCellNum());
    if(row.getLastCellNum() == -1)
    cell = row.createCell(0);
    else
    cell = row.createCell(row.getLastCellNum());

    cell.setCellValue(colName);
    cell.setCellStyle(style);

    fileOut = new FileOutputStream(path);
    workbook.write(fileOut);
    fileOut.close();

    }catch(Exception e){
    e.printStackTrace();
    return false;
    }

    return true;

    }
    // removes a column and all the contents
    public boolean removeColumn(String sheetName, int colNum) {
    try{
    if(!isSheetExist(sheetName))
    return false;
    fis = new FileInputStream(path);
    workbook = new XSSFWorkbook(fis);
    sheet=workbook.getSheet(sheetName);
    XSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
    XSSFCreationHelper createHelper = workbook.getCreationHelper();
    style.setFillPattern(HSSFCellStyle.NO_FILL);

    for(int i =0;i<getRowCount(sheetName);i++){
    row=sheet.getRow(i);
    if(row!=null){
    cell=row.getCell(colNum);
    if(cell!=null){
    cell.setCellStyle(style);
    row.removeCell(cell);
    }
    }
    }
    fileOut = new FileOutputStream(path);
    workbook.write(fileOut);
    fileOut.close();
    }
    catch(Exception e){
    e.printStackTrace();
    return false;
    }
    return true;

    }
    // find whether sheets exists
    public boolean isSheetExist(String sheetName){
    int index = workbook.getSheetIndex(sheetName);
    if(index==-1){
    index=workbook.getSheetIndex(sheetName.toUpperCase());
    if(index==-1)
    return false;
    else
    return true;
    }
    else
    return true;
    }

    // returns number of columns in a sheet
    public int getColumnCount(String sheetName){
    // check if sheet exists
    if(!isSheetExist(sheetName))
    return -1;

    sheet = workbook.getSheet(sheetName);
    row = sheet.getRow(0);

    if(row==null)
    return -1;

    return row.getLastCellNum();

    }
    //String sheetName, String testCaseName,String keyword ,String URL,String message
    public boolean addHyperLink(String sheetName,String screenShotColName,String testCaseName,int index,String url,String message){
    //System.out.println("ADDING addHyperLink******************");

    url=url.replace('\\', '/');
    if(!isSheetExist(sheetName))
    return false;

    sheet = workbook.getSheet(sheetName);

    for(int i=2;i<=getRowCount(sheetName);i++){
    if(getCellData(sheetName, 0, i).equalsIgnoreCase(testCaseName)){
    //System.out.println("**caught "+(i+index));
    setCellData(sheetName, screenShotColName, i+index, message,url);
    break;
    }
    }

    return true;
    }
    public int getCellRowNum(String sheetName,String colName,String cellValue){

    for(int i=2;i<=getRowCount(sheetName);i++){
    if(getCellData(sheetName,colName , i).equalsIgnoreCase(cellValue)){
    return i;
    }
    }
    return -1;

    }

    // to run this on stand alone
    public static void main(String arg[]) throws IOException{

    //System.out.println(filename);
    ExcelUtil datatable = null;

    datatable = new ExcelUtil("H:\\Student_Selenium_Workspaces\\Framework_Weekend\\src\\Framework_XL_Files\\Controller.xlsx");
    for(int col=0 ;col< datatable.getColumnCount("TC5"); col++){
    System.out.println(datatable.getCellData("TC5", col, 1));
    }
    }

    }

  33. // To launch driver and report generation

    package com.tos.driver;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.firefox.internal.ProfilesIni;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;

    public class driver {

    /* Initialize webdriver */
    public void launchBrowser(String browser) {

    if (browser.equalsIgnoreCase(“FF”)) {

    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile myprofile = profile.getProfile(“default”);
    WebDriver driver = new FirefoxDriver(myprofile);
    driver.manage().window().maximize();

    } else if (browser.equalsIgnoreCase(“IE”)) {

    System.setProperty(“webdriver.ie.driver”,
    “C:\\Users\\sunil.wali\\Desktop\\Framework\\DM\\resources\\IEDriverServer.exe”);
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    WebDriver driver = new InternetExplorerDriver(capabilities);

    driver.manage().window().maximize();
    }

    else if (browser.equalsIgnoreCase(“Chrome”)) {

    System.setProperty(“webdriver.chrome.driver”,
    “C:\\Users\\sunil.wali\\Desktop\\Framework\\DM\\resources\\chromedriver.exe”);
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    }

    }

    // Static HTML Reporting Methods

    public static PrintStream reporter = null;
    public static DateFormat dateFormat;
    public static Calendar cal;
    public static String currenTimeStamp;

    public void reportSetup() {
    if (reporter == null) {
    File targetFile = null;
    Calendar currentDate = Calendar.getInstance();
    SimpleDateFormat displayFormat = new SimpleDateFormat(“MM_dd_yyyy_HH_mm_ss”);
    SimpleDateFormat parseFormat = new SimpleDateFormat(“MM_dd_yyyy_HH_mm_ss” + ” a”);
    Date date = null;
    try {
    date = parseFormat.parse(parseFormat.format(currentDate.getTime()));
    } catch (ParseException ex) {
    }
    currenTimeStamp = displayFormat.format(date);
    // Create a TestResults folder in path directory if not exist
    String destPath = System.getProperty(“user.dir”) + “\\” + “TestResults”;
    targetFile = new File(destPath);
    if (!targetFile.exists()) {
    targetFile.mkdir();
    }
    // Copy the ResultsFolder from the resource in to result folder
    // Rename the folder
    // Copy the path of result folder
    // Create a print handle to the result summary
    String srcResultfolder = System.getProperty(“user.dir”) + “\\Resources\\ResultsFolder”;
    File destinationLocation = new File(destPath);
    File sourceLocation = new File(srcResultfolder);
    try {
    copyFolder(sourceLocation, destinationLocation);
    }

    catch (IOException e) {
    }
    String destResultPath = destPath + “\\ResultSummary”;
    String resultSummaryFolderPath = System.getProperty(“user.dir”) + “\\” + “TestResults\\ProjectName_Result_”
    + currenTimeStamp;
    // Change Project name
    // Rename the dirctory
    File file = new File(destResultPath);
    File newFilePath = new File(resultSummaryFolderPath);
    file.renameTo(newFilePath);
    String resultSummaryFilePath = resultSummaryFolderPath + “\\Index.html”;
    // Create a handle to dump the results
    try {
    reporter = new PrintStream(new FileOutputStream(resultSummaryFilePath, true), true);
    } catch (FileNotFoundException e) {
    System.out.println(“”);
    }
    }
    }

    public static void copyFolder(File src, File dest) throws IOException {
    if (src.isDirectory()) {
    // if directory not exists, create it
    if (!dest.exists()) {
    dest.mkdir();
    }
    // list all the directory contents
    String files[] = src.list();
    for (String file : files) {
    // construct the src and dest file
    // structure
    File srcFile = new File(src, file);
    File destFile = new File(dest, file);
    // recursive copy
    copyFolder(srcFile, destFile);
    }
    } else {
    // if file, then copy it
    // Use bytes stream to support all file types
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dest);
    byte[] buffer = new byte[1024];
    int length;
    // copy the file content in bytes
    while ((length = in.read(buffer)) > 0) {
    out.write(buffer, 0, length);
    }
    in.close();
    out.close();
    }

    }

    }

  34. Hi Bas,

    This is really nice reporting and I was able to add many Such Columns in HTML.
    Can you help me in Getting the Start and End time or Executim time on the header of the report what Test Report is printed?

    Thanks in Advance

  35. hi,
    I’m trying to call ur project through a jsp (via servlet) . but it gives this error.
    exception

    javax.servlet.ServletException: Servlet execution threw an exception

    root cause

    java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
    com.ontestautomation.selenium.reporting.Myak.doPost(Myak.java:41)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

    root cause

    java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    com.ontestautomation.selenium.reporting.Myak.doPost(Myak.java:41)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.
    what should i do now?

    • Hey Achindra,

      I’m sorry, but I don’t have any expertise with what you’re trying to achieve, so I think you’re better off asking this on a site such as StackOverflow. Good luck!

      — Bas

  36. Hi All,

    While testing I did not provide any value to a particular field in a form. However on executing it the extent reports which is appearing is showing it as passed. Why is it happening? Please provide me a solution

  37. Hi, thanks for the post. I used the code and it seems to work fine.

    My question to you is :

    Can we possibly use this to check test cases like

    click on a button/link
    loading of page

    If yes, how would we do it? Thanks.

    • Hey Saili,

      thanks, glad you liked it. As you might have seen at the top of the post, there’s also something called ExtentReports, which makes it even easier to create reports that look great.

      To answer your question: sure! Checking whether a link exists, or whether a page has fully load is just another assertion (a check with a boolean outcome, true or false) you can do. This means you can report the result of this check just like any other.

  38. Hey Bas,

    Excellent blog, Tons of information i found here which i have been searching for weeks… Thank for it..

    I just need a simple clarification.. Is ExtentReports is an Opensource or it’s paid one.

    • As of version 3, both, actually. There’s a free version (Community Edition) as well as a paid one (Pro). See here for license details and here for a comparison between both licenses.

      Version 2 (still available, no longer supported) is free.

  39. Hi Bas,

    Really liked your approach to generate the HTML reports.

    I’m a newbie to automation & would like to get my hands dirty by trying to generate reports on my own instead of using Extent Reports.

    As per my understanding your approach generates reports on page level, what I would like to do is to generate a summary HTML report of all the test cases that were run & when individual test cases are clicked, the detailed HTML report similar to what you have explained above must be generated.

    Could you please suggest me ways by which I can achieve this?

  40. Hi Bas,
    Thanks for the custom HTML report.
    I need to generate the same report with multiple test cases that are in same class or different classes.

Leave a Reply to Chenna Cancel reply

Your email address will not be published. Required fields are marked *