Saturday, June 28, 2025

JMeter + Webdriver : Java code just isn’t taking screenshot and it’s giving ERROR c.g.j.p.w.s.WebDriverSampler: Sourced file: inline analysis of:


I’m new to JMeter + WebDriver + Java. JavaScript code is working as anticipated for screenshot. Attributable to current improve of Java, we’re transferring from JavaScript to Java.

Beneath is the code. Are you able to please assist with it?

import org.openqa.selenium.By;
import org.openqa.selenium.assist.occasions.EventFiringWebDriver;
import org.openqa.selenium.assist.ui;
import java.io.File;
import org.apache.commons.io.FileUtils;
import Java.awt.Robotic;
import java.awt.picture.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("/Customers/****/desktop/screenshot.png");
        attempt{
            FileUtils.copyFile(srcFile, destFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

WDS.sampleResult.sampleEnd();

Additionally I attempted beneath code

 File mFile = ((TakesScreenshot)WDS.browser).getScreenshotAs(OutputType.FILE);
 FileUtils.copyFile(mFile, new File("output/" + WDS.identify + "-" + WDS.parameters + ".png"));

Error message:

2022-05-03 11:28:51,641 ERROR c.g.j.p.w.s.WebDriverSampler: Sourced file: inline analysis of: ``import org.openqa.selenium.By; import org.openqa.selenium.assist.occasions.EventFi . . . '' : Typed variable declaration : Class: TakesScreenshot not present in namespace : at Line: 14 : in file: inline analysis of: ``import org.openqa.selenium.By; 
import org.openqa.selenium.assist.occasions.EventFi . . . '' : TakesScreenshot in inline analysis of: ``import org.openqa.selenium.By; 
import org.openqa.selenium.assist.occasions.EventFi . . . '' at line quantity 14

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com