Behave – Step Parameters

Behave - Step Parameters

We can have Behave-Step parameters within the step names.

Behave step Parameters use matcher (name)

Modify the parameter matcher in parsing the step text. There are multiple in-built parsers present in Behave, as explained below โˆ’

  • parseย โˆ’ It gives an easy parser that restores regular expression for the step parameters with plain syntax. For example, {parameter: type}. It allows type conversion with type converters.
  • cfparseย โˆ’ It has the Cardinality Field (CF) support. It can support the below parse expressions โˆ’{values:Type+} โ€“ Cardinality=1..N, many{values:Type*} โ€“ Cardinality=0..N, many0{values:Type?} โ€“ Cardinality=0..1, optionalIt allows type conversion with type converters.
  • reย โˆ’ It utilises the complete regular expressions to parse the clause. We have to take the help of the named groups (? P<name>โ€ฆ) to declare variables obtained from the text and then feed it to the step ().

We can have our customized matcher along with new data types with the help of the register_type method.

behave.register_type(w)

Registers a user-defined type for parsing during type conversion at the time of step matching.

class behave.matchers.Matcher(func, pattern ,step_type=None)

It extracts the parameters out of step names.

  • pattern โˆ’ The pattern matching associated with the step function.
  • func โˆ’ The pattern is associated with the step function.
  • check_match(step) โˆ’ To match with the step name provided.
  • describe(schema=None) โˆ’ Give description in form of text of the function or matcher object.
  • regex_pattern: Yields the utilised textual regex expression.

class behave.model_core.Argument(start, end, original, value, name=Name)

The attributes are as follows โˆ’

  • original โˆ’ The original text which is matched in the name of the step.
  • value โˆ’ The value of the argument which is type converted.
  • name โˆ’ The argument name.
  • start โˆ’ The starting index of the argument in step name.
  • end โˆ’ The ending index of the argument in step name.

class behave.matchers.Match(func, arguments=None)

A step in the feature file is parameter decorator parameters.

The attributes are as follows โˆ’

  • func โˆ’ The step function which is applicable to the given match.
  • arguments โˆ’ The argument list the instances having the matched parameter obtained from the name of the step.

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply