Cucumber 场景大纲和带有通用步骤定义的示例 [英] Cucumber scenario outline and examples with generic step definitions

查看:19
本文介绍了Cucumber 场景大纲和带有通用步骤定义的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能文件如下:

I have a Feature file which is as below:

Scenario Outline: Create ABC

  Given I open the application

  When I enter username as <username>

  And I enter password as <password>

  Then I enter title as <title>

  And press submit


Examples:

| username | password | title |

| Rob      | xyz1      | title1 |

| Bob      | xyz1      | title2 |

这要求我对每个值都有步骤定义.我可以换一个

This mandates me to have step definitions for each of these values. Can i instead have a

可以为每个用户名或密码或标题值映射的通用步骤定义

generic step definition that can be mapped for every username or password or title values in

示例部分.

也就是说,而不是说

@When("^I enter username as Rob$")
public void I_enter_username_as_Rob() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

我可以进入吗

@When("^I enter username as <username>$")
public void I_enter_username_as_username(<something to use the value passed>) throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

推荐答案

你应该使用这种格式

Scenario Outline: Create ABC

    Given I open the application
    When I enter username as "<username>"
    And I enter password as "<password>"
    Then I enter title as "<title>"
    And press submit

这会产生

@When("^I enter username as "([^"]*)"$")
public void I_enter_username_as(String arg1) throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

arg1 现在将传递您的用户名/值.

arg1 will now have your username/value passed.

这篇关于Cucumber 场景大纲和带有通用步骤定义的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆