cucumber - 如何在 Cypress 功能文件中添加 Before() 函数?

标签 cucumber cypress feature-file

我在我的 Cypress 框架中使用功能文件。

下面是一个场景示例:

Scenario: #1 Cancel should return to Customer Management landing page
 Given User is on the Edit Customer Page
 When User updates the email address to "abc@gmail.com"
 Then the updated email address will appear on the summary page

我面临的问题是,当我重新运行此测试时,原始电子邮件地址将是 "abc@gmail.com" (它在测试期间更新的值第一次试运行)。所以测试实际上不会更新电子邮件地址。

处理此问题的最佳方法是什么?

我正在考虑使用类似 Before() 函数的方法来删除客户(如果存在),然后重新创建它。然后我就可以更新它并且每次的值都是相同的。

但是,我不知道如何在功能文件中添加 Before()。我有一个导航到特定页面的 Background,但这是我应该放置它的地方吗?

最佳答案

cypress-cucumber-preprocessor同时支持 Mocha 的 before/beforeEach/after/afterEach 钩子(Hook)和 Cucumber 的 Before 和 After 钩子(Hook)。所以在你的步骤定义文件中,你可以:

//This example is with the Cucumber hooks
const {
  Before,
  After,
  Given,
  Then,
} = require('cypress-cucumber-preprocessor/steps')

// this will get called before each scenario
Before(() => {
  //Code to delete customer if it exists
})

关于cucumber - 如何在 Cypress 功能文件中添加 Before() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71314238/

相关文章:

selenium - 通过 selenium 跳过图像加载

java - Cucumber:初始化然后在步骤定义之间传递数据?

java - 如何将一个特征文件的数据(来自示例)传递到另一特征文件?

alert - 如何在 Cypress 确认窗口中单击“接受”

node.js - 我如何在 Cypress 中使用流程?

java - 在 cucumber 测试中使用特征文件中的值?

ruby-on-rails - Rails 测试中缺少记录

jquery - 如何在 cypress 中获取 data-id 的值

Flutter 驱动测试浏览器