gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:24:40 25 4
gpt4 key购买 nike

我在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com