Cucumber BDD with Selenium WebDriver and Testng Framework

Cucumber BDD with Selenium WebDriver and Testng Framework


Cucumber is a Behavior Driven Development (BDD) testing framework that helps the non technical members of the team can easily understand the scenario’s automating by testers. In Cucumber, the feature files plays very important role that contains plain English text written using gherkin language which is easy to understand. Refer to the Cucumber Basics

Cucumber-BDD using Page Object Model and Testng Framework:

1. Create a Maven Project with name as ‘cucumbermvn’. Refer to the steps->

http://total-qa.com/advanced-selenium/maven/

2. Add the following dependencies and plugins required for Cucumber,Selenium,Testng.
Refer to the dependencies for Cucumber – Java project


https://cucumber.io/docs/reference/jvm#java

3. Create a following Directory Structure for the project as mentioned below:

Cucumber - BDD,StepDefs,Selenium,Testng,Page Object Model,Maven

Cucumber – BDD,StepDefs,Selenium,Testng,Page Object Model,Maven

4. Refer to the Functional Tests OpenMRSTests.java as mentioned below:

5. Refer to the Step Definitions file LoginPage.java as mentioned below:

6. Feature file Login.feature contains the steps to be performed as part of the scenario:

7. Refer to the testng.xml file.

8. Execute the following maven command with Goals as verify to generate the Cucumber Reports.

mvn verify


Cucumber Reports,CucumberTestReport.json

Cucumber Reports,CucumberTestReport.json

5 comments on “Cucumber BDD with Selenium WebDriver and Testng Framework

  1. suprava

    suppose we have multiple feature file in same folder and if we want to run each one feature file without hard code in @cucumberoption then how to configure each feature file in testng.xml file.

    Reply
  2. total-qa

    Hi ,

    In the above example we have not hardcorded the feature file name.
    So it will pick all the feature files available under the features folder.
    features=”src/test/resources/features”

    Regards,
    total-qa.com

    Reply
  3. Minu Kumari

    I am using below dependencies getting error
    The method getCucumberFeature() is undefined for the type CucumberFeatureWrapper
    The method provideFeatures() is undefined for the type TestNGCucumberRunner
    Any specific reason why its not working
    @Test(groups = “cucumber”,dataProvider=”features”)
    public void test(CucumberFeatureWrapper wrapper) throws Exception {
    testRunner.runCucumber(wrapper.getCucumberFeature());
    }
    @DataProvider(name=”features”)
    public Object[][] getFeatures()
    {
    return testRunner.provideFeatures();
    }

    org.testng
    testng
    6.8

    org.seleniumhq.selenium
    selenium-java
    2.53.1

    io.cucumber
    cucumber-java
    4.2.6

    io.cucumber
    cucumber-testng
    4.2.6

    Reply
  4. Koushal Majeti

    i have created a same project i am encountering step_definitions.cstLogin.userWillProvideInformationForTheNewUserid(cstLogin.java:12)

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *