java - Scenario.embed 错误:无法解析“场景”中的“嵌入”方法
问题描述
我有一个黄瓜项目。如果我想截屏,我想使用以下方法嵌入它。
scenario.embed(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES), "image/png");
但是我得到一个错误embed
-Cannot resolve method 'embed' in 'Scenario'
我的钩子文件的一部分
@After
public void teardownAndScreenshotOnFailure(Scenario scenario){
try {
if(driver != null && scenario.isFailed())
{
scenario.embed(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES), "image/png");
}
if(driver != null)
{
driver.manage().deleteAllCookies();
driver.quit();
driver = null;
}
....
我已经导入了以下内容:
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
我在我的 POM.xml 中使用最新版本的黄瓜:6.9.1
解决方案
根据 6.9.1 的 Java 文档。您可以使用 attach() 方法。
embed()方法已被弃用,并已从 6.0文档中删除。
public void attach(byte[] data, String mediaType, String name)
Attach data to the report(s).
// Attach a screenshot. See your UI automation tool's docs for
// details about how to take a screenshot.
scenario.attach(pngBytes, "image/png", "Bartholomew and the Bytes of the Oobleck");
To ensure reporting tools can understand what the data is a mediaType must be provided. For example: text/plain, image/png, text/html;charset=utf-8.
Parameters:
data - what to attach, for example an image.
mediaType - what is the data?
name - attachment name
推荐阅读
- r - 如何根据时间顺序重新排列数据框中的行
- javascript - 粘性导航栏的响应取决于滚动
- c++ - 以人类可读的形式在 QSettings 中保存自定义 QMap 模板实例化
- php - 为每个商家分配一个用于在线库存系统的数据库是否很好?
- android - How get time server in firebase by kotlin
- c - 有编译的命令吗?
- jquery - 使用 jquery 将活动类动态添加到菜单及其子菜单
- java - Add focus event on an element in a graph with jgraphx
- amazon-web-services - Amazon Lex with Lambda function - error 424 Failed Dependency (Python)
- c++ - 匹配/不在引号之间,带有可转义的引号和多行