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