npm - 为什么 cypress 模块在运行 sorry-cypress run 命令时没有检测到?

标签 npm cypress

当我尝试运行用于并行运行测试用例的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/

相关文章:

node.js - 我收到以下错误 - NPM 错误 : debug module is not working

node.js - NPM - 错误 : Cannot find module '../'

javascript - puppeteer 操纵者相当于柏树的 contains() 方法

javascript - Cypress,使用 "Cypress.Commands.add"定义新命令时得到错误结果

node.js - 如何使用 n 将特定版本的 Node 设置为默认值

node.js - 当我尝试使用 npm 在 win8 中安装某些软件包时,它总是给我这样的错误

node.js - 如何列出一个 npm 模块的所有版本?

Cypress 断言,验证某些文本是否存在类

testing - .json 文件中的单独定位器 - Cypres

material-ui - Cypress mat-select 选择命令失败