首页 > 解决方案 > 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

我不知道为什么我会遇到这个问题,我试过降级我的黄瓜,谷歌错误但 shomehow 嵌入不起作用。嵌入错误

标签: javacucumber

解决方案


根据 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

推荐阅读