【问题标题】:Same step name in two diffrent feature file两个不同功能文件中的相同步骤名称
【发布时间】:2022-10-25 17:37:53
【问题描述】:

尝试使用小黄瓜、黄瓜和柏树进行自动化测试。我在 *.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 文件仅使用 login.feature 和相同的注册。除非您推荐其他解决方案。提前谢谢你和最好的问候。

【问题讨论】:

    标签: javascript automated-tests cucumber cypress gherkin


    【解决方案1】:

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

     A user enters the username {string}
    

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

    A user enters the username "cypress_agent"
    

    在其他一些功能中

     A user enters the username "agent"
    

    它调用与您在本质上使步骤动态化的步骤相同的步骤。所以恕我直言,你必须完成重复的步骤,黄瓜会处理它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 2014-09-23
      • 1970-01-01
      相关资源
      最近更新 更多