Is there any way to declare a variable in a feature file to then use in a cucumber test? Something like this:
myFile.feature
Given whenever a value is 50
myFile.java
@Given("^whenever a value is 50$")
public void testing(value) {
assertEqual(value, 50);
}
Honestly, I don't even know what this would look like. But I would love to not have to declare a value in both the feature file AND the Cucumber test. Thanks!
Yes you can! Write the Given-step in the feature.
Feature: foobar
Scenario: something
Given whenever a value is 50
Then run it as a JUnit test. You will see something like this in the console.
@Given("^whenever a value is (\\d+)$")
public void whenever_a_value_is(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Then you can copy+paste it and change it to:
@Given("^whenever a value is (\\d+)$")
public void whenever_a_value_is(int value) {
assertEquals(value, 50);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.