通过传入 REST API JSON 主体对象来使用不同数据集的场景大纲

Scenario Outline to use different data set by passing in REST API JSON body object

我们有 JSON BODY arrays/objects 的 REST API。要在运行时控制数据进入 JSON 文件,使用 testdata.properties 文件定义数据并调用它,如下所示。我们正在使用黄瓜宁静。

Testdata.properties 文件:

Value = 123

步骤定义文件:

@Given("^Set the \"([^\"]*)\" with \"([^\"]*)\"$")
public void set_data_parameterization (String fieldName, String Value)  {

            if (fieldName.contains("Test")) {
                jsonObjectNew.getAsJsonObject("TestInfo").add("Value",
                        gson.toJsonTree(Value));
            }

    System.err.println("Test value fetched from the Scenario outline");

}

JSON 文件:

{
"TestInfo": {
    "Test123": 3,
    "Value": 50 // this value to be replaced
}  
}

.特征文件:

Scenario Outline:: 
1. Testing data parameterize

Given Set the URL for "Test" as "base" 
And Set the "Test" with "Value"

Examples:
|Value|
|700|
|710|

如果从 .properties 文件调用变量数据工作正常,但是如果想要为同一场景执行不同的数据集。怎么可能实现。尝试使用功能文件中的示例,但是当 运行 文件作为 cucumbertest> 获取实际有效载荷值 50。它不会替换为 700/710。

请指导。

现在能够按预期获得值,问题是我正在尝试 "String"(例如:"Values")。当在 .feature 文件中尝试时,其余代码是相似的。 能够获取给定示例的迭代值。