0

When starting my Cucumber tests (both via Selenium and integration/rest), the Spring Boot (Test) application is not started automatically.

How can I configure the Cucumber start the Spring Boot application (as well)?

I tried many ways. My files are:

Cucumber main starter:

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/cucumber_integration_tests")
public class Cucumber_Integration_Test {
}

The glue code file is something like:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration
@IntegrationTest
public class StepDefsIntegrationTest extends SpringIntegrationTest {
    @When("^the client calls /version$")
    public void the_client_issues_GET_version() throws Throwable {
        executeGet("http://localhost:8080/version");
    }
    etc. 
}

Alternative way of starting the application in the glue code file:

@SpringBootTest( properties = "server.port=8080", classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class wine_Cucumber_Selenium_Steps {
    private WebDriver driver;
    private String baseUrl = "http://localhost";

    private int port = 8080;

    @Given("^I visit the wine cellar home page$")
    public void goToWineCellarHomePage() {
        // Firefox
        // System.setProperty("webdriver.gecko.driver", "K:\\k_schijf\\download_via_firefox\\geckodriver-v0.11.1-win64\\geckodriver.exe");
        // driver = new FirefoxDriver();

        // Chrome
        System.setProperty("webdriver.chrome.driver", "K:\\k_schijf\\download_via_firefox\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        baseUrl += ":" + port;
        driver.navigate().to(baseUrl + "/index.html");
    }

Diagnose:

  • I don't see Spring started with a message
  • I get the error message "ResourceAccessException: I/O error on GET request for "http://localhost:8080/version": Connection refused"

2 Answers 2

4

You might want to use @ContextConfiguration with @SpringBootTest annotation. I have cucumber tests working example here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for sharing your code. I tried to put the ContextConfiguration/SpringBoot at the Cucumber runtest, but it doesn't work yet. Do you have a working Cucumber, Selenium, Spring Boot example?
Your solution works when I add the \@ContextConfiguration with \@SpringBootTest annotations besides the Cucumber Defined Steps!! It even works when doing the Cucumber, Selenium, Spring Boot tests!! When put (only) besides the runtest, it doesn't work.
2

Thank you @ravinikam for showing a good direction. I will experiment further with the combination of ContextPath & SpringBootTest.

An answer (maybe not the best) is that I used the 1.2.4 version of Cucumber and added this code to the runTest of Cucumber. That worked.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
@WebIntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
public @interface CucumberStepsDefinition {
}

Another idea was given by Bealdung: see this short example of an integration test.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.