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.setup
import io.cucumber.java.After
import io.cucumber.java.Before
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import io.github.bonigarcia.wdm.WebDriverManager
class 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.setup
import io.cucumber.junit.Cucumber
import io.cucumber.junit.CucumberOptions
import 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.testdefinitions
import io.cucumber.java.en.Given
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import e2e.setup.Hooks
import org.openqa.selenium.By
import org.junit.Assert.assertTrue
class 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 Search
Scenario: 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 failed
io.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.