我想问当我用小黄瓜 BDD 运行 cypress 时“并且”它不起作用并且出现错误,而其他词如 Give、When、&Then 可以运行,我得到的解决方案是我可以运行代码,但我将“And”一词改为“When”,,,我想问如何解决我面临的问题,请帮助我,以便“And”可以实现
这是feature文件夹中的search.feature文件
Feature: Search Feature
@focus
Scenario: Search for the term bank
Given I visit the Zero Bank homepage
When I enter "bank" into the search box
And I press enter
Then I should see search results related to bank
////
这是stepDef文件夹中的searchStep.js文件
/// <reference types="cypress" />
import { Given, When, Then, } from "@badeball/cypress-cucumber-preprocessor";
Given('I visit the Zero Bank homepage', () => {
cy.visit('http://zero.webappsecurity.com/index.html')
})
When('I enter {string} into the search box', (searching) => {
cy.get('#searchTerm').click().type(searching)
})
And('I press enter', () => {
cy.get('#searchTerm').type('{enter}')
})
Then('I should see search results related to bank', () => {
// cy.url().should('include', '/search.html?searchTerm=Bank');
cy.get('h2').should('exist') // Pastikan elemen <h2> ada di halaman
cy.get('h2').should('contain', 'Search Results:')
})
////
这是我的 package.json 文件
{
“名称”:“bdd”,
“版本”:“1.0.0”,
“描述”:“测试”,
“主要”:“index.js”,
“作者”:“亚亚”,
“许可证”:“麻省理工学院”,
“开发依赖项”:{
"柏树": "^13.10.0",
“更漂亮”:“^3.2.5”
},
“依赖项”:{
"@badeball/cypress-cucumber-preprocessor": "^20.0.5",
"@cypress/browserify-preprocessor": "^3.0.2",
“柏树”:“最新”
},
“柏树黄瓜预处理器”:{
“nonGlobalStepDefinitions”:假,
“stepDefinitions”:“cypress/e2e/stepDef/*.js”
},
“脚本”:{
"cy:open": "柏树打开"
}
}`
////
这是我的 cypress.config 文件
const { defineConfig } = require("cypress");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");
async function setupNodeEvents(on, config) {
// Menambahkan preprocessor Cucumber
await preprocessor.addCucumberPreprocessorPlugin(on, config);
// Mengonfigurasi browserify untuk mengatasi masalah import/require dalam definisi langkah-langkah
on("file:preprocessor", browserify.default(config));
return config;
}
module.exports = defineConfig({
video: false,
defaultCommandTimeout: 5000,
pageLoadTimeout: 10000,
e2e: {
// Pola untuk mencocokkan file-file spesifikasi (features)
specPattern: "cypress/e2e/features/*.feature", // Pastikan ini sesuai dengan struktur folder Anda
supportFile: false,
nonGlobalStepDefinitions: true,
setupNodeEvents,
},
});
/////
这是我的 .prettierrc 文件
{
"semi": false,
"useTabs": true,
"tabWidth": 4,
"singleQuote": true
}
////
这是我跑步的结果
请帮帮我,谢谢老师
这个问题在项目的FAQ中得到了解答。