Setting up an IntelliJ, Java/Maven and Cucumber, Selenium project

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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật