我在這個網站上看到了其他類似的問題,但沒有一個對我有滿意的解決方案。我沒有任何 webpack.config.js 檔案,因為我們從 angular 獲取默認配置。請參閱下面的相應圖片以更好地了解我的問題。

我專案中的其他配置:
包.json
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"json": {
"enabled": true
},
"stepDefinitions": "**/cypress/e2e/**/*.js",
"step_definitions": "**/cypress/e2e/**/*.js"
},
cypress.config.ts
import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
specPattern: '**/e2e/**/*.feature',
"supportFile": false,
chromeWebSecurity: false
},
})
更新 1: 您好 @Wirtuald,感謝您回復我。我開始在一個非常復雜的角度專案中遇到這個問題。所以,我從頭開始創建了一個基本專案,但我仍然遇到同樣的問題。然后,我在下面為您提供這個新專案的所有資訊:
我沒有“插件”檔案夾
package.json 上的版本:
"devDependencies": { "@badeball/cypress-cucumber-preprocessor": "^11.2.0", "cypress": "^10.2.0" },package.json 上的前處理器配置
"cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "json": { "enabled": true }, "stepDefinitions": [ "[filepath].{js,ts}", "cypress/e2e/**/*.{js,ts}" ]}
cypress.config.js:
const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { specPattern: "**/*.feature", chromeWebSecurity: false, setupNodeEvents(on, config) { // implement node event listeners here }, }, });
-專案結構

- 直接注意-steps.js
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
Given("Access to NXSuite", () => {
cy.visit("https://www.nxsuite.com");
})
uj5u.com熱心網友回復:
嘗試安裝@cypress/webpack-preprocessor
uj5u.com熱心網友回復:
就我而言,這是最新版本的問題cypress
我在用著
"@badeball/cypress-cucumber-preprocessor": "^11.2.0",
"cypress": "^10.2.0",
首先,確保您使用@badeball/cypress-cucumber-preprocessor修復了 cypress 10 的一些兼容性問題的最新版本。有關更多資訊,請參閱https://github.com/badeball/cypress-cucumber-preprocessor/issues/722#。
此外,最新版本的 cypress 已洗掉插件檔案。cypress/plugins/index.js就我而言,從內部方法遷移所有代碼setupNodeEvents解決了這個問題。請參閱https://docs.cypress.io/guides/references/migration-guide#Plugins-File-Removed
魔鬼在細節中,它也可能與您的插件檔案本身有關。也許您可以分享它,以便我們更好地幫助您。您還可以分享您使用的“@badeball/cypress-cucumber-preprocessor”的版本嗎
希望對你有幫助,
uj5u.com熱心網友回復:
從快速入門開始,您只是缺少 webpack 流程
然后配置您的首選捆綁器以處理功能檔案。請參閱示例/了解如何使用 Browserify、Esbuild 或 Webpack。
webpack.ts 示例在cypress-cucumber-preprocessor/examples/webpack-ts/cypress.config.ts 中給出。
它需要額外安裝@cypress/webpack-preprocessor和ts-loader。
import { defineConfig } from "cypress";
import * as webpack from "@cypress/webpack-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
async function setupNodeEvents(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
await addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
webpack({
webpackOptions: {
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: "ts-loader",
},
],
},
{
test: /\.feature$/,
use: [
{
loader: "@badeball/cypress-cucumber-preprocessor/webpack",
options: config,
},
],
},
],
},
},
})
);
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}
export default defineConfig({
e2e: {
specPattern: "**/*.feature",
supportFile: false,
setupNodeEvents,
},
});
在Update1中cypress.config.js你有一個錯字
module.exports = defineConfig({
應該
export default defineConfig({
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/496207.html
