I've been spending hours with ChatGPT trying to get this to run, but I'm running into the same errors again and again.
My project is a fresh, simple java/kotlin project, with Selenium and Cucumber. (Maven.) I'm trying just to get a simple test (feature file and step definition to run), without luck.
Here's my project setup:
project
- cucumber (module)
- src
- main
- java (nothing here, as I'm using "test" instead of "main")
- resources (nothing here, as I'm using "test" instead of "main")
- test
- java
- e2e
- setup
- Hooks.kt
- RunCucumberTest
- testdefinitions
- TestStepDefinitions.kt
- resources
- features
- testfeature.feature
Hooks.kt:
package e2e.setupimport io.cucumber.java.Afterimport io.cucumber.java.Beforeimport org.openqa.selenium.WebDriverimport org.openqa.selenium.chrome.ChromeDriverimport io.github.bonigarcia.wdm.WebDriverManagerclass Hooks { companion object { lateinit var driver: WebDriver } @Before fun setUp() { WebDriverManager.chromedriver().setup() driver = ChromeDriver() driver.manage().window().maximize() } @After fun tearDown() { driver.quit() }}
RunCucumberTest.kt:
package e2e.setupimport io.cucumber.junit.Cucumberimport io.cucumber.junit.CucumberOptionsimport org.junit.runner.RunWith@RunWith(Cucumber::class)@CucumberOptions( features = ["src/test/resources/features"], glue = ["e2e.testdefinitions"], plugin = ["pretty", "html:target/cucumber-reports"])class RunCucumberTest
TestStepDefinitions.kt:
package e2e.testdefinitionsimport io.cucumber.java.en.Givenimport io.cucumber.java.en.Thenimport io.cucumber.java.en.Whenimport e2e.setup.Hooksimport org.openqa.selenium.Byimport org.junit.Assert.assertTrueclass StepDefinitions { @Given("I open the browser and go to the Google homepage") fun i_open_the_browser_and_go_to_the_google_homepage() { Hooks.driver.get("https://www.google.com") } @When("I search for {string}") fun i_search_for(searchQuery: String) { Hooks.driver.findElement(By.name("q")).sendKeys(searchQuery) Hooks.driver.findElement(By.name("q")).submit() } @Then("the page title should start with {string}") fun the_page_title_should_start_with(titleStartsWith: String) { assertTrue(Hooks.driver.title.startsWith(titleStartsWith)) }}
testfeature.feature:
Feature: Google SearchScenario: Searching on Google Given I open the browser and go to the Google homepage When I search for "Selenium WebDriver" Then the page title should start with "Selenium WebDriver"
The project builds fine, and the libraries and dependencies all seem to be right.
But when I try running the scenario in the feature file, I get this error:
Before All/After All failedio.cucumber.core.backend.CucumberBackendException: Please annotate a glue class with some context configuration.For example: @CucumberContextConfiguration @SpringBootTest(classes = TestConfig.class) public class CucumberSpringConfiguration { }Or: @CucumberContextConfiguration @ContextConfiguration( ... ) public class CucumberSpringConfiguration { } at io.cucumber.spring.SpringFactory.start(SpringFactory.java:102) at io.cucumber.core.runner.Runner.buildBackendWorlds(Runner.java:134)
The examples doesn't tell me much, since I'm not well versed with Spring.
But as far as I can see, my glue and features specifications are correct? But obviously not, or not according to IntelliJ.