gpt4 book ai didi

cucumber - BDD- cucumber : Is possible to disable Background logic for only one scenario in feature?

转载 作者:行者123 更新时间:2023-12-02 21:44:18 25 4
gpt4 key购买 nike

在功能文件中有一个背景和多个场景,但现在需要一个与不必运行后台逻辑的相同功能相关的场景,是否可以仅针对一个场景禁用?

更新 - 添加示例:

Feature: Sign Up

In order to access to protected parts of site
A user
Should sign up

Background:
Given I am on sign up page
And I am not logged in

Scenario: User sign up succesfully
When I sign up with valid fields
Then I should view dashboard page

Scenario: User altredy sign up
When I sign up with altredy registred user e-mail
Then I should view altredy sign up message and link to forgot password page

Scenario: User try to sign up with missing/wrong data
When I will try to sign up with missing/wrong data
Then I should error message

Scenario: User altredy sign in
#here disable background
Given I am logged in
When I am on sign up page
Then i should be redirect to dashboard page

最佳答案

解决方案 1。

您可以将该场景放在其他没有背景或有自己背景的功能文件中

解决方案 2。

从特征文件中删除背景,然后将其逻辑放在步骤定义上,例如

Given 'I am on sign up page' do
some code here
end

Given 'I am not logged in' do
some code here
end

然后在每个第一步

Given 'I sign up with valid fields' do
step 'I am on sign up page'
step 'I am not logged in'
the rest of your code for this step
end

Given 'I sign up with altredy registred user e-mail' do
step 'I am on sign up page'
step 'I am not logged in'
the rest of your code for this step
end

Given 'I will try to sign up with missing/wrong data' do
step 'I am on sign up page'
step 'I am not logged in'
the rest of your code for this step
end

虽然你会重复这些至少 3 次,但这并不漂亮。

解决方案 3。

您可以删除该场景并将其步骤粘贴到第一个场景中,例如

Scenario: User sign up succesfully
When I sign up with valid fields
Then I should view dashboard page #this is your Given I am logged in step
When I am on sign up page
Then i should be redirect to dashboard page

关于cucumber - BDD- cucumber : Is possible to disable Background logic for only one scenario in feature?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9897044/

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