当我尝试运行用于并行运行测试用例的sorry-cypress 命令
时
CYPRESS_API_URL="http://localhost:1234/" cy2 run --parallel --record --key somekey --ci-build-id hello-cypress
即使安装了 cypress,它也会抛出错误。 这是 sorry-cypress 设置链接
sorry-cypress npm 模块基本链接: https://docs.sorry-cypress.dev/guide/get-started
Error: Cannot detect cypress. Is cypress installed? at getStateModulePath (/home/ashish/.nvm/versions/node/v14.17.5/lib/node_modules/cy2/lib/patch.js:90:11)
这是我的 package.json 文件
{
"name": "test-automation",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {
"cucumber-html-reporter": "5.5.0",
"cypress": "^8.4.1",
"cypress-cucumber-preprocessor": "4.1.4",
"cypress-plugin-tab": "1.0.5",
"cypress-wait-until": "1.7.1",
"eslint": "7.30.0",
"eslint-plugin-cypress": "2.11.3",
"junit-report-merger": "2.2.3"
},
"engines": {
"node": "14"
},
"scripts": {
"open": "cypress open",
"api": "cypress run --headless --browser chrome --spec \"cypress/integration/API/**/*\"",
"ui": "cypress run --browser chrome --spec \"cypress/integration/UI/**/*\"",
"delete:reports": "rm cypress/results/* || true",
"combine:reports": "jrm cypress/results/combined-report.xml \"cypress/results/*.xml\"",
"prechrome": "yarn run delete:reports",
"chrome": "cypress run --browser chrome",
"postchrome": "yarn run combine:reports",
"docker:pull": "docker pull cypress/included:7.6.0",
"predocker:e2e": "yarn run delete:reports",
"docker:e2e": "docker run -it -v $PWD:/e2e -w /e2e --entrypoint=cypress cypress/included:7.6.0 run --headless --browser chrome",
"postdocker:e2e": "yarn run combine:reports",
"generate:report": "node cypress/cucumber-html-reporter.js"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
},
"dependencies": {
"cy2": "^1.3.0"
}
}
最佳答案
这里的问题是 cy2 模块的位置。
运行此命令将有助于解决此问题。
CYPRESS_API_URL="http://localhost:1234/" ./node_modules/cy2/bin/cy2 run --parallel --record --key somekey --ci-build-id hello-cypress
我这里改的是cy2
和./node_modules/cy2/bin/cy2
因为cy2直接访问不到。
安装 cy2 模块通过 npm 将在 node_module 中安装 cy2。
Yarn add 将用于直接访问 cy2 模块。
关于npm - 为什么 cypress 模块在运行 sorry-cypress run 命令时没有检测到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69342587/