如何在Cypress测试运行器中运行特定场景

huangapple go评论88阅读模式
英文:

How to Run Specific Scenario in Cypress Test Runner

问题

我正在使用Cypress、TypeScript和Cypress-Cucumber-Pre-Processor框架。

Cypress测试运行器是一个很好的工具,用于调试和检查测试用例中发生的一切,但每次我选择运行一个规范文件(在我的情况下是特性文件)时,所有测试用例都会被调用运行。

我想在这里运行特定的测试用例,我知道可以使用标签的命令行方法来运行特定的测试用例,但我想使用Cypress测试运行器运行它,有办法吗?

英文:

I am working with Cypress,TypeScript,Cypress-Cucumber-Pre-Processor Framework.

Cypress Test Runner is a great tool to debug and check everything that is happening with your test case , but every time I select a spec file(In my case Feature File) to run , all the test cases
are invoked to run

I want to run specific test case here ,I know command line method to run specific test case with tags,
But I want to run it using Cypress Test Runner , Is there any way ?

答案1

得分: 4

也许你想要使用@only标记,而不是使用特殊的开发功能。

请查看 cypress-cucumber-preprocessor/features/tags
/only_tag.feature
这是一个示例。

  规则:
   - 存在任何@only标记时只有带有该标记的测试才会运行
   - 此行为针对每个文件进行范围限定
   - 此标记的存在会覆盖任何其他标记筛选条件

如果你进一步查看示例,你会看到它可以添加到特性或场景中。

这部分展示了临时应用@only以仅运行带有该标记的场景,尽管在永久配置中指定了另一个标记。

  场景: 指定标记
    假如有一个名为cypress/e2e/a.feature的文件内容如下:
      """
      特性: 一个特性
        @only
        场景: 一个场景
          假如一个步骤

        @foo
        场景: 另一个场景
          假如一个步骤
      """
    以及一个名为cypress/support/step_definitions/steps.js的文件内容如下:
      """
      const { Given } = require("@badeball/cypress-cucumber-preprocessor");
      Given("一个步骤", function(table) {});
      """
    当我使用-e tags=@foo运行cypress时
    那么它应该只运行场景一个场景
    并且应该跳过场景另一个场景
英文:

Maybe instead of using a special dev feature, you want to use @only tag.

See cypress-cucumber-preprocessor/features/tags
/only_tag.feature
is an example of this option.

  Rules:
   - In presence of any @only tag, only tests tagged with this should be run
   - This behavior is scoped per file
   - Presence of this tag override any other tag filter

If you look further at the example, you can see it added to Feature or to Scenario.

This part shows temporary application of @only working to run only that tagged scenario, even though another tag is specified in the permanent configuration.

  Scenario: specifying tags
    Given a file named "cypress/e2e/a.feature" with:
      """
      Feature: a feature
        @only
        Scenario: a scenario
          Given a step

        @foo
        Scenario: another scenario
          Given a step
      """
    And a file named "cypress/support/step_definitions/steps.js" with:
      """
      const { Given } = require("@badeball/cypress-cucumber-preprocessor");
      Given("a step", function(table) {});
      """
    When I run cypress with "-e tags=@foo"
    Then it should appear to have run the scenario "a scenario"
    And it should appear to have skipped the scenario "another scenario"

答案2

得分: 0

作为一种解决方法,我创建了 DevelopFeature,此功能文件将仅包含我正在开发的测试用例,以便我可以在 Cypress 测试运行中仅运行此单个测试用例。一旦测试用例开发完成,我将此场景移动到所需功能。

英文:

As a workaround, I created DevelopFeature , This feature file will only contain the test case I am developing so that I can run only this single Test Case in Cypress Test Run
Once Development of Test Case is completed,I am moving this scenario to desired feature

huangapple
  • 本文由 发表于 2023年6月11日 23:10:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451106.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定