Search code examples
pythonpython-behave

"from behave import *" is not allowing me to use given when then etc to define steps


from behave import *
import time

DEFAULT_EMAIL = ""
DEFAULT_PASSWORD = ""

@given("unauthenticated user loads the home page")
def step_impl(context):
    assert context.is_sign_in_submit_displayed()

@step("sign-in button is clicked")
def step_impl(context):
    context.login_page = context.login.click_sign_in_submit()

@when("login form is populated with valid credentials")
def step_impl(context):
    context.enter_email(DEFAULT_EMAIL)
    context.enter_password(DEFAULT_PASSWORD)

@then("login is successful")
def step_impl(context):
    assert context.home_page.is_rewards_displayed()
    assert context.home_page.is_account_displayed()

Does the behave import not define given when then etc? I am seeing the following errors just from this snippet so far:

{
Undefined variable 'given'
Undefined variable 'step'
Undefined variable 'when'
Undefined variable 'then'
}

Solution

  • This was solved by installing using pip3 rather than pip.