我有一个黄瓜项目。如果我想截取屏幕截图,我想使用以下命令将其嵌入。
scenario.embed(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES), "image/png");但是我收到错误embed-Cannot resolve method 'embed' in 'Scenario'
我的 hooks 文件的一部分
@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;
}
....
Run Code Online (Sandbox Code Playgroud)
我导入了以下内容:
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;
Run Code Online (Sandbox Code Playgroud)
我在 POM.xml 中使用最新版本的黄瓜:6.9.1
根据 6.9.1 的 Java 文档。您可以使用 Attach() 方法。
\nembed()方法已弃用,并从 6.0文档中删除。
\npublic void attach\xe2\x80\x8b(byte[] data, String mediaType, String name)\nAttach data to the report(s).\n \n // Attach a screenshot. See your UI automation tool\'s docs for\n // details about how to take a screenshot.\n scenario.attach(pngBytes, "image/png", "Bartholomew and the Bytes of the Oobleck");\n \n \nTo 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.\n\n\n\nParameters:\ndata - what to attach, for example an image.\nmediaType - what is the data?\nname - attachment name\nRun Code Online (Sandbox Code Playgroud)\n