我正在使用黄瓜开发 Cypress BBD 框架:
以下是安装的依赖项:
"devDependencies": {
"cypress": "^13.11.0",
"cypress-cucumber-preprocessor": "^4.3.1"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": false,
"stepDefinitions": "cypress/e2e/Cucumber/tests/"
}
我当前的文件夹结构:
.
└── CypressCucumberFramework-Version1/
├── cypress/
│ ├── e2e/
│ │ └── Cucumber/
│ │ ├── features/
│ │ │ ├── flightReservation.feature
│ │ │ ├── registerPage.feature
│ │ │ └── signOn.feature
│ │ ├── pages/
│ │ │ ├── flightReservation.js
│ │ │ ├── registerPage.js
│ │ │ └── signOn.js
│ │ └── tests/
│ │ ├── testFlightReservation.cy.js
│ │ ├── testRegisterPage.cy.js
│ │ └── testSignOnPage.cy.js
│ ├── fixtures/
│ │ └── testData.json
│ ├── support/
│ │ ├── commands.js
│ │ └── e2e.js
│ ├── screenshots
│ └── videos
├── node_modules
├── cypress.config.js
├── package-lock.json
└── package.json
当Allure Cypress Reporting依赖项未安装时,我能够从Cypress Test Runner和VScode Terminal成功执行测试。
所以,当我添加下面的 Allure Cypress Reporting 依赖项时”
package.json
"devDependencies": {
"allure-commandline": "^2.29.0",
"allure-cypress": "^3.0.0-beta.3",
"cypress": "^13.11.0",
"cypress-cucumber-preprocessor": "^4.3.1"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": false,
"stepDefinitions": "cypress/e2e/Cucumber/tests/"
}
cypress.config.js
const { defineConfig } = require("cypress");
const cucumber = require('cypress-cucumber-preprocessor').default
const { allureCypress } = require("allure-cypress/reporter");
module.exports = defineConfig({
video:true,
screenshotOnRunFailure: true,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
//Cucumber PreProcessor
on('file:preprocessor', cucumber())
//Allure Reports
allureCypress(on);
},
specPattern: "cypress/e2e/Cucumber/features/*.feature"
},
env:{
registerPageURL:'https://demo.guru99.com/test/newtours/register.php',
signOnPageURL:'https://demo.guru99.com/test/newtours/login.php',
flightReservation: 'https://demo.guru99.com/test/newtours/reservation.php',
}
});
e2e.js
// Import commands.js using ES2015 syntax:
import './commands';
import "allure-cypress/commands";
因此,在使用上述配置和依赖项执行Allure Cypress Reporting的测试时,我面临以下问题:
参考:https://allurereport.org/docs/cypress/
错误:
The error was:
Error: Can't walk dependency graph: Cannot find module 'allure-cypress/commands' from 'C:\Users\angshumanbasak\CypressCucumberFramework-Version1\cypress\support\e2e.js'
required by C:\Users\angshumanbasak\CypressCucumberFramework-Version1\cypress\support\e2e.js
at C:\Users\angshumanbasak\CypressCucumberFramework-Version1\node_modules\resolve\lib\async.js:146:35
at processDirs (C:\Users\angshumanbasak\CypressCucumberFramework-Version1\node_modules\resolve\lib\async.js:299:39)
at isdir (C:\Users\angshumanbasak\CypressCucumberFramework-Version1\node_modules\resolve\lib\async.js:306:32)
at C:\Users\angshumanbasak\CypressCucumberFramework-Version1\node_modules\resolve\lib\async.js:34:69
at callback (C:\Users\angshumanbasak\AppData\Local\Cypress\Cache\13.11.0\Cypress\resources\app\node_modules\@packages\server\node_modules\graceful-fs\polyfills.js:299:20)
at callback (C:\Users\angshumanbasak\AppData\Local\Cypress\Cache\13.11.0\Cypress\resources\app\node_modules\@packages\server\node_modules\graceful-fs\polyfills.js:299:20)
at FSReqCallback.oncomplete (node:fs:197:21)
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
- A missing file or dependency
- A syntax error in the file or one of its dependencies
Fix the error in your code and re-run your tests.
虽然我有导入“allure-cypress/commands”;在 e2e.js 中,我无法理解为什么我会面临这个模块依赖错误。 任何解决问题的帮助将不胜感激!
在 beta.3 版本中,没有
allure-cypress/commands
文件夹,查看 node-modules/allure-cypress
文件夹下 - 只有 /dist
文件夹。
所以删除线
import "allure-cypress/commands"
。如果您从一些旧笔记中得到了这一点并希望遵循它们,请降级至 v.2.15.1
。