Cucumber BDD (Part 2): Creating a Sample Java Project with Cucumber, TestNG, and Maven

Thilina Ashen Gamage

CS Undergraduate and ML Researcher at University of Moratuwa, Software Engineer, Technology Evangelist, and Tech Blogger, https://platformengineer.com | https://ashenlive.com

You may also like...

6 Responses

  1. Rodrigo González says:

    Hi Thilina:

    Your tutorial is really good.
    The only thing is that I cannot generate the JSon reports.

    Could you please help me?

    • First of all, thanks a lot for taking your time to read through my blog post, Rodrigo! 🙂

      Can you please let me know how I can help you? If you can share the error log with your pom.xml, I can help you for sure.

  2. Rodrigo González says:

    Hi Thilina:

    This is my POM:

    4.0.0

    cl.coopeuch
    automation_test_cucumber
    1.0-SNAPSHOT
    jar

    1.2.5
    8

    info.cukes
    cucumber-java8
    ${cucumber.version}
    test

    info.cukes
    cucumber-jvm-deps
    1.0.5
    test

    info.cukes
    cucumber-testng
    1.2.5
    compile

    org.testng
    testng
    6.9.8
    test

    net.masterthought
    cucumber-reporting
    3.8.0

    org.seleniumhq.selenium
    selenium-api
    3.4.0
    test

    org.seleniumhq.selenium
    selenium-ie-driver
    3.4.0
    test

    junit
    junit
    4.12
    test

    org.seleniumhq.selenium
    selenium-support
    3.4.0
    test

    com.github.stephenc.monte
    monte-screen-recorder
    0.7.7.0

    org.apache.poi
    poi-ooxml
    3.16
    test

    info.cukes
    cucumber-junit
    ${cucumber.version}
    test

    com.google.guava
    guava
    21.0

    net.masterthought
    cucumber-sandwich
    0.0.4

    org.apache.maven.plugins
    maven-resources-plugin
    2.4

    org.apache.maven.plugins
    maven-surefire-plugin
    2.18.1

    testng.xml

    net.masterthought
    maven-cucumber-reporting
    2.0.0

    execution
    verify

    generate

    automation_test_cucumber
    target/cucumber-reports/advanced-reports
    target/cucumber-reports/CucumberTestReport.json
    42
    false

    org.apache.maven.plugins
    maven-compiler-plugin
    3.3

    1.${java.version}
    1.${java.version}

    • I don’t see any major issue in the pom file. Can you recheck whether you have followed these steps:

      1) AIn the TestRunner class, inside format option of @CucumberOptions, make sure you have included "json:target/cucumber-reports/CucumberTestReport.json" line. This is where we tell Cucumber on our expected result formats.
      2) If you are using an IDE, the project root and output directories could have been changed to different locations. So as a result, your JSon results might be generated in a different location. (E.g. If you are on Windows, and your project is in D://projects/QA/Cucumber/ directory, but your IDE has set the output path to D://, then your results will be generated in somewhere like D://target/cucumber-reports/…. Therefore please double check whether you have defined your paths correctly.

      If none of above steps work for you, I kindly suggest you to download my sample project mentioned in this tutorial: https://github.com/ashenwgt/awesome-bdd-with-cucumber, remove sample code snippets, add your test scripts, modify things as you need, and use it as you wish.

  3. Rodrigo González says:

    Hi Thilina:

    I changed the “format” with “plugin” in Runner class and it is working.
    Thanks!!!

    • Thilina Ashen Gamage says:

      Oh! I did a quick google search and found that “format” keyword is now deprecated. I’m really sorry for the inconvenience, mate. And many thanks for your feedback 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.