Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cucumber放心:如何将请求信息放入HTML报告中_Cucumber_Rest Assured_Cucumber Java - Fatal编程技术网

Cucumber放心:如何将请求信息放入HTML报告中

Cucumber放心:如何将请求信息放入HTML报告中,cucumber,rest-assured,cucumber-java,Cucumber,Rest Assured,Cucumber Java,我想在我的HTML报告中显示我的请求和响应详细信息 功能文件示例: Feature: Rest Assured under Cucumber POC Scenario: Azure Login Scenario Given Request specifications are set with base uri "https://login.microsoftonline.com/" When Azure Login Request Executed Then Ve

我想在我的HTML报告中显示我的请求和响应详细信息

功能文件示例:

Feature: Rest Assured under Cucumber POC

  Scenario: Azure Login Scenario
    Given Request specifications are set with base uri "https://login.microsoftonline.com/"
    When Azure Login Request Executed
    Then Verify Status Code is 200
跑步者级别为:

@RunWith(Cucumber.class)

@CucumberOptions(
        features = "src/main/resources/features",
        glue = {""},
        tags = "@tests",
        plugin = {      "pretty",
                        "json:target/cucumber-reports/Cucumber.json",
                        "html:target/cucumber-reports"}//reporting plugin
)
public class CucumberRunner {}
这些步骤是:

@Given("Request specifications are set with base uri {string}")
public void setRequestsSpec(String baseUri){

    RequestSpecification spec = new RequestSpecBuilder()
            .setBaseUri(baseUri)
            .addFilter(new ResponseLoggingFilter())//log request and response for better debugging. You can also only log if a requests fails.
            .addFilter(new RequestLoggingFilter())
            .build();

    testContext().setRequestSpec(spec);
}

@When("^Azure Login Request Executed$")
public void azureLoginExecuted() {

    response =
    given()  //Add x-www-form-urlencoded body params:
        .formParam(GRANT_TYPE_KEY, GRANT_TYPE_VALUE)
        .formParam(AUTO_TEAM_CLIENT_ID_KEY, AUTO_TEAM_CLIENT_ID_VALUE)
        .formParam(AUTO_TEAM_CLIENT_SECRET_KEY, AUTO_TEAM_CLIENT_SECRET_VALUE)
        .formParam(RESOURCE_KEY, RESOURCE_VALUE)
    .when()
        .post(AUTO_TEAM_TENANT_ID + RESOURCE); //Send the request along with the resource

    testContext().setResponse(response);

    setAuthorizationToken();
}

@Then("Verify Status Code is {int}")
public void verifyStatusCode(int expected_repsonse_code) {
    testContext().getResponse().then().statusCode(expected_repsonse_code);
}
目前,我发现如何仅在IntelliJ控制台中显示这些详细信息:

例如:

@tests
Feature: Rest Assured under Cucumber POC

  @tests
  Scenario: Azure Login Scenario                                                            # src/main/resources/features/poc.feature:5
    Given Request specifications are set with base uri "https://login.microsoftonline.com/" # CommonStepsDefinitions.setRequestsSpec(String)
Request method: POST
Request URI:    https://login.microsoftonline.com/6ae4e000-b5d0-4f48-a766-402d46119b76/oauth2/token
Proxy:          <none>
Request params: <none>
Query params:   <none>
还有更多

但HTML报告仅显示:


谢谢大家!

我可以给你一些细节,可能无法完全回答你的问题

为了向HTML报告添加数据,您可以使用:

@After
public void addDataToReport(Scenario scenario) { //scenario is provided from Cucumber
    scenario.write(string with the information about scenario);
}
它不会格式化,我不知道如何更改报告的显示方式。每个消息将位于每个测试用例下

您必须以某种方式将信息传递给@After hook

我希望其他人能回答更多细节

编辑:

为了存储关于当前正在运行的场景的信息,甚至是并行的,我们可以基于线程创建一个类来存储必要的信息,这样它将是线程安全的

让我们创建一个类来存储场景。我们称之为存储

@在每个场景之前运行挂钩之前。我们获取有关场景的信息并将其存储,以便知道在哪个线程上运行哪个场景。 记住,钩子必须可以通过Cucumber Runner中的glue参数访问

现在,如果我们想在报告中添加更多信息:

    @Then("Data is saved to the report")
    public void data_is_saved_to_the_report() {
        System.out.println("Saving data to report");
        Storage.getScenario().write("Test data and stuff");
    }
我们只是从存储中获取当前场景,并使用scenario.write方法将信息添加到报告中

报告中的内容如下所示:

谢谢你的提示。事实上,我希望有一个更好的集成解决方案:@dushkin我将我的答案编辑得更复杂。也许它能解决你的问题?非常感谢你抽出时间。我将在周日免费检查您的解决方案,我会更新,希望也能接受。再次感谢!:如果scenario.isFailed或类似的内容,请添加。阅读Cucumber中的数据表
public class BeforeHook {

    @Before(order = 1)
    public void getScenario(Scenario scenario) {
        Storage.putScenario(scenario);
    }
}
    @Then("Data is saved to the report")
    public void data_is_saved_to_the_report() {
        System.out.println("Saving data to report");
        Storage.getScenario().write("Test data and stuff");
    }