#cucumber #cypress #cypress-cucumber-preprocessor
Вопрос:
У меня есть тест, который выглядит следующим образом:
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}
, определение шага будет выбрано, и тест будет выполнен просто отлично.
Что я упускаю?
Ответ №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)
})
Комментарии:
1. Это все исправило! Спасибо