How to resolve problem with catching data from yaml in steps.py in pytest-bdd. In other part of framework, everything works as it should. I have class:
class Globals:
TITLE = None
USERNAME1 = None
LAST_NAME1 = None
PASSWORD1 = None
WRONG_PASSWORD = None
EMAIL1 = None
BDAY = None
BMONTH = None
BYEAR = None
def __init__(self, path):
self.load_data_from_yaml(path)
def load_data_from_yaml(self, path):
with open(path, "r") as param_file:
try:
yaml_file = yaml.safe_load(param_file)
self.TITLE = yaml_file.get("title1")
self.USERNAME1 = yaml_file.get("username1")
self.PASSWORD1 = yaml_file.get("password1")
self.WRONG_PASSWORD = yaml_file.get("wrong_password")
self.LAST_NAME1 = yaml_file.get("lastname1")
self.EMAIL1 = yaml_file.get("email1")
self.BDAY = yaml_file.get("bday")
self.BMONTH = yaml_file.get("bmonth")
self.BYEAR = yaml_file.get("byear")
except yaml.YAMLError as exc:
print(exc)
def get_yaml_element(self, element):
return getattr(self, element, None)
and scenario:
Scenario Outline: Login to the website
Given Navigate to login page
When I enter my login and "<password>"
And I click the login button
Then I should get login alert
Examples:
| password |
| PASSWORD1 |
| WRONG_PASSWORD |
and step:
@when('I enter my login and <password>')
def step_when_enter_credentials(webdriver_initializer, password):
driver = webdriver_initializer
selenium_elements = Page(driver)
globals_instance = Globals(PARAMS_PATH)
password_to_use = globals_instance.get_yaml_element(password)
selenium_elements.type_into(selenium_elements.EMAIL_ADDRESS_REGISTER_VALUE, selenium_elements.globals.EMAIL1)
selenium_elements.type_into(selenium_elements.EMAIL_PASSWORD, password_to_use)
besides steps.py globals_instance work as it should be but in this situation i still have an error:
E pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: When "I enter my login and "PASSWORD1"". Line 12 in scenario "Login to the website" in the feature "pytest_bdd/features/login.feature"
All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames.
My question is why?
Solution: step
@when('I enter my login and {password}')should have parse@when(parsers.parse('I enter my login and {password}'))