2

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 "[email protected]" 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 "[email protected]" 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 "[email protected]" and "githubtest"')
def step_impl(context):
    raise NotImplementedError(u'STEP: Given Launch GITHUB app with "[email protected]" 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'
1
  • @musikreck i tried all ways as you said, still see the same issues. Commented Jun 13, 2018 at 21:46

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

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?
No problem. I've found Allure and cucumber-html-reporter. This StackOverflow post 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.