• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Java Program
  • Selenium
  • Selenium Programs
  • Manual Testing
  • Difference
  • Tools
  • SQL
  • Contact Us
  • Search
SoftwareTestingo » Selenium » Selenium Programs » How to Capture Screenshot Different Name Using TestNg?

How to Capture Screenshot Different Name Using TestNg?

Last Updated on: April 13, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • Capture Screenshot Different Name

Capture Screenshot Different Name

How to Capture Screenshot Different Name Using TestNG?

package com.selenium.basics;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CaptureScreenshotWithDifferentName 
{
   static WebDriver driver;
   public static void main(String[] args) throws InterruptedException, IOException
   {
      CaptureScreenshotWithDifferentName obj=new CaptureScreenshotWithDifferentName();
      driver=new FirefoxDriver();
      driver.get("http://www.softwaretestingblog.in");
      Thread.sleep(3000);
      obj.getScreenShots("manoj");
      driver.close();
   }
   public void getScreenShots(String abc) throws IOException 
   {
      TakesScreenshot ts=(TakesScreenshot)driver;
      File src=ts.getScreenshotAs(OutputType.FILE);
      FileUtils.copyFile(src, new File("G:\\Base_Workspace\\Luna\\Selenium\\Screenshots\\SC" + abc+getTimeStamp() + ".png")); //Files are Stored in G:\Base_Workspace\Luna\Selenium\Screenshots
   }
   public String getTimeStamp() 
   {
      String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
      return timestamp;
   }
}

Read Also: Create Log Details in Java Selenium

    Filed Under: Selenium Programs

    Reader Interactions

    Leave a Reply Cancel reply

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

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers