0

我有一个如下所示的测试:

Feature: App example

  I want to use the application

  @focus
  Scenario: Showing some text by clicking a button
    Given I visit the application
    When I click on a test button
    Then I should see "Test Bar Foo" in the content section

以下是步骤实现:

import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

import exampleSelectors from '../page/example'

const url = 'http://localhost:3000'

Given('I visit the application', () => {
  cy.visit(url)
})

When('I click on a test button', () => {
  cy.findByTestId(exampleSelectors.testBtn).click()
})

Then('I should see "{string}" in the content section', (content) => {
  cy.findByTestId(exampleSelectors.testContent).should('contain', content)
})

运行 cypress 时,出现以下错误:

Error: Step implementation missing for: I should see "Test Bar Foo" in the content section  

根据Cucumber 参数类型文档{string}语法应该检测"Test Bar Foo"字符串。
如果我更改{string}{word},则拾取步骤定义并且测试运行良好。

我错过了什么?

4

1 回答 1

1

黄瓜表达式 - 黄瓜文档

{string} 匹配单引号或双引号字符串,例如"banana split"'banana split'(但不是banana split)。只会提取引号之间的文本。引号本身被丢弃。空引号对是有效的,将被匹配并作为空字符串传递给步骤代码。

"因此,您的步骤定义中不需要额外的:

Then('I should see {string} in the content section', (content) => {
  cy.findByTestId(exampleSelectors.testContent).should('contain', content)
})
于 2021-06-16T18:32:47.537 回答