Java.io.FileNotFoundException: With Screenshoot and ExtentRe | Selenium Forum
M
Posted on 22/12/2016
Hi, I am trying to add a screenshot in my test to the ExtentReports and went I do it is giving a java.io.FileNotFoundException:

My method is

public void takeScreenShoot() throws IOException {
Date d=new Date();
String screenshotFile=d.toString().replace(":", "_").replace(" ", "_")+".png";
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"//screenshots//"+screenshotFile ));

} catch (IOException e) {
e.printStackTrace();
}

test.log(LogStatus.INFO,"Screenshoot " + test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile ));
}


And my class that i am extend is

public class DummyTestB extends BaseTest{
private static Properties prop = BaseTest.getProperties();
private static ExtentReports screenshotFile;
private static ExtentReports rep = ExtentManager.getInstance();
private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(DummyTestB.class.getName());

ExtentTest test;

@Test
public void testB1() throws IOException{

test = rep.startTest("Dummy TestB");
test.log(LogStatus.INFO, "Starting the test");


openBrowser("browser");
//SSLCertificateHandle("browser");
log.debug("urlKey");
log.info("urlKey world");
test.log(LogStatus.INFO, "Open the browser ");
//test.log(LogStatus.FAIL, "Screenshot the test" + test.addScreenCapture(System.getProperty("user.dir")+"/screenshots/photo.png"));


url("url");


test.log(LogStatus.INFO, "input the url");

test.log(LogStatus.INFO, "input the email");

test.log(LogStatus.INFO, "click the button");
takeScreenShoot();
quit("appurl");
}
@AfterTest
public void testB2() throws IOException{

rep.endTest(test);
rep.flush();

}

Can someone help thanks

M
Replied on 22/12/2016

which line is [color=#FF0000:32ndj8xm]java.io.FileNotFoundException:[/color:32ndj8xm] this error coming on? send a full stack trace.


M
Replied on 28/12/2016

[quote="qtpselenium.supp0rt@gmail.com":2c4rr7s0]which line is [color=#FF0000:2c4rr7s0]java.io.FileNotFoundException:[/color:2c4rr7s0] this error coming on? send a full stack trace.[/quote:2c4rr7s0]

test.log(LogStatus.INFO,"Screenshoot " + test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile ));
}


M
Replied on 28/12/2016

java is not able to find screenshot file at this location.

System.getProperty("user.dir")+"//screenshots//"+screenshotFile

please check by debugging eclipse that is screenshot is present at that location or not.


M
Replied on 29/12/2016

[quote="qtpselenium.supp0rt@gmail.com":1m81mzlf]java is not able to find screenshot file at this location.

System.getProperty("user.dir")+"//screenshots//"+screenshotFile

please check by debugging eclipse that is screenshot is present at that location or not.[/quote:1m81mzlf]

Yes there is a folder and screenshots are creating a this point.


M
Replied on 29/12/2016

come on skype right now. qtpselenium1


M
Replied on 13/09/2018

Hi, I am also facing the same error, How did you solve it? Please help..


M
Replied on 14/09/2018

This happens when path to screenshot is not correct
Please correct path