提问者:小点点

如何将数据从“示例”部分传递到cucumber中的步骤定义


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

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

Given Login to AAA Application in "<Environment>"

When  Enter the Customer Details

Then  Select the Service 

示例:|环境|

|QA|
|UAT|
|Prod|

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

步骤定义:@给定("^登录到AAA应用程序在 "([^"]*)"$")

public void Login_to_AAA_Application(String Environment) throws Throwable 

{

如何在此处为所有环境编写代码。和我的方案需要根据方案大纲的示例部分中提供的环境执行。

}

感谢任何建议/帮助。


共1个答案

匿名用户

为每个env创建属性文件(如QA.properties ),其中包含< code>url 、< code >凭据等数据。

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