Skip to content
Snippets Groups Projects
Commit 4af305e9 authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Removed explicit waits in functional tests

parent 4c008882
No related branches found
No related tags found
No related merge requests found
Pipeline #86638 passed
import time
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from core import models
from core.models import UserAccount
......@@ -47,11 +46,20 @@ class UntestedParent:
self.assertEqual('Statistics', title.text)
def test_available_tasks_are_shown(self):
# A function that takes the element corresponding to the tasks
# component and return a function that can be used as a condition for
# WebDriverWait
def subscriptions_loaded_cond(tasks_el):
def loaded(*args):
sub_links = tasks_el.find_elements_by_tag_name('a')
return any((link != '/home' for link in extract_hrefs_hashes(sub_links)))
return loaded
self._login()
tasks = self.browser.find_element_by_name('subscription-list')
title = tasks.find_element_by_class_name('v-toolbar__title')
self.assertEqual('Tasks', title.text)
time.sleep(8)
WebDriverWait(self.browser, 6).until(subscriptions_loaded_cond(tasks))
subscription_links = extract_hrefs_hashes(
tasks.find_elements_by_tag_name('a')
)
......
import time
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from core.models import UserAccount
from util.factories import make_test_data
......@@ -102,7 +102,7 @@ class LoginPageTest(LiveServerTestCase):
password_input = self.browser.find_element_by_xpath('//input[@aria-label="Password"]')
password_input.send_keys('p')
self.browser.find_element_by_xpath('//button[@type="submit"]').send_keys(Keys.ENTER)
time.sleep(1)
WebDriverWait(self.browser, 3).until(ec.url_contains('/home'))
def test_tutor_can_login(self):
tutor = self.test_data['tutors'][0]
......@@ -130,8 +130,9 @@ class LoginPageTest(LiveServerTestCase):
username_input.send_keys(username)
password_input = self.browser.find_element_by_id('input-register-password')
password_input.send_keys(password)
self.browser.find_element_by_id('register-submit').click()
time.sleep(1)
register_submit_el = self.browser.find_element_by_id('register-submit')
register_submit_el.click()
WebDriverWait(self.browser, 3).until_not(ec.visibility_of(register_submit_el))
tutor = UserAccount.objects.get(username=username)
self.assertEqual(UserAccount.TUTOR, tutor.role)
self.assertFalse(tutor.is_active, "Tutors should be inactive after registered")
......@@ -6,6 +6,8 @@ from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
def create_browser() -> webdriver.Firefox:
......@@ -23,6 +25,7 @@ def login(browser, live_server_url, username, password='p'):
password_input = browser.find_element_by_xpath('//input[@aria-label="Password"]')
password_input.send_keys(password)
browser.find_element_by_xpath('//button[@type="submit"]').send_keys(Keys.ENTER)
WebDriverWait(browser, 3).until(ec.url_contains('/home'))
def reset_browser_after_test(browser: webdriver.Firefox, live_server_url):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment