top of page

Reports

 

1 Download the jars from:      

 

 http://extentreports.com/community/

2 Add the jars to project

3 Code

import java.util.concurrent.TimeUnit;

 

import org.junit.After;

import org.junit.AfterClass;

import org.junit.BeforeClass;

import org.junit.Test;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;

 

import static org.junit.Assert.assertEquals;

 

import java.io.File;

import java.io.IOException;

 

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.OutputType;

 

public class added_or_remove {

 

static WebDriver driver;

static ExtentReports extent;

static ExtentTest test;

static File scrFile;

static File destFile;

public static String takeSS()
    {
        String SSpath = null;
        try
        {
            Date date = new Date();
            SimpleDateFormat sdf=new SimpleDateFormat("ddMMyyyy_HHmmss");
            String ds=sdf.format(date);
            SSpath= ReportImagePath + ds +".png" ;
            File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(scrFile, new File(SSpath));
            System.out.println(SSpath);
        }
        catch(Exception e)
        { 
            System.out.println(e);
        }  
        return SSpath;
    }

/// *********************** Location of  screenshot   ******************

static String path = "/Users/izik/Downloads/Selenium/temp.png";; 

 

@BeforeClass

public static void open_browser()

{

System.out.println("Open Chrome");

System.setProperty("webdriver.chrome.driver","/Users/izik/Downloads/Selenium/chromedriver");

 

/// *********************** ExtentReports -  new instance   ***********************

extent= new ExtentReports("/Users/izik/Downloads/Selenium/temp.html",false);

driver = new ChromeDriver();

driver.get("http://yoniflenner.net/Xamples/ex_synchronization.html");

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

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

 

// ***********************   TakesScreenshot  ***********************

scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

destFile = new File(path);

 

}

 

@AfterClass

public static void close_browser()

{

driver.quit();

// **************     Writing to document  ***********************

extent.flush(); 

}

 

 

@Test

public void a_test() throws Exception 

{

try{

test=extent.startTest("add_or");

Thread.sleep(3000);

LogStatus status = test.getRunStatus();

assertEquals("12", "13");

test.log(LogStatus.PASS, "ghhhj");

FileUtils.copyFile(scrFile, destFile);

 

// **************     Start log  ***********************

test.log(LogStatus.PASS, "pass! " + test.addScreenCapture(path));

 

}

catch(Exception ie)

{

test.addScreenCapture(path);

    test.log(LogStatus.FAIL, ie);

    System.out.println("failr"+ ie);

   

try {

FileUtils.copyFile(scrFile, destFile);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// **************     Send log Status  **********************

test.log(LogStatus.FAIL, "fail! " + test.addScreenCapture(path));

}

catch(AssertionError ie)

{

test.addScreenCapture(path);

    test.log(LogStatus.FAIL, ie);

    System.out.println("failr"+ ie);

   

Thread.sleep(3000);

FileUtils.copyFile(scrFile, destFile);

// **************     Send log Status  **********************

test.log(LogStatus.FAIL, "fail! " + test.addScreenCapture(path));

}

}

 

 

@After

public void test()

// **************     End log  ***********************

extent.endTest(test); 

}

 

}

Selenium - izselenium aoutomation tool

054-8059589

  • White Facebook Icon
  • White Twitter Icon
  • White Google+ Icon
  • White YouTube Icon

© 2017 by izselenium

bottom of page