or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-handling.mdhooks.mdindex.mdparameter-transformation.mdruntime-context.mdstep-definitions.md

step-definitions.mddocs/

0

# Step Definitions

1

2

Core step definition annotations for writing BDD test steps in multiple languages. Cucumber-Java generates language-specific step definition annotations for over 70 languages, supporting both Cucumber expressions and regular expressions.

3

4

## Capabilities

5

6

### English Step Definitions

7

8

The most commonly used step definition annotations from the English language package.

9

10

```java { .api }

11

/**

12

* Step definition annotation for Given steps

13

* @param value Cucumber expression or regular expression pattern

14

*/

15

@Given("step text with {parameter}")

16

public void givenStep() { }

17

18

/**

19

* Step definition annotation for When steps

20

* @param value Cucumber expression or regular expression pattern

21

*/

22

@When("step text with {parameter}")

23

public void whenStep() { }

24

25

/**

26

* Step definition annotation for Then steps

27

* @param value Cucumber expression or regular expression pattern

28

*/

29

@Then("step text with {parameter}")

30

public void thenStep() { }

31

32

/**

33

* Step definition annotation for And steps

34

* @param value Cucumber expression or regular expression pattern

35

*/

36

@And("step text with {parameter}")

37

public void andStep() { }

38

39

/**

40

* Step definition annotation for But steps

41

* @param value Cucumber expression or regular expression pattern

42

*/

43

@But("step text with {parameter}")

44

public void butStep() { }

45

```

46

47

**Usage Examples:**

48

49

```java

50

import io.cucumber.java.en.*;

51

52

public class StepDefinitions {

53

54

// Cucumber expression with built-in parameter types

55

@Given("I have {int} cukes in my belly")

56

public void i_have_cukes_in_my_belly(int cukes) {

57

// Implementation

58

}

59

60

// Regular expression with capture groups

61

@When("^I eat (\\d+) cukes$")

62

public void i_eat_cukes(int cukes) {

63

// Implementation

64

}

65

66

// Step with custom parameter type

67

@Then("the date should be {date}")

68

public void the_date_should_be(LocalDate date) {

69

// Implementation using custom date parameter type

70

}

71

72

// Multiple annotations on same method

73

@Given("I am logged in")

74

@And("I have admin privileges")

75

public void user_setup() {

76

// Shared implementation

77

}

78

}

79

```

80

81

### Repeatable Annotations

82

83

Container annotations for multiple step definitions on a single method.

84

85

```java { .api }

86

/**

87

* Container for multiple @Given annotations

88

*/

89

@Given.Givens({

90

@Given("first condition"),

91

@Given("second condition")

92

})

93

public void multipleGivenConditions() { }

94

95

/**

96

* Container for multiple @When annotations

97

*/

98

@When.Whens({

99

@When("first action"),

100

@When("second action")

101

})

102

public void multipleWhenActions() { }

103

104

/**

105

* Container for multiple @Then annotations

106

*/

107

@Then.Thens({

108

@Then("first outcome"),

109

@Then("second outcome")

110

})

111

public void multipleThenOutcomes() { }

112

113

/**

114

* Container for multiple @And annotations

115

*/

116

@And.Ands({

117

@And("first additional step"),

118

@And("second additional step")

119

})

120

public void multipleAndSteps() { }

121

122

/**

123

* Container for multiple @But annotations

124

*/

125

@But.Buts({

126

@But("first exception"),

127

@But("second exception")

128

})

129

public void multipleButExceptions() { }

130

```

131

132

### International Step Definitions

133

134

Cucumber-Java generates step definition annotations for 70+ languages using their native Gherkin keywords.

135

136

**French (io.cucumber.java.fr)**:

137

```java { .api }

138

import io.cucumber.java.fr.*;

139

140

@Soit("j'ai {int} concombres")

141

public void j_ai_concombres(int nombre) { }

142

143

@Quand("je mange {int} concombres")

144

public void je_mange_concombres(int nombre) { }

145

146

@Alors("j'ai {int} concombres dans le ventre")

147

public void j_ai_concombres_dans_le_ventre(int nombre) { }

148

```

149

150

**German (io.cucumber.java.de)**:

151

```java { .api }

152

import io.cucumber.java.de.*;

153

154

@Angenommen("ich habe {int} Gurken")

155

public void ich_habe_gurken(int anzahl) { }

156

157

@Wenn("ich {int} Gurken esse")

158

public void ich_esse_gurken(int anzahl) { }

159

160

@Dann("habe ich {int} Gurken im Bauch")

161

public void habe_ich_gurken_im_bauch(int anzahl) { }

162

```

163

164

**Spanish (io.cucumber.java.es)**:

165

```java { .api }

166

import io.cucumber.java.es.*;

167

168

@Dado("que tengo {int} pepinos")

169

public void tengo_pepinos(int cantidad) { }

170

171

@Cuando("como {int} pepinos")

172

public void como_pepinos(int cantidad) { }

173

174

@Entonces("tengo {int} pepinos en la barriga")

175

public void tengo_pepinos_en_la_barriga(int cantidad) { }

176

```

177

178

### Available Language Packages

179

180

Cucumber-Java supports step definitions in the following languages:

181

182

| Language | Package | Keywords |

183

|----------|---------|----------|

184

| Arabic | `io.cucumber.java.ar.*` | وبالنظر إلى، عندما، ثم |

185

| Chinese (Simplified) | `io.cucumber.java.zh_cn.*` | 假如، 当, 那么 |

186

| Chinese (Traditional) | `io.cucumber.java.zh_tw.*` | 假設、當、那麼 |

187

| Dutch | `io.cucumber.java.nl.*` | Gegeven, Als, Dan |

188

| English | `io.cucumber.java.en.*` | Given, When, Then |

189

| French | `io.cucumber.java.fr.*` | Soit, Quand, Alors |

190

| German | `io.cucumber.java.de.*` | Angenommen, Wenn, Dann |

191

| Italian | `io.cucumber.java.it.*` | Dato, Quando, Allora |

192

| Japanese | `io.cucumber.java.ja.*` | 前提、もし、ならば |

193

| Korean | `io.cucumber.java.ko.*` | 조건、만일、그러면 |

194

| Portuguese | `io.cucumber.java.pt.*` | Dado, Quando, Então |

195

| Russian | `io.cucumber.java.ru.*` | Дано, Когда, Тогда |

196

| Spanish | `io.cucumber.java.es.*` | Dado, Cuando, Entonces |

197

198

And 50+ additional languages including Hindi, Thai, Vietnamese, Hebrew, Polish, Czech, and many others.

199

200

### Parameter Types

201

202

Step definitions support various built-in parameter types and custom parameter types:

203

204

**Built-in Types:**

205

```java

206

@Given("I have {int} items") // Integer parameter

207

@Given("I have {float} dollars") // Float parameter

208

@Given("I have {double} percentage") // Double parameter

209

@Given("I have {biginteger} points") // BigInteger parameter

210

@Given("I have {bigdecimal} score") // BigDecimal parameter

211

@Given("I have {byte} flags") // Byte parameter

212

@Given("I have {short} count") // Short parameter

213

@Given("I have {long} id") // Long parameter

214

@Given("I have {string} name") // String parameter (quoted)

215

@Given("I have {word} status") // String parameter (single word)

216

```

217

218

**Usage with Data Tables and Doc Strings:**

219

```java

220

@Given("the following users exist:")

221

public void users_exist(List<Map<String, String>> users) {

222

// users contains list of user data from table

223

}

224

225

@Given("the following JSON:")

226

public void json_data(String docString) {

227

// docString contains the raw JSON text

228

}

229

```