| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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 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)
- table = self.browser.find_element_by_id('movie-table')
- rows = table.find_elements_by_tag_name('tr')
- self.assertTrue(
- any(row.text == '1: Inception' for row in rows)
- )
- # 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')
|