10

默认情况下,运行cypress open会打开赛普拉斯窗口,然后我必须手动点击“运行所有测试”按钮来运行它们。

如何仅通过运行 就在浏览器中运行所有测试cypress open,而不需要额外的步骤?

谢谢你。

编辑:当我更改测试文件时,我需要重新运行测试,就像这样cypress open做一样,所以只运行一次(比如在无头模式下)没有帮助。

4

4 回答 4

5

如果您无头运行赛普拉斯测试cypress run,它会运行所有测试,而无需单击“运行所有测试”按钮。

我发现使用npx cypress run是最好的方法。有关无头运行 cypress 的文档指定了您可以使用的其他选项:https ://docs.cypress.io/guides/guides/command-line.html#

于 2018-04-06T10:12:45.370 回答
5

使用时,cypress open您可以使用全局配置选项在每次编辑后在浏览器中重新运行测试,watchForFileChanges详见此处

您可以将其作为命令行参数传递:

cypress open --config watchForFileChanges=true

或者您可以在cypress.json文件中指定它:

{
    "watchForFileChanges": true
}

首次运行时,您仍然需要单击运行所有规范cypress open,但之后对测试文件的任何编辑都会导致重新运行测试。

于 2018-09-10T05:28:12.807 回答
0

您可以告诉 Cypress UI 的界面(请记住,Cypress UI 与任何其他页面一样位于 DOM 中)重新运行该套件 - 只需在启动时从您的应用程序发送一些预定义的信号,并让 Cypress 直接使用 jQuery(避免 log-事件)找到它自己的重新加载按钮并单击它。

在我的示例中,“信号”是某个控制台日志消息,我的 React 应用程序在启动过程中会打嗝:

Cypress.on("window:before:load", (win) => { // registers callback early, long before the app is loaded
  win.console._log = win.console.log;
  win.console.log = function monkeyPatchedConsoleLog() {
    if (arguments[0].match(/^MyApp starting: \(.*\)/)) { // match the app's startup message
      cy.$$(".restart", top.document).click(); // click Cypress' own reload button
    }
    return win.console._log.apply(win.console, arguments); // otherwise log normally
  };
});

support/*(将其包含在您的文件中的某处)

于 2020-04-28T17:26:54.497 回答
0

如果要使用npx cypress open,则在package.json中将标志“setnonGlobalStepDefinitions”设置为 false,然后在“stepDefinitions”中指明包含文件的文件夹。

{
  "devDependencies": {
    "cypress": "^9.1.0",
    "cypress-cucumber-preprocessor": "^4.3.0"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": false,
    "stepDefinitions": "cypress/integration/"
  }
}

您的测试将一个接一个地运行。

于 2021-12-04T00:28:13.880 回答