anshooarora / extentreports-java

Community version of Extent API for Java has moved to https://github.com/extent-framework/
http://extentreports.com
Other
528 stars 318 forks source link

When appending to extent reports, the date/time is showing incorrectly #783

Closed mandarin77 closed 7 years ago

mandarin77 commented 7 years ago

When appending to extent reports, the date/time is showing incorrectly. I am able to get the correct date/time in the most recent test run, but as a new test run comes in and appends to the report, the date/time for example will change from 2-26-2017 to 08-09-0006.

image

image

image

image

Here is a snippet of the code

package TEST; import java.util.concurrent.TimeUnit; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.RandomStringUtils; import org.ini4j.Config; import org.junit.; import static org.junit.Assert.; import org.openqa.selenium.; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.ie.; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.Reporter; import org.testng.annotations.; import org.testng.annotations.BeforeClass; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import java.lang.String; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus; import com.thoughtworks.selenium.webdriven.commands.Click; import Utility.MKTConfigReader; import Utility.MKTExtentManager; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.Properties; import java.util.Random; import org.seleniumhq.jetty7.util.log.Log; import java.util.UUID; import commonfunctions.; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class TEST {

  ExtentReports extent;
  ExtentTest test;
  String sRandStr = RandomStringUtils.randomAlphabetic(5);
  String timeStamp = new SimpleDateFormat("MMddyyyy_HHmmss").format(Calendar.getInstance().getTime());

  //private WebDriver driver;
  private RemoteWebDriver driver;
  private StringBuffer verificationErrors = new StringBuffer();

  @BeforeClass
  public void setUp() throws Exception {

  //Sets Extent reporting instance  
  extent = MKTExtentManager.Instance();

  //Sets path to configreader object repository
  MKTConfigReader config=new MKTConfigReader();       

  //Chrome
   System.setProperty("webdriver.chrome.driver", config.getChromeDriver());
   driver = new ChromeDriver();

 //Sets timeout at 30 seconds  
   driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

 }

  @Test

  public void TEST() throws Exception {

  //Sets Extent reporting instance  
  //extent = MKTExtentManager.Instance();

  //Sets path to configreader object repository
    MKTConfigReader config=new MKTConfigReader();     

  //Names the test case in report results
    test = extent.startTest("Apply Online Graduate New Lead " + timeStamp);

  //Test case begins

  //Open website
  test.log(LogStatus.INFO, "Open Website");
  driver.get(config.getUrlTest());
  test.log(LogStatus.PASS, "Open website passed"); 

  //MAXIMIZE WINDOW
    Thread.sleep(1000);
    driver.manage().window().maximize();
    Thread.sleep(1000);

    //FOCUS BACK ON WINDOW TO IGNORE POPUP
    Thread.sleep(3000);
    for (String handle : driver.getWindowHandles()) {
        driver.switchTo().window(handle);
    }

    Thread.sleep(3000);

//Click LINK
test.log(LogStatus.INFO, "Click button");
driver.findElement(By.xpath("/html/body/div[1]/form/div[5]/div/div[2]/div[1]/dl/dt[3]/h2/a")).click();
test.log(LogStatus.PASS, "Click button passed");

}

//NEW @AfterMethod //Captures test execution information to pass through in next step public void getResult(ITestResult result) throws IOException { //Captures screenshot from failed test case and inserts into test result report if(result.getStatus()==ITestResult.FAILURE) {

String screenshotPath = GetScreenshot.capture(driver, result.getMethod().getMethodName() + "_" + "failure"+sRandStr); test.log(LogStatus.FAIL, result.getThrowable()); test.log(LogStatus.FAIL, "screenshot below: " + test.addScreenCapture(screenshotPath)); } }

@AfterClass

public void tearDown() throws Exception {

{ //Closes out QA test execution reporting for test case
extent.endTest(test); extent.flush(); extent.close(); driver.quit(); }

//Closes browser //driver.quit();

String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } }

mandarin77 commented 7 years ago

Here is my extent class and xml config as well:

package Utility;

import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;

import com.relevantcodes.extentreports.DisplayOrder; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.IExtentTestClass; import com.relevantcodes.extentreports.LogStatus;

import java.util.concurrent.TimeUnit; import java.io.File; import java.io.IOException; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat;

import org.apache.commons.io.FileUtils; import org.ini4j.Config; import org.junit.; import static org.junit.Assert.; import org.openqa.selenium.; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.ie.; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.safari.SafariDriver; import org.testng.Reporter; import org.testng.annotations.*; import org.testng.annotations.BeforeClass; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.thoughtworks.selenium.webdriven.commands.Click; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Date; import java.util.Properties; import Utility.MKTConfigReader; import commonfunctions.GetDateinJava;

public class MKTExtentManager {

@SuppressWarnings("deprecation") public static ExtentReports Instance() {

ExtentReports extent; String Path = "./Reports/Report.html"; System.out.println(Path); extent = new ExtentReports(Path, false);

extent.loadConfig(new File("./extent-config.xml")); return extent; } public static String CaptureScreen(WebDriver driver, String ImagesPath) { TakesScreenshot oScn = (TakesScreenshot) driver; File oScnShot = oScn.getScreenshotAs(OutputType.FILE); File oDest = new File(ImagesPath+".png"); try { FileUtils.copyFile(oScnShot, oDest); } catch (IOException e) {System.out.println(e.getMessage());} return ImagesPath+".png"; } }


here is the xml config:

<?xml version="1.0" encoding="UTF-8"?>

UTF-8 Custom ]]> Nightly Automation Test Results MM-dd-yyyy HH:mm:ss img { float: left;height: 90%;margin-left: 30px;margin-top: 2px;width: auto; } ]]>
anshooarora commented 7 years ago

Thanks. This is fixed now.

See #815.

https://github.com/anshooarora/extentreports-java/commit/fd879337d1fbd3d07c352fc12f852eeb0ba5125c

mandarin77 commented 7 years ago

Thanks Anshoo. I will try the fix and let you know.

All the best,

Darin

On Mar 23, 2017, at 4:26 PM, Anshoo Arora notifications@github.com wrote:

Thanks. This is fixed now.

See #815.

fd87933

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

dwelsh1 commented 7 years ago

Hello Anshoo,

Is this fixed in the latest Java 2.41.2 version. If I have the global date format override set to MM-dd-yyyy the dates are messed up. If I set it to the default of yyyy-MM-dd then the dates are correct.

I also see a problem on the dashboard. I ran 3 tests that took about 33 seconds to run all 3. The Dashboard Total Time Taken (Current Run) shows: 0h 5m 39s+214ms and Total Time Taken (Overall) shows: 0h 1m 72s+206ms. Quite a bit longer than 33 seconds.

Another thing I noticed is that in my pom file I have version 2.41.2 but on the report in the top corner it says: v2.41.1.

Note: I do have DisplayOrder.NEWEST_FIRST set.

Thanks, Don