I am new to JMeter + WebDriver + Java. JavaScript code is working as expected for screenshot. Due to recent upgrade of Java, we are moving from JavaScript to Java.
Below is the code. Can you please help with it?
import org.openqa.selenium.By;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.ui;
import java.io.File;
import org.apache.commons.io.FileUtils;
import Java.awt.Robot;
import java.awt.image.BufferedImage;
WDS.sampleResult.sampleStart();
WDS.browser.get(“https://www.google.com/”);
Thread.sleep(10);
TakesScreenshot ts = (TakesScreenshot)WDS.browser;
File srcFile = ts.getScreenshotAs(OutputType.FILE);
File destFile = new File(“/Users/****/desktop/screenshot.png”);
try{
FileUtils.copyFile(srcFile, destFile);
} catch (IOException e) {
e.printStackTrace();
}
WDS.sampleResult.sampleEnd();
Also I tried below code
File mFile = ((TakesScreenshot)WDS.browser).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(mFile, new File(“output/” + WDS.name + “-” + WDS.parameters + “.png”));
Error message:
2022-05-03 11:28:51,641 ERROR c.g.j.p.w.s.WebDriverSampler: Sourced file: inline evaluation of: “import org.openqa.selenium.By; import org.openqa.selenium.support.events.EventFi . . . ” : Typed variable declaration : Class: TakesScreenshot not found in namespace : at Line: 14 : in file: inline evaluation of: “import org.openqa.selenium.By;
import org.openqa.selenium.support.events.EventFi . . . ” : TakesScreenshot in inline evaluation of: “import org.openqa.selenium.By;
import org.openqa.selenium.support.events.EventFi . . . ” at line number 14