2017 © Pedro Peláez
 

library behat-variables

Store variables across Scenarios during Behat testing

image

rdx/behat-variables

Store variables across Scenarios during Behat testing

  • Thursday, November 16, 2017
  • by rudiedirkx
  • Repository
  • 3 Watchers
  • 3 Stars
  • 60,328 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 32 % Grown

The README.md

Behat Variables

Build Status Scrutinizer Code Quality, (*1)

Stores your custom variables across Scenarios during Feature testing., (*2)

The idea

You're making users and profiles to test, and you want to use those creations further in the same Feature. You can't, because: 1) Behat arguments are literals, and 2) FeatureContext lives only for every Scenario, not for the entire Feature., (*3)

With behat-variables, you can save & use those variables: user ids, passwords, activation tokens, etc., (*4)

Given a new user "Fred"           # Your custom step, with a return value
And I save it into "UID"          # A provided step that saves that return value
When I go to "/users/<<UID>>"     # Custom step, with dynamic argument
Then I should see "Hello, Fred!"  # Custom step, with predictable content

The <<UID>> part is the magic. Works for any argument, not just URIs., (*5)

Set up

In order to use variables in your Behat feature, you must do 2 things:, (*6)

  • Add the Feature Context class: rdx\behatvars\BehatVariablesContext
  • Add the Extension class: rdx\behatvars\BehatVariablesExtension

See the Behat docs for where they fit in behat.yml, or see this repo's behat.yml:, (*7)

default:
  suites:
    default:
      contexts:
        - rdx\behatvars\BehatVariablesContext
        - FeatureContext
  extensions:
      rdx\behatvars\BehatVariablesExtension: ~

And make sure your custom steps have a scalar return value, or an array of scalars:, (*8)

/**
 * @Given a value :value
 */
public function aValue($value) {
  return $value;
}

/**
 * @Given values :value1 and :value2
 */
public function valuesAnd($value1, $value2) {
  return [$value1, $value2];
}

Examples

See features/simple.feature for very simple examples (with only 3 custom steps). It's the test used to test this package., (*9)

Features

This package provides 1 step, in several formats:, (*10)

(I|we) save (it|that|those|them) into "VARIABLE_NAME"

So you can make several custom step combinations:, (*11)

Given "4" cars in the same shop                   # Custom
And we save those into "CAR1,CAR2,CAR3,CAR4"      # Provided

Given a user "Fred" in organization "McDonald's"  # Custom
And we save those into "USER,ORGANIZATION"        # Provided

The Versions

16/11 2017

dev-master

9999999-dev

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx

16/11 2017

1.2

1.2.0.0

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx

11/11 2017

1.1

1.1.0.0

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx

06/04 2016

1.0.3

1.0.3.0

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx

31/03 2016

1.0.2

1.0.2.0

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx

28/03 2016

1.0.1

1.0.1.0

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx

28/03 2016

1.0.0

1.0.0.0

Store variables across Scenarios during Behat testing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudie Dirkx