How to write cucumber Step definitions in python

前端 未结 2 634
南旧
南旧 2021-01-12 06:43

I am new to the Cucumber framework. I am trying to make Cucumber work with Python. I have written the feature file and want to know how to write the step definitions in Pyth

2条回答
  •  太阳男子
    2021-01-12 07:17

    Check out behave, behaviour-driven development library, Python style.

    Behavior-driven development (or BDD) is an agile software development technique that encourages collaboration between developers, QA and non-technical or business participants in a software project. We have a page further describing this philosophy.

    behave uses tests written in a natural language style, backed up by Python code.

    It doesn't use Cucumber, but you can reuse .feature files because they use the same Gherkin language.

    Sample behave's step definition:

    from behave import *
    
    @given('we have behave installed')
    def step_impl(context):
        pass
    
    @when('we implement a test')
    def step_impl(context):
        assert True is not False
    
    @then('behave will test it for us!')
    def step_impl(context):
        assert context.failed is False
    

提交回复
热议问题