Search code examples
javaselenium-webdrivercucumberbddgherkin

Cucumber Java with Selenium - Reuse and concat Login feature with other features


I have a doubt with the use of a login feature. What I look for:

I have a Login feature that should be used with all the rest of future features that I'm using with Cucumber and Selenium. This Login feature should concat with the rest of features.

This is mi Login.feature

Feature: Login Profile
  As an user of Page X
  I want to login my profile using my credentials
  In order to see the default dashboard

  Background: User navigates to Company home page
    Given I am on the Company login page

  @wip
  Scenario Outline: Successful login
    When I fill in User ID with "<username>"
    And I fill in Password with "<password>"
    And I click on the Log In button
    And I should get the Second code login with "<email>" and "<pass>"
    And I must put the Second code in the field code for accessing


    Examples:
      | username     | password | email              | pass    |
      | XXXXXXXX     | YYYYYYY  | ZZZZZZ@WWWWWW.com  | 1234556 |

I need to concat this feature with another new one without closing navigation in Selenium.

Could anybody guide me?


Solution

  • See In Cucumber, steps defined under Scenario/Outline with in one Feature file can not be reused in other Feature files.

    If you want to reuse login steps then you shall declare these under background in all those feature files where all scenarios shall reuse login steps written once under background in every feature file.

    Example

    Feature: Registration, Login and MyAccount
    Background: User is Logged In
    Given I am on the homepage
    And I follow "Sign in"
    @smoke
    Scenario: Verify Login Functionality
    When I fill "email address textbox" with "goswami.tarun77@gmail.com"
    Then I fill "password textbox" with "Test1234"