Skip to content

attach only works for first scenario in outline when using HTML formatter #79

Closed
@rolengrays

Description

@rolengrays

Describe the bug

When outputting HTML report with Scenario Template, Scenario::attach only works for the first scenario in a Scenario Outline.

To Reproduce

  1. Create a test case as follows:
Feature: attach data to HTML report
  Scenario Template: test
    Then store '<val>'
  Examples:
    | val |
    | foo |
    | bar |
package org.example;

import io.cucumber.java.After;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Then;

public class StepDefinitions {
  private String text;

  @Then("store {string}")
  public void store(String t) {
    this.text = t;
  }

  @After
  public void attach(Scenario s) {
    String line = s.getLine().toString();
    s.attach("val: " + this.text, "text/plain", line);
    System.out.println(this.text + " attached");
    this.text = "";
  }
}
package org.example;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"html:target/report.html"})
public class RunCucumberTest {
}
  1. Run mvn test
  2. Both foo attached and bar attached are displayed on my console, but target/report.html only shows val: foo.
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Running org.example.RunCucumberTest
foo attached
bar attached

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.642 sec
...

Expected behavior

target/report.html shows both val: foo and val: bar.

Context & Motivation

For example, When some tests fails, we can get addtional information for each test that has parameters from HTML report. These are helpful for debugging.

Screenshots

Cucumber - Google Chrome 2020_09_27 23_25_36

Environment

  • Cucumber Version: 6.7.0
  • OS: Windows 10 1909
  • Runtime: OpenJDK 14.0.2
  • Build tool: Apache Maven 3.6.3
  • Browser: Google Chrome 85.0.4183.121

Additional context

It seems that val: bar is found in window.CUCUMBER_MESSAGES but not renderd.

$ grep -o -E "val:\s(foo|bar)" target/report.html
val: foo
val: bar

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions