如何从“中传递数据”;“例子”;Cucumber中步骤定义的部分

如何从“中传递数据”;“例子”;Cucumber中步骤定义的部分,cucumber,Cucumber,我有一个场景,需要在三个不同的环境中执行相同的场景。所以我使用了场景大纲,如下所示 场景大纲:创建测试成功流 Given Login to AAA Application in "<Environment>" When Enter the Customer Details Then Select the Service 所以我的问题是如何在步骤定义中实现这一点。我不想硬编码要素文件中的数据。所以,若环境是QA,那个么QA数据应该通过,就像UAT意味着U

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

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

Given Login to AAA Application in "<Environment>"

When  Enter the Customer Details

Then  Select the Service 
所以我的问题是如何在步骤定义中实现这一点。我不想硬编码要素文件中的数据。所以,若环境是QA,那个么QA数据应该通过,就像UAT意味着UAT数据应该自动获取一样

步骤定义: @给定(“^Login to AAA Application in”([^”]*)“$”)

{

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

}

任何建议/帮助都将不胜感激。

为每个环境创建属性文件(如QA.properties),其中包含
url
凭证等数据

示例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");

我认为您可以在每种情况下使用switch case为全局变量赋值。这不是您在场景/示例中要做的事情,而是在运行测试的配置中要做的事情。如何做取决于您的技术堆栈。@dilimpeghwal-如果可能,请您详细说明。我做了同样的事情,但它不起作用。例如:switch(Environment){case“INT”:break;case“UAT”:break;}@Marit-需要更清楚..我的问题很简单..我想用不同的环境执行相同的场景,而不需要硬编码示例部分中的数据。
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");