You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: general/development/tools/behat/writing.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -264,6 +264,70 @@ Sometimes, you will need to set up data that is specific to your plugin, or perf
264
264
265
265
As well as creating completely new steps, you can also extend some of the standard steps:
266
266
267
+
#### Calling other steps
268
+
269
+
When writing custom steps you will often want to perform actions, such as:
270
+
271
+
- clicking a link
272
+
- pressing a button
273
+
- typing into a field
274
+
- calling another existing step
275
+
276
+
When doing this you **should** use the `\behat_session_trait::execute()` method to call the existing step to perform the action.
277
+
You **should not** call the `->click()` method on a `NodeElement` manually as this will bypass some of the error detection states, and pausing to wait for JavaScript actions to take place.
278
+
279
+
The `\behat_session_trait::execute()` method accepts:
280
+
281
+
- the name of the method to call on a behat context class; and
282
+
- any arguments.
283
+
284
+
For example:
285
+
286
+
```php title="behat_general.php"
287
+
/**
288
+
* Toggles the specified admin switch.
289
+
*
290
+
* @When /^I toggle the "(?P<element_string>(?:[^"]|\\")*)" admin switch "(?P<state_string>on|off)"$/
291
+
* @param string $element Element we look for
292
+
* @param string $state The state of the switch
293
+
* @throws ElementNotFoundException Thrown by behat_base::find
294
+
*/
295
+
public function i_toggle_admin_switch($element, $state) {
296
+
// First check we are running Javascript, otherwise explode.
297
+
if (!$this->running_javascript()) {
298
+
throw new \Behat\Mink\Exception\DriverException('Switches are only available with JavaScript enabled');
0 commit comments