如何在柏树测试中实现beforeall黄瓜钩?

发布于 2025-01-31 09:22:48 字数 1397 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下伊人醉 2025-02-07 09:22:48

我通过将背景添加到每个功能文件来解决此问题。这将在您的功能文件中的每种情况下执行。

例子:

Feature: Doing some this

Background: 
    Given This will run before each scenario
Scenario: 
    Given Will run after the background process
Scenario: 
    This Will also run after the background run

I worked around this by adding background to each feature file. This will execute before each scenario in your feature file.

Example:

Feature: Doing some this

Background: 
    Given This will run before each scenario
Scenario: 
    Given Will run after the background process
Scenario: 
    This Will also run after the background run
洛阳烟雨空心柳 2025-02-07 09:22:48

我不是Cypress-Cucumber =预处理器的专家noreferrer“> cypress-cucumber-preprocessor/features/hooks_ordering.feature 似乎有摩卡咖啡正常用法()

Cucumber ()是一个不同的钩子,因为资本“ b”。

    And a file named "cypress/support/step_definitions/steps.js" with:
      """
      const {
        Given,
        Before,
        After
      } = require("@badeball/cypress-cucumber-preprocessor")
      let counter;
      before(function() {
        counter = 0;
      })
      beforeEach(function() {
        expect(counter++, "Expected beforeEach() to be called after before()").to.equal(0)
      })
      Before(function() {
        expect(counter++, "Expected Before() to be called after beforeEach()").to.equal(1)
      })

I'm no expert in cypress-cucumber=preprocessor, but looking at cypress-cucumber-preprocessor/features/hooks_ordering.feature there seems to be normal usage of Mocha before() and beforeEach() hooks.

Cucumber Before() is a different hook, because of the capital "B".

    And a file named "cypress/support/step_definitions/steps.js" with:
      """
      const {
        Given,
        Before,
        After
      } = require("@badeball/cypress-cucumber-preprocessor")
      let counter;
      before(function() {
        counter = 0;
      })
      beforeEach(function() {
        expect(counter++, "Expected beforeEach() to be called after before()").to.equal(0)
      })
      Before(function() {
        expect(counter++, "Expected Before() to be called after beforeEach()").to.equal(1)
      })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文