两个不同特征文件中的步骤名称相同



尝试使用小黄瓜、黄瓜和柏树进行自动化测试。我在*.feature文件中编写测试场景,在*.js文件中编写代码。

他想逐个模块进行测试。首先测试的是登录模块,然后是注册模块。

登录。功能

Feature: Login page
Feature Login page will work depending on the user credentials.
Background:
Given A user opens a website to log in
Scenario: Success Login as Agent
When A user enters the username "agent"
And A user enters the password "pass!"
And A user clicks on the login button
Then The user was logged in as an Agent
Scenario: Success Login as Customer
When A user enters the username "customer"
And A user enters the password "pss123!"
And A user clicks on the login button
Then The user was logged in as an Customer
Scenario: Success Login as Admin
When A user enters the username "admin"
And A user enters the password "admin1"
And A user clicks on the login button
Then The user was logged in as an Admin
Scenario: Log in to the wrong user
When A user enters the username "1qazxsw23edc"
And A user enters the password "1qazxsw23edc"
And A user clicks on the login button
Then Error when logging in to the wrong user

注册。功能

Feature: New user registration.
Feature is designed to test the operation of registration.
Background:
Given A user opens a website to register
Scenario: Correct registration of a new user
When User clicks on button to register
And A user enters the username "cypress_agent"
And A user enters the email "cypress_test@gmail.com"
And A user enters the first name "Cypress"
And A user enters the last name "Test"
And A user enters the password "zaq1@WSX"
And A user enters the password confirmation "zaq1@WSX"
And A user clicks on the submit button
Then TBA

当试图启动步骤重复的任何特征文件时,问题就会出现,这是真的,因为步骤";用户打开网站以登录";或";用户输入用户名"{string}";。

Error
Multiple matching step definitions for: A user enters the username "cypress_agent"
A user enters the username {string}
A user enters the username {string}

最简单的解决方案是更改名称。然而,我被告知,测试越深入,最终相同的名字就会重复。这个问题还有其他解决办法吗?例如,要使login.js文件使用ONLY login.feature和相同的功能进行注册。除非你推荐其他解决方案。提前感谢并致以最良好的问候。

我建议更合理地安排测试文件。您不需要更改文件名或更改任何内容。但是您要记住可重用性和可扩展性的概念。由于您已经在步骤定义中有了一个通用步骤,这对您来说就足够了,即

A user enters the username {string}

在功能文件中,您可以使用与您的功能相关的任何字符串进行调用,您已经这样做了,即

A user enters the username "cypress_agent"

以及在一些其他特征中

A user enters the username "agent"

它调用的步骤与您使步骤在自然界中具有动态性的步骤相同。所以IMHO,你必须得到重复的步骤和黄瓜会照顾它。

最新更新