from selenium import webdriver from selenium.webdriver.common.keys import Keys import time import unittest class NewVisitorTest(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() def tearDown(self): self.browser.quit() def check_for_row_in_list_table(self, row_text): table = self.browser.find_element_by_id('movie-table') rows = table.find_elements_by_tag_name('tr') self.assertIn(row_text, [row.text for row in rows]) def test_can_start_a_list_and_retrieve_it_later(self): # Edith has heard about a cool new online to-do app. She goes # to check out its homepage self.browser.get('http://localhost:8000') # She notices the page title and header mention to-do lists self.assertIn('MovieLib', self.browser.title) header_text = self.browser.find_element_by_tag_name('h1').text self.assertIn('Your Movie list', header_text) # She is invited to enter a to-do item straight away inputbox = self.browser.find_element_by_id('input-new-movie') self.assertEqual( inputbox.get_attribute('placeholder'), 'Enter a movie title' ) # She types "Inception" into a text box inputbox.send_keys('Inception') # When she hits enter, the page updates, and now the page lists # "1: Inception" as an item in a to-do list table inputbox.send_keys(Keys.ENTER) time.sleep(1) self.check_for_row_in_list_table('1: Inception') inputbox = self.browser.find_element_by_id('input-new-movie') inputbox.send_keys('The Sixth Sense') inputbox.send_keys(Keys.ENTER) time.sleep(1) self.check_for_row_in_list_table('1: Inception') self.check_for_row_in_list_table('2: The Sixth Sense') # There is still a text box inviting her to add another item. She # enters "Armageddon" # self.fail('Finish the test!') # She is invited to enter a to-do item straight away if __name__ == '__main__': unittest.main(warnings='ignore')