# Cucumber-JVM setup

> Emit Cucumber JSON from a JVM runner and keep browser steps discoverable for KwikQA repair and validation.

Use Cucumber's `json` plugin. For repair and validation, KwikQA needs a failing step that names its JVM definition and a scenario whose code reaches Selenium, Selenide, Playwright for Java, or Appium. Cucumber-JS and non-browser scenarios can be diagnosed from their reports.

For validation, [prepare the JDK and Maven or Gradle build](https://kwikqa.com/docs/frameworks/java/#prerequisites) on macOS or Linux. The CLI's `--capture` flag applies to the JavaScript browser runners.

## Write Cucumber JSON

In a JUnit Platform project, add a suite class to `src/test/java/example/checkout/RunCucumberTest.java`. Use `io.cucumber:cucumber-java`, `io.cucumber:cucumber-junit-platform-engine`, and `org.junit.platform:junit-platform-suite` as test dependencies. Cucumber-JVM 8 needs a JSON library on the test classpath, for example `tools.jackson.core:jackson-databind`. The example uses Cucumber-JVM 8.0.4, JUnit Platform 6.1.3, and Jackson Databind 3.2.4. Use versions compatible with the rest of your test build.

```
package example.checkout;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;

import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "example.checkout.steps")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty,json:target/cucumber/cucumber.json")
public class RunCucumberTest {}
```

Place your feature files in `src/test/resources/features`. For Maven, run `./mvnw test` with the configuration above. With Gradle, configure the test task to use the JUnit Platform, change the plugin destination to `json:build/cucumber/cucumber.json`, and run `./gradlew test`. If your project already sets `cucumber.plugin`, append the JSON plugin there.

## Make browser steps visible in source

Keep the step definition and the page object it calls in source roots KwikQA can inspect. This example keeps both classes under `src/test/java`. Selenium appears in the page object's imports, so KwikQA can follow the step's call to a browser library.

```
// src/test/java/example/checkout/steps/CheckoutSteps.java
package example.checkout.steps;

import io.cucumber.java.After;
import io.cucumber.java.en.When;

public class CheckoutSteps {
  private final CheckoutPage checkout = new CheckoutPage();

  @When("I apply a coupon at checkout")
  public void applyCoupon() {
    checkout.applyCoupon();
  }

  @After
  public void closeBrowser() {
    checkout.close();
  }
}
```

```
// src/test/java/example/checkout/steps/CheckoutPage.java
package example.checkout.steps;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class CheckoutPage {
  private final WebDriver driver = new ChromeDriver(new ChromeOptions().addArguments("--headless=new"));

  public void applyCoupon() {
    driver.get("http://localhost:3000/checkout");
    driver.findElement(By.cssSelector("[data-testid=apply-coupon]")).click();
  }

  public void close() {
    driver.quit();
  }
}
```

Set the URL to your test app and keep your normal driver lifecycle and scenario assertions. A step with a missing definition or a helper KwikQA cannot resolve may leave the scenario diagnose-only. The Cucumber JSON report records each scenario's final attempt.

## Analyze a failing scenario

```
npx kwikqa analyze --report target/cucumber/cucumber.json --html
```

Pass the Gradle report path if you use Gradle. Add `--local` to group failures without an account. Use the same `--report` path when running `kwikqa fix`. For an eligible scenario, continue with [your first repair](https://kwikqa.com/docs/first-repair/). See [Cucumber's reporter documentation](https://cucumber.io/docs/cucumber/reporting/) for other plugins.

---

Source: https://kwikqa.com/docs/frameworks/cucumber-jvm/, updated 2026-11-27
