Coder Social home page Coder Social logo

viveksingh7340 / cucumber-jvm-testng-integration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sahajamit/cucumber-jvm-testng-integration

0.0 1.0 0.0 37.11 MB

cucumber-jvm-testng-integration

License: Apache License 2.0

Java 92.63% Gherkin 7.37%

cucumber-jvm-testng-integration's Introduction

Integration of Cucumber-JVM and TestNG

Cucumber-JVM has native integration with Junit and it uses Junit as a test runner. But if you want to integrate TestNG with Cucumber-JVM then there is no proper documentation available to do this. So I decided to create a sample project where I can demonstrate this integration along with some better reporting.

Basic Integration

To have a simple integration you just need to create a runner class and just extend it from AbstractTestNGCucumberTests.

###Here is the basic code:

package com.cucumber.testng.examples;

import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;

/**
 * Created by amit.rawat on 21/12/15.
 */
public class BaseStepDefs {
    @Before()
    public void before(Scenario scenario) {
        scenario.getId();
        System.out.println("This is before Scenario: " + scenario.getName().toString());
    }

    @After
    public void after(Scenario scenario) {
        System.out.println("This is after Scenario: " + scenario.getName().toString());
    }
}

If you will run this java file as a testNG class file then it will simply pick the features mentioned in the @CucumberOptions. We can point to a folder here with multiple feature files or we can point to a specific feature file. For Reporting, we are using the native cucumber-jvm reports which will generate a cucumber1.json file and will also generate a pretty html file.

Advanced Integration

To have full-fledged integration with TestNg where you can use testng xml along with parallel execution. Please refer these files: /testng.xml /src/test/java\com/cucumber/testng/examples/RunCukesByCompositionGrp1_Test1.java /src/test/java\com/cucumber/testng/examples/RunCukesByCompositionGrp1_Test2.java

###Here is the sample code:

@CucumberOptions(features = "src/test/resources/com.cucumber.testng.examples/date_calculator1.feature", 
plugin = "json:target/cucumber2.json")
public class RunCukesByCompositionGrp1_Test2 {
    @Test(groups = "examples-testng", description = "Example of using TestNGCucumberRunner to invoke Cucumber")
    public void runCukes() {
        new TestNGCucumberRunner(getClass()).runCukes();
    }
}

Here we are creating a test method that will be invoked by TestNG and invoke the Cucumber runner within that method. So this test method can point to a group of features and will generate a dedicated results json file. Similarly we can have another similar file "RunCukesByCompositionGrp1_Test2.java" which will point to a different batch of features. This way we can run this both groups of features parallelly using testng.xml.

To see this whole thing running simply checkout this projecy and run this command:

mvn clean test

cucumber-jvm-testng-integration's People

Contributors

sahajamit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.