使用 {string} 表达式时缺少步骤实现
Step implementation missing when using {string} expression
我有一个如下所示的测试:
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)
})
当运行ning cypress 时,出现以下错误:
Error: Step implementation missing for: I should see "Test Bar Foo" in the content section
根据 Cucumber parameter types documentation,{string}
语法应该检测 "Test Bar Foo"
字符串。
如果我将 {string}
更改为 {word}
,则会选择步骤定义并且测试 运行 就好了。
我错过了什么?
来自Cucumber Expressions - Cucumber Documentation:
{string}
Matches single-quoted or double-quoted strings, for example "banana split"
or 'banana split'
(but not banana split
). Only the text between the quotes will be extracted. The quotes themselves are discarded. Empty pairs of quotes are valid and will be matched and passed to step code as empty strings.
因此您不需要在步骤定义中添加额外的 "
:
Then('I should see {string} in the content section', (content) => {
cy.findByTestId(exampleSelectors.testContent).should('contain', content)
})
我有一个如下所示的测试:
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)
})
当运行ning cypress 时,出现以下错误:
Error: Step implementation missing for: I should see "Test Bar Foo" in the content section
根据 Cucumber parameter types documentation,{string}
语法应该检测 "Test Bar Foo"
字符串。
如果我将 {string}
更改为 {word}
,则会选择步骤定义并且测试 运行 就好了。
我错过了什么?
来自Cucumber Expressions - Cucumber Documentation:
{string}
Matches single-quoted or double-quoted strings, for example"banana split"
or'banana split'
(but notbanana split
). Only the text between the quotes will be extracted. The quotes themselves are discarded. Empty pairs of quotes are valid and will be matched and passed to step code as empty strings.
因此您不需要在步骤定义中添加额外的 "
:
Then('I should see {string} in the content section', (content) => {
cy.findByTestId(exampleSelectors.testContent).should('contain', content)
})