fix e2e tests

This commit is contained in:
Sam 2023-07-13 21:49:27 +02:00
parent 4476698f70
commit 311c601724
5 changed files with 29 additions and 13 deletions

View File

@ -22,7 +22,7 @@ class TestLogin:
assert inputs[1].get_attribute('id') == 'password' assert inputs[1].get_attribute('id') == 'password'
assert inputs[1].get_attribute('type') == 'password' assert inputs[1].get_attribute('type') == 'password'
button = selenium.find_element(By.TAG_NAME, 'button') button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
assert button.get_attribute('type') == 'submit' assert button.get_attribute('type') == 'submit'
assert 'Log in' in button.text assert 'Log in' in button.text
@ -47,4 +47,7 @@ class TestLogin:
assert 'Statistics' in nav assert 'Statistics' in nav
assert 'Add a workout' in nav assert 'Add a workout' in nav
assert user['username'] in nav assert user['username'] in nav
assert 'Logout' in nav logout_button = selenium.find_elements(By.CLASS_NAME, 'logout-button')[
0
]
assert logout_button

View File

@ -6,14 +6,19 @@ from .utils import register_valid_user
class TestLogout: class TestLogout:
def test_user_can_log_out(self, selenium): def test_user_can_log_out(self, selenium):
user = register_valid_user(selenium) user = register_valid_user(selenium)
user_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-user-menu') logout_button = selenium.find_elements(By.CLASS_NAME, 'logout-button')[
logout_link = user_menu.find_elements(By.CLASS_NAME, 'nav-item')[2] 0
]
logout_link.click() logout_button.click()
modal = selenium.find_element(By.ID, 'modal')
confirm_button = modal.find_elements(By.CLASS_NAME, 'confirm')[0]
confirm_button.click()
selenium.implicitly_wait(1) selenium.implicitly_wait(1)
nav = selenium.find_element(By.ID, 'nav').text nav = selenium.find_element(By.ID, 'nav').text
assert 'Register' in nav assert 'Register' in nav
assert 'Login' in nav assert 'Login' in nav
assert user['username'] not in nav assert user['username'] not in nav
assert 'Logout' not in nav buttons = selenium.find_elements(By.CLASS_NAME, 'logout-button')
assert buttons == []

View File

@ -35,7 +35,7 @@ class TestRegistration:
assert form_infos[1].text == 'Enter a valid email address.' assert form_infos[1].text == 'Enter a valid email address.'
assert form_infos[2].text == 'At least 8 characters required.' assert form_infos[2].text == 'At least 8 characters required.'
button = selenium.find_element(By.TAG_NAME, 'button') button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
assert button.get_attribute('type') == 'submit' assert button.get_attribute('type') == 'submit'
assert 'Register' in button.text assert 'Register' in button.text
@ -84,7 +84,11 @@ class TestRegistration:
register(selenium, user) register(selenium, user)
assert selenium.current_url == URL assert selenium.current_url == URL
errors = selenium.find_element(By.CLASS_NAME, 'error-message').text errors = (
selenium.find_element(By.ID, 'user-form')
.find_element(By.CLASS_NAME, 'error-message')
.text
)
assert 'Sorry, that username is already taken.' in errors assert 'Sorry, that username is already taken.' in errors
def test_user_does_not_return_error_if_email_is_already_taken( def test_user_does_not_return_error_if_email_is_already_taken(

View File

@ -30,7 +30,7 @@ class TestWorkout:
) )
selenium.find_element(By.NAME, 'workout-distance').send_keys('10') selenium.find_element(By.NAME, 'workout-distance').send_keys('10')
confirm_button = selenium.find_element(By.CLASS_NAME, 'confirm') confirm_button = selenium.find_elements(By.CLASS_NAME, 'confirm')[-1]
confirm_button.click() confirm_button.click()
WebDriverWait(selenium, 10).until( WebDriverWait(selenium, 10).until(

View File

@ -34,7 +34,7 @@ def register(selenium, user):
password.send_keys(user.get('password')) password.send_keys(user.get('password'))
accepted_policy = selenium.find_element(By.ID, 'accepted_policy') accepted_policy = selenium.find_element(By.ID, 'accepted_policy')
accepted_policy.click() accepted_policy.click()
submit_button = selenium.find_element(By.TAG_NAME, 'button') submit_button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
submit_button.click() submit_button.click()
@ -45,7 +45,7 @@ def login(selenium, user):
email.send_keys(user.get('email')) email.send_keys(user.get('email'))
password = selenium.find_element(By.ID, 'password') password = selenium.find_element(By.ID, 'password')
password.send_keys(user.get('password')) password.send_keys(user.get('password'))
submit_button = selenium.find_element(By.TAG_NAME, 'button') submit_button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
submit_button.click() submit_button.click()
@ -65,8 +65,12 @@ def register_valid_user(selenium):
def register_valid_user_and_logout(selenium): def register_valid_user_and_logout(selenium):
user = register_valid_user(selenium) user = register_valid_user(selenium)
user_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-user-menu') user_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-user-menu')
logout_link = user_menu.find_elements(By.CLASS_NAME, 'nav-item')[2] logout_button = user_menu.find_elements(By.CLASS_NAME, 'logout-button')[0]
logout_link.click() logout_button.click()
modal = selenium.find_element(By.ID, 'modal')
confirm_button = modal.find_elements(By.CLASS_NAME, 'confirm')[0]
confirm_button.click()
selenium.implicitly_wait(1)
return user return user