Steps
This module contains all step implementations needed to write a feature file that describes a locust
load test scenario for grizzly
.
A feature is described by using Gherkin. These expressions is then used by grizzly
to configure and
start locust
, which takes care of generating the load.
Feature: description of the test
Background: steps that are common for all (if there is multiple) scenarios
Given ...
And ...
Scenario: steps for a specific flow through a component in the target environment
Given ...
And ...
Then ...
When ...
In this package there are modules with step implementations that can be used in both Background
and Scenario
sections in a feature file.
Custom
Custom steps are implemented in your grizzly
project features/steps/steps.py
file. This is also the file that imports all grizzly
-defined step implementations.
There are examples of this in the Example.
Considerations
When writing step expressions, the following should be taken into consideration.
Class PermutationEnum
class PermutationEnum(Enum, metaclass=PermutationMeta)
Interface class for getting __vector__
value from the class that inherits it.
All objects used to represent possible values in step expressions and that has a registered custom parse
type should
inherit this class and set appropiate __vector__
values and make an implementation of from_string
. This is so
grizzly-ls
can make educated suggestions on possible step expressions.
vector
This class variable represents (x, y)
dimensions on how the values can expand in a step expression.
Consider the following Enum
, being mapped to a custom parse
type named FruitType
:
from behave import register_type
class Fruit(PermutationEnum):
__vector__ = None # see examples below
BANANA = 0
APPLE = 1
ORANGE = 2
@classmethod
def from_string(cls, value: str) -> Fruit:
return cls[value.upper()]
register_type(
FruitType=Fruit.from_string,
)
None
Variable occurs 1..N
times in the expression
When permutated, it will only produce one step expression and all instances of the variable in the expression will have been replaced with nothing.
Then I want to eat a "{fruit:FruitType}" # -->
Then I want to eat a ""
Then I want to eat a "{fruit1:FruitType}" and a "{fruit2:FruitType}" # -->
Then I want to eat a "" and a ""
(False, True)
Variable occurs 1
time in the expression.
When permutated, it will produce the number of step expressions as values in the enum.
Then I want to eat a {fruit:FruitType} # -->
Then I want to eat a banana
Then I want to eat a apple
Then I want to eat a orange
(True, False)
Variable occurs 2..N
times in the expression.
When permutated, combination of all enum values will be produced, if the variable type occurs the same number of times as values in the enum.
Then I want to eat a {fruit1:FruitType}, a {fruit2:FruitType} and a {fruit3:FruitType} # -->
Then I want to eat a banana, a apple and a orange
(True, True)
Variable occurs 2..N
times in the expression, and should produce more than one combination of the step expression.
Then I want to eat a {fruit1:FruitType}, a {fruit2:FruitType} and a {fruit3:FruitType} # -->
Then I want to eat a banana, a apple and a orange
Then I want to eat a apple, a banana and a orange
Then I want to eat a orange, a banana and a apple
Class permutation
class permutation()
Decorator used to annotate parse
methods that are not using Class PermutationEnum as a base.
This could be for example parse methods that uses regular expressions via parse.with_pattern
.
import parse
from behave import register_type
from grizzly_extras.text import permutation
@parse.with_pattern(r'(hello|world)')
@permutation(vector=(True, True))
def parse_hello_world(text: str) -> str:
return text.strip()
register_type(
HelloWorldType=parse_hello_world,
)
See vector for an explanation of possible values and their meaning.