0

我想执行一个测试用例,尝试使用不同的凭据登录并检查错误消息。如何在 Cucumber 中做到这一点?

Feature: Login

Login Test Suite

Background: 
  Given I'm on the login page

Scenario: 01. Should not be able to login with invalid cred
When I log in with "username" and "password"
    |  username   | password | ExpectedError                     |
    |    asdasd   | anything | Invalid credentials specified     |
    |             | anything | Please specify a username         |
    |    asdasd   |          | Please specify a password         |
    |             |          | No username or password specified |
Then An error msg should appear

这是我要传递两个参数,用户名和密码的地方:

When('I log in with (string) and (string)', (username,password) => {
    p.loginWith(username, password)
})
4

1 回答 1

1

看起来你想要一个Scenario Outline。您需要重新表述每个步骤,并且数据表将移动到“示例”表中:

Feature: Login
  Login Test Suite

Background: 
  Given I'm on the login page

Scenario Outline: 01. Should not be able to login with invalid cred
  When I log in with "<username>" and "<password>"
  Then the "<ExpectedError>" error msg should appear

Examples:
  | username | password | ExpectedError                     |
  | asdasd   | anything | Invalid credentials specified     |
  |          | anything | Please specify a username         |
  | asdasd   |          | Please specify a password         |
  |          |          | No username or password specified |

该方案将对示例表中的每一行执行一次。步骤中的<...>标记允许您引用示例表列之一中的值。

您的Then步骤需要改写以通过预期的验证错误。它的步骤定义非常简单,我将把实现留给你。这是存根:

Then('the (string) error msg should appear', (expectedError) => {
  // TODO: Make assertion
});
于 2021-04-02T14:37:50.723 回答