在赛普拉斯中运行时,如何将某些测试或文件组合在一起? [英] How to group together certain tests or files when doing a run in Cypress?

查看:261
本文介绍了在赛普拉斯中运行时,如何将某些测试或文件组合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行赛普拉斯(Cypress),并且其中有文件夹,其中有针对不同应用程序的测试. 我有一个名为"smhw-qa"的文件夹,其中包含此特定应用程序的子文件夹和测试文件.

I am currently running Cypress and I have folders inside of it, where I have tests located for different applications. I have a folder entitled "smhw-qa" which contains sub-folders and tests files for this specific application.

此目录apps将来还将包含其他应用程序.

This directory apps will also include other applications too in future.

为了避免每次都要运行每次测试,我希望只运行该特定文件夹.文件夹的位置如下:

In order to avoid having to run every test for a run, I wish to only run this specific folder. The location of the folder is as such:

'cypress/integration/apps/smhw-qa'

随着时间的流逝,将有更多的文件夹和测试添加到apps目录.

Over time, there will be more folders and tests added to the apps directory.

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

I am familiar with how to run a specific file, so doing the following works:

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

当我使用npx cypress -run命令时,如何指定赛普拉斯专门运行哪个文件夹?

How can I specify to Cypress which folder to run specifically when I use the npx cypress -run command?

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

To run a specific test file I tried:

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平台上运行特定的测试套件时,可以节省时间.我也不需要指定单个文件,因为这很耗时.

Running specific sets of tests by their folders will be much easier for me, and will save time when running a specific suite of tests on our CI platform for example. I will also not need to specify the individual files since this is time-consuming.

这也意味着我可以拆分测试,然后在不同的计算机上运行

It would also mean I can split out my tests and run them on different machines

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

Do I need to put anything into my test files, or inside of cypress.json or modify anything else, or can this be achieved through the terminal? What options must I use instead?

谢谢

推荐答案

我认为错误消息中的线索是,您致电

I think the clue is in the error message, you call

cypress/integration/apps/smhw-qa

,错误消息显示

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

因此要使用--project标志,您需要根据每个示例复制/cypress文件夹,如本示例所示 cypress-test-nested-projects

so to use the --project flag you need to replicate the /cypress folder per project, as per this example cypress-test-nested-projects

文件夹结构:

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


但是,我认为您可能想使用--spec标志.如果我对它的理解正确,则可以使用全局模式来保留当前的文件夹结构. 文档


However, I think you might want to use the --spec flag instead. If I understand it correctly, the glob pattern will allow you to keep the current folder structure. Docs

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

这篇关于在赛普拉斯中运行时,如何将某些测试或文件组合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆