1

I am new to Python and Behave. I am trying to setup a POC for my automation project. I followed the tutorials from the behave document, but when i run behave, it throws steps are not detectable. What am i missing?

my folder structure looks like this.

/features/testone.feature
/features/steps/testone_steps.py

feature file

Feature: Running sample feature

@smoke @regression
Scenario: Login to github and verify it works in testone feature of scenario one
Given Launch GITHUB app with "test@test.com" and "githubtest"

step file

from behave import given, when, then, step

@given(u'Launch GITHUB app with "{text}" and "{text}"')
def step_impl(context, user, password):
    print(f"This is the given step with {user} and {password}")

output

λ behave
Feature: Running sample feature # features/testone.feature:1

  @smoke @regression
  Scenario: Login to github and verify it works in testone feature of scenario one  # features/testone.feature:4
    Given Launch GITHUB app with "test@test.com" and "githubtest"                   # None


Failing scenarios:
  features/testone.feature:4  Login to github and verify it works in testone feature of scenario one

0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 0 failed, 0 skipped, 1 undefined
Took 0m0.000s

You can implement step definitions for undefined steps with these snippets:

@given(u'Launch GITHUB app with "test@test.com" and "githubtest"')
def step_impl(context):
    raise NotImplementedError(u'STEP: Given Launch GITHUB app with "test@test.com" and "githubtest"')

i noticed in my vscode editer , in the steps file, the pylint shows this message.

[pylint] E0611:No name 'given' in module 'behave'
[pylint] E0611:No name 'when' in module 'behave'
[pylint] E0611:No name 'then' in module 'behave'
[pylint] E0611:No name 'step' in module 'behave'
mmar
  • 1,840
  • 6
  • 28
  • 41

1 Answers1

1

Your issue is that you're using the incorrect format in your step file. Try this:

from behave import given, when, then, step

@given(u'Launch GITHUB app with "{user}" and "{password}"')
def step_impl(context, user, password):
    print("This is the given step with {user} and {password}".format(user, password))

Notice that the parameter defined in the @given statement matches the parameter passed in the step_impl().

Namely, if in the @given, you have

@given(u'Launch GITHUB app with "{user}" and "{password}"')

then in your step implementation, you should have

def step_impl(context,user,password)

Without this match, and in your current code, you'll receive the NotImplementedError because behave is looking for a step implementation with context and text as parameters in your step file, i.e. def step_impl(context, text).

natn2323
  • 1,983
  • 1
  • 13
  • 30
  • Thank you, its working fine. I have one more question. As we are doing a POC with python and behave, we are looking for HTML report generation for the results. In java we had cucumbersandwitch reports library which prints a pretty good html reports with failure screenshot capturing, likewise in behave-python do we have any such html report library that we can use? i have googled, but could not find any good source. could you please help me on this? – mmar Jun 14 '18 at 15:24
  • No problem. I've found [Allure](http://allure.qatools.ru/) and [cucumber-html-reporter](https://www.npmjs.com/package/cucumber-html-reporter). This [StackOverflow post](https://stackoverflow.com/questions/40763066/how-to-generate-reports-in-behave-python) might help you out too. If you wanted to do it manually, you could make a POST request with your behave results at the end of your program and send it to your server's API endpoint for processing. – natn2323 Jun 14 '18 at 15:34