Thursday, 24 November 2022

TestNG Project take screenschot test_case selenium project

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.annotations.Test;

import java.io.File;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class Take_Screenschot extends Load_Test {


LocalDateTime dt = LocalDateTime.now();
DateTimeFormatter dt_format = DateTimeFormatter.ofPattern("dd-MM-yy HH:mm:ss");
String time_now = dt.format(dt_format);



@Test
public void test_screenschot(){
System.out.println("Time Now: "+time_now);
ExtentTest test = extent.createTest("Takeing Schreenschot.");

try{
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String path = "target/Spark/homePageScreenshot.png"+time_now;
FileUtils.copyFile(screenshot, new File("target/Spark/homePageScreenshot.png"));
test.log(Status.INFO, "target/Spark/homePageScreenshot.png");
extent.flush();
}
catch (Throwable t){
System.out.println("Exceptions: "+t);
}
}

}

--
With Warm REGARDS,

En. S. WANKHEDE

No comments:

Post a Comment

Welcome, happy learning

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...