首页 > 解决方案 > 如何使用 Selenium Hub、Node 和 Remote Webdriver 捕获图像并将它们附加到 Cucumber Reports (Jenkins)?

问题描述

目前我正在使用 Ubuntu 实例在云中触发我的自动化测试。

Ubuntu 实例有一个 Jenkins 实例正在运行,还有 Selenium Hub 和 Node。似乎截图图像没有保存在 ubuntu 系统上的 builds\3\cucumber-html-reports\embeddings 中,但是在 Windows 系统上这个问题不存在。

我目前添加了以下逻辑来捕获图像并将其附加到 Jenkins Cucumber 报告中,但是目前图像没有附加到报告中:

@After
public void after(Scenario scenario) {
    if (scenario.isFailed()) {
        try {
            WebDriver augmentedDriver = new Augmenter().augment(getDriver());
            byte[] s = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.BYTES);
            scenario.embed(s, "image/png");

示例报告(在 Jenkins 中生成),请注意,在本地运行测试时,图像会被保存并附加到报告中。 在此处输入图像描述

标签: javaseleniumjenkinsselenium-webdrivercucumber

解决方案


我没有直接回答 ubuntu 问题。但是,尝试将捕获图像的路径作为 html 链接添加到您的黄瓜报告中。

@After
public void after(Scenario scenario){
   if (scenario.isFailed()) {
        try {
            WebDriver augmentedDriver = new Augmenter().augment(getDriver());
            File path = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(path,new File(localRepoPath));
            String html = "<html><body><a href=\">" + localRepoPath + "\"> screenshot </a></body></html>";
            scenario.embed(html.getBytes(), "text/html");
       }catch(Exception e){
          // Do Something
       }
  }        
}

推荐阅读