fix e2e tests

This commit is contained in:
Sam 2022-07-03 15:01:21 +02:00
parent b57433d0c4
commit 8c9ae82842
7 changed files with 55 additions and 43 deletions

View File

@ -1,3 +1,5 @@
from selenium.webdriver.common.by import By
from .utils import TEST_URL
@ -9,7 +11,7 @@ class TestIndex:
def test_navbar_contains_all_links(self, selenium):
selenium.get(TEST_URL)
nav = selenium.find_element_by_id('nav').text
nav = selenium.find_element(By.ID, 'nav').text
assert "FitTrackee" in nav
assert "Login" in nav
assert "Register" in nav

View File

@ -1,3 +1,5 @@
from selenium.webdriver.common.by import By
from .utils import TEST_URL, login_valid_user, register_valid_user_and_logout
URL = f'{TEST_URL}/login'
@ -7,24 +9,24 @@ class TestLogin:
def test_navbar_contains_login(self, selenium):
selenium.get(URL)
nav = selenium.find_element_by_id('nav').text
nav = selenium.find_element(By.ID, 'nav').text
assert 'Login' in nav
def test_it_displays_login_form(self, selenium):
selenium.get(URL)
inputs = selenium.find_elements_by_tag_name('input')
inputs = selenium.find_elements(By.TAG_NAME, 'input')
assert len(inputs) == 2
assert inputs[0].get_attribute('id') == 'email'
assert inputs[0].get_attribute('type') == 'email'
assert inputs[1].get_attribute('id') == 'password'
assert inputs[1].get_attribute('type') == 'password'
button = selenium.find_element_by_tag_name('button')
button = selenium.find_element(By.TAG_NAME, 'button')
assert button.get_attribute('type') == 'submit'
assert 'Log in' in button.text
links = selenium.find_elements_by_class_name('links')
links = selenium.find_elements(By.CLASS_NAME, 'links')
assert links[0].tag_name == 'a'
assert 'Register' in links[0].text
assert links[1].tag_name == 'a'
@ -37,7 +39,7 @@ class TestLogin:
login_valid_user(selenium, user)
nav = selenium.find_element_by_id('nav').text
nav = selenium.find_element(By.ID, 'nav').text
assert 'Register' not in nav
assert 'Login' not in nav
assert 'Dashboard' in nav

View File

@ -1,16 +1,18 @@
from selenium.webdriver.common.by import By
from .utils import register_valid_user
class TestLogout:
def test_user_can_log_out(self, selenium):
user = register_valid_user(selenium)
user_menu = selenium.find_element_by_class_name('nav-items-user-menu')
logout_link = user_menu.find_elements_by_class_name('nav-item')[2]
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_link.click()
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 'Login' in nav
assert user['username'] not in nav

View File

@ -1,3 +1,5 @@
from selenium.webdriver.common.by import By
from .utils import register_valid_user
@ -5,18 +7,18 @@ class TestProfile:
def test_it_displays_user_profile(self, selenium):
user = register_valid_user(selenium)
app_menu = selenium.find_element_by_class_name('nav-items-user-menu')
profile_link = app_menu.find_elements_by_class_name('nav-item')[1]
app_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-user-menu')
profile_link = app_menu.find_elements(By.CLASS_NAME, 'nav-item')[1]
profile_link.click()
selenium.implicitly_wait(1)
user_header = selenium.find_element_by_class_name('user-header')
user_header = selenium.find_element(By.CLASS_NAME, 'user-header')
assert user['username'] in user_header.text
assert '0\nworkouts' in user_header.text
assert '0\nkm' in user_header.text
assert '0\nsports' in user_header.text
user_infos = selenium.find_element_by_id('user-infos')
user_infos = selenium.find_element(By.ID, 'user-infos')
assert 'Registration date' in user_infos.text
assert 'First name' in user_infos.text
assert 'Last name' in user_infos.text

View File

@ -1,3 +1,5 @@
from selenium.webdriver.common.by import By
from .utils import (
TEST_URL,
random_string,
@ -13,7 +15,7 @@ class TestRegistration:
selenium.get(URL)
selenium.implicitly_wait(1)
inputs = selenium.find_elements_by_tag_name('input')
inputs = selenium.find_elements(By.TAG_NAME, 'input')
assert len(inputs) == 4
assert inputs[0].get_attribute('id') == 'username'
assert inputs[0].get_attribute('type') == 'text'
@ -22,7 +24,7 @@ class TestRegistration:
assert inputs[2].get_attribute('id') == 'password'
assert inputs[2].get_attribute('type') == 'password'
form_infos = selenium.find_elements_by_class_name('form-info')
form_infos = selenium.find_elements(By.CLASS_NAME, 'form-info')
assert len(form_infos) == 3
assert form_infos[0].text == (
'3 to 30 characters required, only alphanumeric characters and '
@ -31,11 +33,11 @@ class TestRegistration:
assert form_infos[1].text == 'Enter a valid email address.'
assert form_infos[2].text == 'At least 8 characters required.'
button = selenium.find_element_by_tag_name('button')
button = selenium.find_element(By.TAG_NAME, 'button')
assert button.get_attribute('type') == 'submit'
assert 'Register' in button.text
links = selenium.find_elements_by_class_name('links')
links = selenium.find_elements(By.CLASS_NAME, 'links')
assert links[0].tag_name == 'a'
assert 'Login' in links[0].text
assert links[1].tag_name == 'a'
@ -50,7 +52,7 @@ class TestRegistration:
register(selenium, user)
message = selenium.find_element_by_class_name('success-message').text
message = selenium.find_element(By.CLASS_NAME, 'success-message').text
assert (
'A link to activate your account has been '
'emailed to the address provided.'
@ -67,7 +69,7 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
nav = selenium.find_element_by_id('nav').text
nav = selenium.find_element(By.ID, 'nav').text
assert 'Register' in nav
assert 'Login' in nav
@ -80,7 +82,7 @@ class TestRegistration:
register(selenium, user)
assert selenium.current_url == URL
errors = selenium.find_element_by_class_name('error-message').text
errors = selenium.find_element(By.CLASS_NAME, 'error-message').text
assert 'Sorry, that username is already taken.' in errors
def test_user_does_not_return_error_if_email_is_already_taken(
@ -92,7 +94,7 @@ class TestRegistration:
register(selenium, user)
assert selenium.current_url == f'{TEST_URL}/login'
message = selenium.find_element_by_class_name('success-message').text
message = selenium.find_element(By.CLASS_NAME, 'success-message').text
assert (
'A link to activate your account has been '
'emailed to the address provided.'

View File

@ -1,3 +1,4 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait
@ -7,36 +8,36 @@ from .utils import TEST_URL, register_valid_user
class TestWorkout:
def test_user_can_add_workout_without_gpx(self, selenium):
register_valid_user(selenium)
app_menu = selenium.find_element_by_class_name('nav-items-app-menu')
add_workout_link = app_menu.find_elements_by_class_name('nav-item')[3]
app_menu = selenium.find_element(By.CLASS_NAME, 'nav-items-app-menu')
add_workout_link = app_menu.find_elements(By.CLASS_NAME, 'nav-item')[3]
add_workout_link.click()
selenium.implicitly_wait(1)
radio_button = selenium.find_element_by_id('withoutGpx')
radio_button = selenium.find_element(By.ID, 'withoutGpx')
radio_button.click()
select = Select(selenium.find_element_by_id('sport'))
select = Select(selenium.find_element(By.ID, 'sport'))
select.select_by_index(1)
selenium.find_element_by_name('title').send_keys('Workout title')
selenium.find_element_by_name('workout-date').send_keys('2018-12-20')
selenium.find_element_by_name('workout-time').send_keys('14:05')
selenium.find_element_by_name('workout-duration-hour').send_keys('01')
selenium.find_element_by_name('workout-duration-minutes').send_keys(
selenium.find_element(By.NAME, 'title').send_keys('Workout title')
selenium.find_element(By.NAME, 'workout-date').send_keys('2018-12-20')
selenium.find_element(By.NAME, 'workout-time').send_keys('14:05')
selenium.find_element(By.NAME, 'workout-duration-hour').send_keys('01')
selenium.find_element(By.NAME, 'workout-duration-minutes').send_keys(
'00'
)
selenium.find_element_by_name('workout-duration-seconds').send_keys(
selenium.find_element(By.NAME, 'workout-duration-seconds').send_keys(
'00'
)
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_element(By.CLASS_NAME, 'confirm')
confirm_button.click()
WebDriverWait(selenium, 10).until(
EC.url_changes(f"{TEST_URL}/workouts/add")
)
workout_details = selenium.find_element_by_id('workout-info').text
workout_details = selenium.find_element(By.ID, 'workout-info').text
assert 'Duration: 1:00:00' in workout_details
assert 'Distance: 10 km' in workout_details
assert 'Average Speed: 10 km/h' in workout_details

View File

@ -5,6 +5,7 @@ import string
import time
import requests
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from urllib3.util import parse_url
@ -25,24 +26,24 @@ def random_string(length=8):
def register(selenium, user):
selenium.get(f'{TEST_URL}/register')
selenium.implicitly_wait(1)
username = selenium.find_element_by_id('username')
username = selenium.find_element(By.ID, 'username')
username.send_keys(user.get('username'))
email = selenium.find_element_by_id('email')
email = selenium.find_element(By.ID, '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'))
submit_button = selenium.find_element_by_tag_name('button')
submit_button = selenium.find_element(By.TAG_NAME, 'button')
submit_button.click()
def login(selenium, user):
selenium.get(f'{TEST_URL}/login')
selenium.implicitly_wait(1)
email = selenium.find_element_by_id('email')
email = selenium.find_element(By.ID, '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'))
submit_button = selenium.find_element_by_tag_name('button')
submit_button = selenium.find_element(By.TAG_NAME, 'button')
submit_button.click()
@ -61,8 +62,8 @@ def register_valid_user(selenium):
def register_valid_user_and_logout(selenium):
user = register_valid_user(selenium)
user_menu = selenium.find_element_by_class_name('nav-items-user-menu')
logout_link = user_menu.find_elements_by_class_name('nav-item')[2]
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_link.click()
return user