Multiple Captures

You don’t have to stop at capturing just a single argument. Cucumber will pass an argument to your block for every capture group in your regular expression, so you can grab as many details as you like from a step.

Here’s an example. Let’s imagine our bank wants to start offering its customers savings accounts as well as their regular checking account. Customers can use the ATM to transfer money between their accounts. Here’s one of the scenarios for this new feature:

 Scenario​: Transfer funds from savings into checking account
  Given I have deposited $10 in my Checking Account
  And I have deposited $500 in my Savings Account
  When I transfer $500 from my Savings Account into my Checking Account
  Then the balance of ...

Get The Cucumber Book, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.