Manwlis.e
Manwlis.e

Reputation: 192

How to load a value from . properties file in Cucumber-jvm step class

I have written a cucumber integration tests and it is running ok.

And then i wanted some class variables from the step.java to get their values from .properties values

public class cucumberStepClass { 
    @Value("${value.from.propertiesfile}")
    private String variable
//rest of integration test
}

Does anyone know how can i inject those values so my test can use them?

Upvotes: 8

Views: 14545

Answers (2)

Mykola Gurov
Mykola Gurov

Reputation: 8695

Have you enabled integration with spring dependency injection? You need to add the cucumber-spring dependency for that. See https://docs.cucumber.io/cucumber/state/#spring

Upvotes: 4

WesternGun
WesternGun

Reputation: 12728

To add my two cents to the first answer: remember to annotate the class with @SpringBootTest and @TestPropertySource("classpath:test.properties"). And the properties file should be .properties extension or .xml. .yml cannot be loaded.

Upvotes: 2

Related Questions