From 93b6c7ba11c6c214fc7e6da36d2b86c79a8122dd Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 21 May 2018 19:55:26 +0200 Subject: [PATCH] Improve test --- functional_tests/test.py | 54 +++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/functional_tests/test.py b/functional_tests/test.py index e9fb126..6d3f98d 100644 --- a/functional_tests/test.py +++ b/functional_tests/test.py @@ -1,12 +1,54 @@ +import time + +from django.test import LiveServerTestCase from selenium import webdriver +from selenium.common.exceptions import WebDriverException + +MAX_WAIT = 10 -def main(): - browser = webdriver.Firefox() - browser.get('http://localhost:8000') +class NewVisitorTest(LiveServerTestCase): + def setUp(self): + self.browser = webdriver.Firefox() - assert 'Django' in browser.title + def tearDown(self): + self.browser.quit() + def test_can_start_a_list_and_retrieve_it_later(self): + # Edith has received a mail from her librarian about a website + # she can use to tell the books she needs. She goes + # to check out its homepage + self.browser.get(self.live_server_url) -if __name__ == '__main__': - main() + # She notices the page title and header mention "manuels" + self.assertIn('Manuels', self.browser.title) + + # She is invited to enter her contact information (first name, + # last name and phone number) + # She types "Edith" into the first name text box + + # She types "Doe" as her last name + + # She types "0612345678" as her phone number + + # When she hits enter, the page updates, and now the page displays + # her contact info on top and a form to enter book data + + # Edith wonders whether the site will remember her books. Then she sees + # that the site has generated a unique URL for her -- there is some + # explanatory text to that effect. + + # She visits that URL - her books list is still there. + + # Satisfied, she goes back to sleep + self.fail('Finish the test!') + + def wait_for(self, fn): + start_time = time.time() + while True: + try: + return fn() + except (AssertionError, WebDriverException) as e: + if time.time() - start_time > MAX_WAIT: + raise e + time.sleep(0.5)