首页 > 解决方案 > 在 Cypress 中运行时如何将某些测试或文件组合在一起?

问题描述

我目前正在运行 Cypress,其中有文件夹,其中有针对不同应用程序的测试。我有一个名为“smhw-qa”的文件夹,其中包含此特定应用程序的子文件夹和测试文件。

该目录apps将来也将包括其他应用程序。

我想做的事

为了避免必须运行每个测试来运行,我希望只运行这个特定的文件夹。文件夹的位置是这样的:

'cypress/integration/apps/smhw-qa'

随着时间的推移,将会有更多的文件夹和测试添加到apps目录中。

我熟悉如何运行特定文件,因此执行以下工作

npx cypress run --spec 'cypress/integration/apps/smhw-qa/banners_promos_global/global_search.js'

当我使用命令时,如何向赛普拉斯指定要运行的文件夹npx cypress -run

我已经尝试过的

要运行我尝试的特定测试文件:

npx cypress run --project 'cypress/integration/apps/smhw-qa'

但这反而提供了一个错误:

Can't run because no spec files were found.

We searched for any files inside of this folder:

/Users/jaswindersingh/Documents/cypress-automation/automation/cypress/integration/apps/smhw-qa/cypress/integration

通过它们的文件夹运行特定的测试集对我来说会容易得多,并且例如在我们的 CI 平台上运行特定的测试套件时会节省时间。我也不需要指定单个文件,因为这很耗时。

这也意味着我可以拆分我的测试并在不同的机器上运行它们

我是否需要将任何内容放入我的测试文件中,或者在cypress.json其他任何内容中进行修改,或者这可以通过终端来实现吗?我必须改用哪些选项?

谢谢

标签: automatione2e-testingcypress

解决方案


我认为线索在错误消息中,你打电话

cypress/integration/apps/smhw-qa

并且错误消息显示

cypress/integration/apps/smhw-qa/cypress/integration

所以要使用--project你需要复制/cypress每个项目的文件夹的标志,按照这个例子cypress-test-nested-projects

文件夹结构:

package.json
node_modules
src/
    clients/
        foo/
            cypress.json
            cypress/
        bar/
            cypress.json
            cypress/

但是,我认为您可能想改用该--spec标志。如果我理解正确,glob 模式将允许您保留当前的文件夹结构。文档

cypress run --spec 'cypress/integration/apps/smhw-qa/**/*'

推荐阅读