Questions tagged [python-behave]

Behave is a BDD framework for Python, based on the Cucumber Framework.

Behave is Behaviour Driven Development (BDD) framework for Python. It follows the Gherkin syntax, which defines Scenarios and steps files.

A scenario is a human readable flow, for example:

Scenario: Calling the metadata API
   Given A matching server
   When I call metadata
   Then metadata response is JSON
   And response status code is 200

The steps file casts programmatic meaning to each line, for example:

...
@then('response status code is {expected_status_code}')
def step_impl(context, expected_status_code):
    assert_equals(context.response.status_code, int(expected_status_code))

@then('metadata response is JSON')
def step_impl(context):
    json.loads(context.metadata_response.data)
...

Behave combines the scenario and steps to a test report:

enter image description here

521 questions
10
votes
4 answers

Handling Exceptions in Python Behave Testing framework

I've been thinking about switching from nose to behave for testing (mocha/chai etc have spoiled me). So far so good, but I can't seem to figure out any way of testing for exceptions besides: @then("It throws a KeyError exception") def…
Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
10
votes
4 answers

How can I get code coverage data from Python BDD functional tests using Behave?

I haven't seen an answer for this specific question (Test coverage tool for Behave test framework) and I haven't seen any Google search results produce a sufficient answer. Therefore... How can I get a code coverage report from Behave? I find it…
fenreer
  • 195
  • 1
  • 2
  • 8
9
votes
3 answers

Debugging python-behave steps with Pycharm

I'm using Pycharm to write tests and running them with behave. I'm running the behave commands with cli. To write the features and scenarios i'm using Pycharm. How can i debug each step?
Shizzle
  • 961
  • 3
  • 10
  • 27
9
votes
3 answers

How to retry failed scenario in Behave using python

Can someone please tell me how I can run a failed test again in Behave using Python? I want to re-run the failed test case automatically if it fails.
Eswar
  • 127
  • 2
  • 6
9
votes
1 answer

Run python behave from python instead of command line

Is there any way to run python behave from within python and not via command line? default usage: run behave command in base folder with features/steps desired usage: call a function (or have a certain import) which executes the behave tests in a…
dreamflasher
  • 1,387
  • 15
  • 22
9
votes
4 answers

Define the order of scenarios (or required scenario) with behave (python)

I'm using behave to test my little Django app. I've already created the file user_management.feature that contains also this Scenario: Scenario: register Given I can access registration form When I put "doctor" in "username" field And I put…
greenkey
  • 383
  • 3
  • 11
9
votes
1 answer

Test coverage tool for Behave test framework

We are using Behave BDD tool for automating API's. Is there any tool which give code coverage using our behave cases? We tried using coverage module, it didn't work with Behave.
user3374477
  • 91
  • 1
  • 3
8
votes
1 answer

How can I pass an object like a list or dictionary in python behave .feature file

How can I pass an object like a list or dictionary as an argument in behave .feature file so I can use that argument in my python function step? See an example of what I'm trying to achieve below: Feature: Scenario: Given the inputs below Given…
tfalade
  • 101
  • 2
  • 5
7
votes
6 answers

How to generate reports in Behave-Python?

For Java there are external report generation tools like extent-report,testNG. The Junit produces the xml format output for individual feature file. To get a detailed report, I don't see an option or wide approach or solution within the Behave…
Ashok kumar Ganesan
  • 1,098
  • 5
  • 20
  • 48
7
votes
1 answer

How to get the current behave step with Python?

I'm using behave with Python to do my tests. In the step file, I want to get the current step name, because if the test fails, I take a screenshot and rename the file to the step name. Something like this: Given user is logged in When user does…
Lucas Mello
  • 342
  • 3
  • 8
7
votes
3 answers

Adding common attributes to a Behave method

Using the great Behave framework, but having trouble with my lack of OOP skills. Behave has an inbuilt context namespace where objects can be shared between test execution steps. After initializing my WebDriver session, I keep passing it between my…
ljs.dev
  • 4,449
  • 3
  • 47
  • 80
6
votes
5 answers

Define a Behave step that works for multiple keywords (e.g. Given, When, and Then)

Is there a way to write a step that works for multiple keywords. Like say my feature is: Scenario: Something happens after navigating Given I navigate to "/" And say some cookie gets set When I navigate to "/some-other-page" Then…
Cynic
  • 6,779
  • 2
  • 30
  • 49
6
votes
1 answer

How to Mock In a BDD Steps File

I would like to mock behaviour of the os.path.exists method so that I can verify if my script behaves correctly when os.path.exists reports that the file/folder does not exist. @when("Service starts with input file that does not exist") def…
Craig
  • 2,286
  • 3
  • 24
  • 37
6
votes
1 answer

Integrating Behave or Lettuce with Python unittest

I'm looking at BDD with Python. Verification of results is a drag, because the results being verified are not printed on failure. Compare Behave output: AssertionError: File "C:\Python27\lib\site-packages\behave\model.py", line 1456, in run …
Frank Kusters
  • 2,544
  • 2
  • 21
  • 30
6
votes
2 answers

Sending Keys Using Splinter

I want to test an autocomplete box using Splinter. I need to send the 'down' and 'enter' keys through to the browser but I'm having trouble doing this. I am currently finding an input box and typing 'tes' into that box…
lukeaus
  • 11,465
  • 7
  • 50
  • 60
1
2
3
34 35