jeudi 30 janvier 2020

How to reuse steps definition of one feature file implementation in another one?

I am having the below folder structure

folder root
    features
         file1.feature
         file2.feature
    source
         file1.py
         file2.py

The implementation of file1.feature is in file1.py and file2.feature is in file2.py. I was trying to reuse a step in file1.feature in file2.feature. I tried importing the function directly in file2.py as below

from source.file2 import method1

However it resulted in the below error getting triggered

    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,
                    )
                )    pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: Given "User is logged-in". Line 6 in scenario "Scenario 1" in the feature "../Features/file1.feature

Is there any way to effectively reuse the steps of one feature file in another one

Aucun commentaire:

Enregistrer un commentaire