FTs now exist in own test files, ea. reliant on base.py to execute
This commit is contained in:
33
src/functional_tests/base.py
Normal file
33
src/functional_tests/base.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.common.exceptions import WebDriverException
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
|
||||||
|
MAX_WAIT = 5
|
||||||
|
|
||||||
|
class FunctionalTest(StaticLiveServerTestCase):
|
||||||
|
# Helper methods
|
||||||
|
def setUp(self):
|
||||||
|
self.browser = webdriver.Firefox()
|
||||||
|
if test_server := os.environ.get('TEST_SERVER'):
|
||||||
|
self.live_server_url = 'http://' + test_server
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.browser.quit()
|
||||||
|
|
||||||
|
def wait_for_row_in_list_table(self, row_text):
|
||||||
|
start_time = time.time()
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
table = self.browser.find_element(By.ID, 'id-list-table')
|
||||||
|
rows = table.find_elements(By.TAG_NAME, 'tr')
|
||||||
|
self.assertIn(row_text, [row.text for row in rows])
|
||||||
|
return
|
||||||
|
except (AssertionError, WebDriverException):
|
||||||
|
if time.time() - start_time > MAX_WAIT:
|
||||||
|
raise
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
28
src/functional_tests/test_layout_and_styling.py
Normal file
28
src/functional_tests/test_layout_and_styling.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
|
||||||
|
from .base import FunctionalTest
|
||||||
|
|
||||||
|
class LayoutAndStylingTest(FunctionalTest):
|
||||||
|
def test_layout_and_styling(self):
|
||||||
|
self.browser.get(self.live_server_url)
|
||||||
|
|
||||||
|
self.browser.set_window_size(1024, 768)
|
||||||
|
print("Viewport width:", self.browser.execute_script("return window.innerWidth"))
|
||||||
|
|
||||||
|
inputbox = self.browser.find_element(By.ID, 'id-new-item')
|
||||||
|
self.assertAlmostEqual(
|
||||||
|
inputbox.location['x'] + inputbox.size['width'] / 2,
|
||||||
|
512,
|
||||||
|
delta=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
inputbox.send_keys('testing')
|
||||||
|
inputbox.send_keys(Keys.ENTER)
|
||||||
|
self.wait_for_row_in_list_table('1. testing')
|
||||||
|
inputbox = self.browser.find_element(By.ID, 'id-new-item')
|
||||||
|
self.assertAlmostEqual(
|
||||||
|
inputbox.location['x'] + inputbox.size['width'] / 2,
|
||||||
|
512,
|
||||||
|
delta=10,
|
||||||
|
)
|
||||||
8
src/functional_tests/test_list_item_validation.py
Normal file
8
src/functional_tests/test_list_item_validation.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
|
||||||
|
from .base import FunctionalTest
|
||||||
|
|
||||||
|
class ItemValidationTest(FunctionalTest):
|
||||||
|
def test_cannot_add_empty_list_items(self):
|
||||||
|
self.fail("write me!")
|
||||||
@@ -1,37 +1,11 @@
|
|||||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
|
||||||
from selenium import webdriver
|
|
||||||
from selenium.common.exceptions import WebDriverException
|
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
import os
|
|
||||||
import time
|
from .base import FunctionalTest
|
||||||
import unittest
|
|
||||||
|
|
||||||
MAX_WAIT = 5
|
MAX_WAIT = 5
|
||||||
|
|
||||||
class NewVisitorTest(StaticLiveServerTestCase):
|
class NewVisitorTest(FunctionalTest):
|
||||||
# Helper methods
|
|
||||||
def setUp(self):
|
|
||||||
self.browser = webdriver.Firefox()
|
|
||||||
if test_server := os.environ.get('TEST_SERVER'):
|
|
||||||
self.live_server_url = 'http://' + test_server
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
self.browser.quit()
|
|
||||||
|
|
||||||
def wait_for_row_in_list_table(self, row_text):
|
|
||||||
start_time = time.time()
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
table = self.browser.find_element(By.ID, 'id-list-table')
|
|
||||||
rows = table.find_elements(By.TAG_NAME, 'tr')
|
|
||||||
self.assertIn(row_text, [row.text for row in rows])
|
|
||||||
return
|
|
||||||
except (AssertionError, WebDriverException):
|
|
||||||
if time.time() - start_time > MAX_WAIT:
|
|
||||||
raise
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
# Test methods
|
# Test methods
|
||||||
def test_can_start_a_todo_list(self):
|
def test_can_start_a_todo_list(self):
|
||||||
self.browser.get(self.live_server_url)
|
self.browser.get(self.live_server_url)
|
||||||
@@ -83,26 +57,3 @@ class NewVisitorTest(StaticLiveServerTestCase):
|
|||||||
page_text = self.browser.find_element(By.TAG_NAME, 'body').text
|
page_text = self.browser.find_element(By.TAG_NAME, 'body').text
|
||||||
self.assertNotIn('Buy peacock feathers', page_text)
|
self.assertNotIn('Buy peacock feathers', page_text)
|
||||||
self.assertIn('Buy milk', page_text)
|
self.assertIn('Buy milk', page_text)
|
||||||
|
|
||||||
def test_layout_and_styling(self):
|
|
||||||
self.browser.get(self.live_server_url)
|
|
||||||
|
|
||||||
self.browser.set_window_size(1200, 768) # may have to switch back to 1024
|
|
||||||
print("Viewport width:", self.browser.execute_script("return window.innerWidth"))
|
|
||||||
|
|
||||||
inputbox = self.browser.find_element(By.ID, 'id-new-item')
|
|
||||||
self.assertAlmostEqual(
|
|
||||||
inputbox.location['x'] + inputbox.size['width'] / 2,
|
|
||||||
512,
|
|
||||||
delta=10,
|
|
||||||
)
|
|
||||||
|
|
||||||
inputbox.send_keys('testing')
|
|
||||||
inputbox.send_keys(Keys.ENTER)
|
|
||||||
self.wait_for_row_in_list_table('1. testing')
|
|
||||||
inputbox = self.browser.find_element(By.ID, 'id-new-item')
|
|
||||||
self.assertAlmostEqual(
|
|
||||||
inputbox.location['x'] + inputbox.size['width'] / 2,
|
|
||||||
512,
|
|
||||||
delta=10,
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user