首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JMeter + Webdriver : Java代码没有截图,它给出了错误c.g.j.p.w.s.WebDriverSampler: Sourced :内联评估:

JMeter + Webdriver : Java代码没有截图,它给出了错误c.g.j.p.w.s.WebDriverSampler: Sourced :内联评估:
EN

Stack Exchange QA用户
提问于 2022-05-03 15:34:59
回答 1查看 668关注 0票数 0

我是JMeter + WebDriver + Java的新手。JavaScript代码正在像预期的那样用于屏幕截图。由于最近对Java的升级,我们正在从JavaScript转向Java。

下面是密码。你能帮忙吗?

代码语言:javascript
复制
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();

另外,我尝试了下面的代码

代码语言:javascript
复制
 File mFile = ((TakesScreenshot)WDS.browser).getScreenshotAs(OutputType.FILE);
 FileUtils.copyFile(mFile, new File("output/" + WDS.name + "-" + WDS.parameters + ".png"));

错误消息:

代码语言:javascript
复制
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
EN

回答 1

Stack Exchange QA用户

发布于 2022-05-03 15:58:11

此错误是由于缺少导入 of TakesScreenshot类造成的。

您需要添加下一行:

代码语言:javascript
复制
import org.openqa.selenium.TakesScreenshot

你剧本的开头。

另外,关于“从js迁移到Java",您要移动的地方不是"Java",而是贝贝解释器,它与Java不完全兼容。而且,使用Beanshell是某种形式的性能反模式.,所以也许“我们”应该考虑改用Groovy。

票数 0
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/50059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档