I’m using python selenium work with behave package.
Here is the code:
@given('the user is on the login page')
def step_given_user_on_login_page(context):
PATH = 'C:/Users/PycharmProjects/ui_test/chromedriver-win32/chromedriver.exe'
context.driver = webdriver.Chrome(PATH, options=chrome_options)
context.driver.set_window_position(2000, 0)
context.driver.maximize_window()
context.driver.get("http://127.0.0.1:5000/cases")
@when('the user enters valid credentials')
def step_when_user_enters_valid_credentials(context):
login(context.driver, username, password)
@when('clicks on the login button')
def step_when_clicks_login_button(context):
# Assuming login function handles the login button click
pass
@then('the user should be redirected to the cases page')
def step_then_user_redirected_to_cases_page(context):
assert "cases" in context.driver.current_url
The code runs well until this line:
assert "cases" in context.driver.current_url
The error is:
AttributeError: 'Context' object has no attribute 'driver'
I’m confused why the first context.driver works:
login(context.driver, username, password)
But the second context.driver failed
assert “cases” in context.driver.current_url
Any friend can help?