0

I am trying to run a test with ptest-bdd. I've used the scenario outline but the variable username is returning a name error saying that username is not defined. I would greatly appreciate a second pair of eyes on my code.

Here is the feature file:

@login

Feature: Valid Login
    As a employee,
    I want to login to my account
    So I can access the application

    Background: 
        Given the login page is displayed

    Scenario Outline: Manager enters correct login credentials and Ok button
        When the user enters their <username> and <password> correctly
        And the user clicks OK
        Then the page redirects to the manager home page

        Examples: Manager
            |   username            |   password                |
            | fake_name             | 1234                      |

And here is the test_login_steps.py code:

from pytest_bdd import scenarios, scenario, given, when, then, parsers
from pages.signin import QaSigninPage
from pages.managerHomepage import QaManagerHomepage
import pytest


CONVERTERS = {
    'username': str,
    'password': str,
}

scenarios('../features/login.feature', example_converters=CONVERTERS)

# Create Page Objects
@pytest.fixture(scope='session')
def pages(test_manager):
    pages={"signin_PAGE": QaSigninPage(test_manager.browser),
            "manager_home_PAGE": QaManagerHomepage(test_manager.browser)}
    return pages


# Given Steps
@given('the login page is displayed')
def login_visit(pages):
    pages["signin_PAGE"].load()

@when('the user enters their <username> and <password> correctly')
def enter_credentials(pages):
    pages["signin_PAGE"].enter_username(username)
    pages["signin_PAGE"].enter_password(password)
Jamie Kook
  • 81
  • 5

2 Answers2

0

I forgot to pass the variables into the function... I figured it out.

Jamie Kook
  • 81
  • 5
0

When you are using CONVERTERS use scenario in place of scenarios, which allows you to pass examples as parameters

Sandeep
  • 34
  • 4