宁静报告中的黄瓜 "Doc Strings"

Cucumber "Doc Strings" in Serenity Reports

我们正在考虑以获取Living Documentation的方式在Cucumber中进行一些测试,"Living documentation"的关键是在"Then"中我们要使用"Doc Strings" (Json 个字符串)。

但是,我们意识到 "Doc Strings" 没有显示在 Serenity 报告中。

是否有可能在 Serenity 报告中显示 "Doc Strings"?

谢谢!

其实是可以的。我创建了一个示例 Git 项目,展示了如何使用 Serenity BDD 的 StepEventBus API 将自定义消息添加到 Serenity 测试报告。

包含更多解释的完整代码可在以下位置找到:https://github.com/datentyp/whosebug.com-questions-47492400-cucumber-doc-strings-in-serenity-reports

public class TestSteps implements En {

public TestSteps() {
    Given("some scenario", () -> { /* implement me! */});
    When("some step contains some doc string", () -> { /* implement me! */});
    /* implement me */
    Then("the content of that doc string should be included in the Serenity test report", this::showStepMessage);
}

public void showStepMessage(String message) {
    // TODO: escape message string for use in HTML
    String escapedMessage = StringUtils.replace(message, " ", " ");

    StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(escapedMessage));
    StepEventBus.getEventBus().stepFinished();
}

}

但请注意,如果您真的想将一些 JSON 文档字符串附加到您的 Then 步骤,那么我认为您可能一开始就尝试做错事。

您可以使用 serenity-rest-assured 捕获通过网络发送的实际 HTTP request/response。这样,您的报告将不仅包括预期的 JSON 负载,还包括请求和响应的 HTTP headers 和负载。

如果您对此感兴趣,请查看文档:http://thucydides.info/docs/serenity-staging/#_testing_rest_with_serenity_bdd