【问题标题】:How to pass the data from "Examples" Section to Step Definition in Cucumber如何将数据从“示例”部分传递到 Cucumber 中的步骤定义
【发布时间】:2020-09-25 07:36:40
【问题描述】:

我有一个场景,需要在三个不同的环境中执行相同的场景。所以我使用了 Scenario Outline,如下所示。

场景大纲:创建测试成功流程

Given Login to AAA Application in "<Environment>"

When  Enter the Customer Details

Then  Select the Service 

示例:|环境|

|QA|
|UAT|
|Prod|

所以我的问题是如何在步骤定义中实现这一点。我不想硬编码特征文件中的数据。因此,如果 Environment 是 QA,那么 QA 数据应该通过,Same like UAT 意味着 UAT 数据应该自动获取..

步骤定义: @Given("^Login to AAA Application in "([^"]*)"$")

public void Login_to_AAA_Application(String Environment) throws Throwable 

{

// 如何在这里为所有环境编写代码。我的场景需要根据场景大纲示例部分提供的环境执行。

}

感谢任何建议/帮助。

【问题讨论】:

  • 我认为您可以使用 switch case 在每种情况下为全局变量赋值。
  • 这不是您在场景/示例中要做的事情,而是在运行测试的配置中。如何做到这一点取决于您的技术堆栈。
  • @DilipMeghwal - 如果可能,请您详细说明。我做了同样的事情,但它不工作。例如:switch(Environment){ case "INT": break;案例“UAT”:中断;}

标签: cucumber


【解决方案1】:

为每个包含urlcredentials 等数据的环境创建属性文件(例如 QA.properties)。

示例 QA.properties 文件内容。

browser=chrome
testSiteUrl=https://parabank.parasoft.com/parabank/index.htm

步骤定义代码。

public  Properties QaPropFile = new Properties();
public  Properties ProdPropFile = new Properties();
public  Properties UATPropFile = new Properties();

public void Login_to_AAA_Application(String Environment) throws Throwable{
    switch(Environment) {
        case "QA":
            FileInputStream QaFileobj = new FileInputStream("filePath");
            QaPropFile.load(QaFileobj);
            break;
        case "Prod":
            FileInputStream ProdFileobj = new FileInputStream("filePath");
            ProdPropFile.load(ProdFileobj);
            break;
        case "UAT":
            FileInputStream UatFileobj = new FileInputStream("filePath");
            UATPropFile.load(UatFileobj);
            break;
        default:
            System.out.println(Environment + " is not a valid envieonment");
    }
}

当您想访问此代码时,请尝试以下代码。

QaPropFile.get("testSiteUrl");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多