Search code examples
cucumber-jvmgherkincucumberjs

Run Feature file with different login


Here we need to run the same feature file with different login and provide login user name from tags.

Run the feature file with user1 and user2

@user1 @user2

Feature: Feature-1

Background : 
 Given I am login with user

Scenario: 

Scenario:

Run the feature file with user1

@user1 

Feature: Feature-2

Background : 
 Given I am login with user

Scenario: 

Scenario:

Solution

  • Use Scenario Outline concept of gherkin language where you can pass user name and password as a Example. For ex:

    -- Feature file
    
    Scenario Outline: Verify Login Functionality
      Given There is a user "<username>" and <password>"
       When I login to the application
    Examples:
    |username|password|
    |user1|pass1|
    |user2|pass2|
    
    -- Spec file
    
    Given(/^There is a user (.*) and (.*)$/, async function(username, password) {
        driver.findElement(Locator to identify the username element).sendKeys(username);
        driver.findElement(Locator to identify the password element).sendKeys(password);
    });
    

    Here, same test scenario written above will be repeated for two different users. Take these two regular expressions as a parameter in spec file and send it to username and password text fields using selenium