samedi 1 février 2020

pytest_bdd.exceptions.StepDefinitionNotFoundError error is getting triggered on using parsers.re in StepDefinition

pytest_bdd.exceptions.StepDefinitionNotFoundError error is getting triggered on using parsers.re in StepDefinition.

I have used the below feature file

Feature: Login Page

Scenario: Opening Login page and logging in
        Given URL is created
        When User is opening the login page and entering the details
        Then User is logged in

    Scenario: Opening Login page and registering
        Given URL is created
        When User is opening the login page and registering
        Then User is logged in

For the step definition, I have tried using parsers.re as shown below to reuse the steps. (scenario, given and then is not pasted to keep the details crisp).

from pytest_bdd import scenario, given, when, then, parsers
import re

@when(parsers.re(r'User is opening the login page (?P<login_type>[a-zA-Z]+)'), converters = dict(login_type = str))
def login(login_type):
    return logging_in("name", login_type)

However, I have encountered the below error.

request = <FixtureRequest for <Function 'login'>>
step = <pytest_bdd.feature.Step object at 0x103ddd128>
scenario = <pytest_bdd.feature.Scenario object at 0x103dcbf98>
encoding = 'utf-8'

    def _find_step_function(request, step, scenario, encoding):
        """Match the step defined by the regular expression pattern.

        :param request: PyTest request object.
        :param step: Step.
        :param scenario: Scenario.

        :return: Function of the step.
        :rtype: function
        """
        name = step.name
        try:
            # Simple case where no parser is used for the step
            return request.getfixturevalue(get_step_fixture_name(name, step.type, encoding))
        except pytest_fixtures.FixtureLookupError:
            try:
                # Could not find a fixture with the same name, let's see if there is a parser involved
                name = find_argumented_step_fixture_name(name, step.type, request._fixturemanager, request)
                if name:
                    return request.getfixturevalue(name)
                raise
            except pytest_fixtures.FixtureLookupError:
                raise exceptions.StepDefinitionNotFoundError(
                    u"""Step definition is not found: {step}."""
                    """ Line {step.line_number} in scenario "{scenario.name}" in the feature "{feature.filename}""".format(
                        step=step,
                        scenario=scenario,
>                       feature=scenario.feature,
                    )
                )
E               pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: When "User is opening the login page and entering the details". Line 8 in scenario "Opening Login page and logging in" in the feature "../Features/login.feature

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest_bdd/scenario.py:98: StepDefinitionNotFoundError
========================== 1 failed in 29.21 seconds ===========================

Is there something wrong with the way in which parsers are used with re resulting in the error?

Aucun commentaire:

Enregistrer un commentaire