Ejemplo n.º 1
0
    def test_multiple_users_can_start_lists_at_different_urls(self):
        # Edith starts a new to-do list
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)
        list_page.add_list_item('Buy peacock feathers')

        # She notices that her list has a unique URL
        edith_list_url = self.browser.current_url
        self.assertRegex(edith_list_url, '/lists/.+')

        # Now a new user, Francis, comes along to the site
        self.browser.quit()
        self.browser = webdriver.Firefox()

        # Francis visits the home page. There is no sign of Edith's list
        self.browser.get(self.live_server_url)
        page_text = self.browser.find_element_by_tag_name('body').text
        self.assertNotIn('Buy peacock feathers', page_text)
        self.assertNotIn('make a fly', page_text)

        # Francis starts a new list by entering a new item. He
        # is less interesting than Edith...
        list_page.add_list_item('Buy milk')

        # Francis gets his own unique URL
        francis_list_url = self.browser.current_url
        self.assertRegex(francis_list_url, '/lists/.+')
        self.assertNotEqual(francis_list_url, edith_list_url)

        # Again, there is no trace of Edith's list
        page_text = self.browser.find_element_by_tag_name('body').text
        self.assertNotIn('Buy peacock feathers', page_text)
        self.assertIn('Buy milk', page_text)
Ejemplo n.º 2
0
    def test_can_start_a_list_for_one_user(self):
        # Edith has heard about a cool new online to-do app. She goes
        # to check out its homepage
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)

        # She notices the page title and header mention to-do lists
        self.assertIn('To-Do', self.browser.title)
        header_text = self.browser.find_element_by_tag_name('h1').text
        self.assertIn('To-Do', header_text)

        # She is invited to enter a to-do item straight away
        input_box = list_page.get_item_input_box()
        self.assertEqual(
            input_box.get_attribute('placeholder'),
            'Enter a to-do item'
        )

        # She types "Buy peacock feathers" into a text box (Edith's hobby
        # is tying fly-fishing lures)
        # When she hits enter, the page updates, and now the page lists
        # "1: Buy peacock feathers" as an item in a to-do list
        list_page.add_list_item('Buy peacock feathers')

        # There is still a text box inviting her to add another item. She
        # enters "Use peacock feathers to make a fly" (Edith is very methodical)
        list_page.add_list_item('Use peacock feathers to make a fly')

        # The page updates again, and she still sees the first item on the list
        list_page.wait_for_row_in_list_table('Buy peacock feathers', 1)
Ejemplo n.º 3
0
    def test_error_messages_are_cleared_on_input(self):
        # Edith starts a list and causes a validation error
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)

        list_page.add_list_item('Banter too thick')
        list_page.get_item_input_box().send_keys('Banter too thick')
        list_page.get_item_input_box().send_keys(Keys.ENTER)

        self.wait_for(lambda: self.assertTrue(
            self.browser.find_element_by_class_name('text-danger').
            is_displayed()))
        self.wait_for(lambda: self.assertIn(
            'is-invalid',
            self.browser.find_element_by_id('id_text').get_attribute('class').
            split(' ')))

        # She starts typing in the input box to clear the error
        list_page.get_item_input_box().send_keys('a')

        # She is pleased to see that the error message disappears
        self.wait_for(lambda: self.assertFalse(
            self.browser.find_element_by_class_name('text-danger').
            is_displayed()))
        self.wait_for(lambda: self.assertNotIn(
            'is-invalid',
            self.browser.find_element_by_id('id_text').get_attribute('class').
            split(' ')))
Ejemplo n.º 4
0
    def test_cannot_add_duplicate_items(self):
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)

        list_page.add_list_item('Buy wellies')

        list_page.get_item_input_box().send_keys('Buy wellies')
        list_page.get_item_input_box().send_keys(Keys.ENTER)

        self.wait_for(
            lambda: self.assertEqual(self.get_error_element().text,
                                     "You've already got this in your list"))
    def test_can_start_a_list_for_one_user(self):
        self.browser.get(self.live_server_url)
        self.assertIn('To-Do', self.browser.title)
        list_page = ListPage(self)
        header_text = self.browser.find_element_by_tag_name('h1').text
        self.assertIn('To-Do', header_text)

        input_box = list_page.get_item_input_box()
        self.assertEqual(input_box.get_attribute('placeholder'),
                         'Enter a to-do item')

        list_page.add_list_item('Buy peacock feathers')
        list_page.add_list_item('Use peacock feathers to make a fly')
Ejemplo n.º 6
0
    def test_error_messages_are_cleared_on_input(self):
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)

        list_page.add_list_item('Banter too thick')
        list_page.get_item_input_box().send_keys('Banter too thick')
        list_page.get_item_input_box().send_keys(Keys.ENTER)

        self.wait_for(
            lambda: self.assertTrue(self.get_error_element().is_displayed()))

        list_page.get_item_input_box().send_keys('a')
        self.wait_for(
            lambda: self.assertFalse(self.get_error_element().is_displayed()))
Ejemplo n.º 7
0
    def test_cannot_add_duplicate_items(self):
        # Edith goes to the home page and starts a new list
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)
        list_page.add_list_item('Buy wellies')

        # She accidentally tries to enter a duplicate item
        list_page.get_item_input_box().send_keys('Buy wellies')
        list_page.get_item_input_box().send_keys(Keys.ENTER)

        # She sees a helpful error message
        self.wait_for(lambda: self.assertEqual(
            self.browser.find_element_by_css_selector('.text-danger').text,
            DUPLICATE_ITEM_ERROR))
Ejemplo n.º 8
0
    def test_can_share_a_list_with_another_user(self):
        """test: можно обмениваться списком с еще одним пользователем"""

        # Эдит является зарегистрированным пользователем
        self.create_pre_authenticated_session('*****@*****.**')
        edith_browser = self.browser
        self.addCleanup(lambda: quit_if_possible(edith_browser))

        # Ее друг Анцифер тоже зависает на сайте списков
        oni_browser = self.make_browser()
        self.addCleanup(lambda: quit_if_possible(oni_browser))
        self.browser = oni_browser
        self.create_pre_authenticated_session('*****@*****.**')

        # Эдит открывает домашнюю страницу и начинает новый список
        self.browser = edith_browser
        self.browser.get(self.live_server_url)
        list_page = ListPage(self).add_list_item('Требуется помощь')

        # Она замечает опцию "Поделиться этим списком"
        share_box = ListPage(self).get_share_box()
        self.assertEqual(share_box.get_attribute('placeholder'),
                         '*****@*****.**')

        # Она делится своим списком
        # Страница обновляется и сообщает, что теперь список используется совместно с Анцифиром
        list_page.share_list_with('*****@*****.**')

        # Анцифер переходит на страницу списков в своем браузере
        self.browser = oni_browser
        MyListsPage(self).go_to_my_lists_page()

        # Он видит на ней список Эдит!
        self.browser.find_element_by_link_text('Требуется помощь').click()

        # На странице, которую Анцифер видит, говорится, что это список Эдит
        self.wait_for(lambda: self.assertEqual(list_page.get_list_owner(),
                                               '*****@*****.**'))

        # Он добавляет элемент в список
        list_page.add_list_item('Hi Edith!')

        # Когда Эдит обновляет страницу, она видит дополнение Анцифера
        self.browser = edith_browser
        self.browser.refresh()
        list_page.wait_for_row_in_list_table('Hi Edith!', 2)
Ejemplo n.º 9
0
    def test_can_share_a_list_with_another_user(self):
        # Edith is a logged-in user
        self.create_pre_authenticated_session('*****@*****.**')
        edith_browser = self.browser
        self.addCleanup(lambda: quit_if_possible(edith_browser))

        # Her friend Oniciferous is also hanging out on the lists site
        oni_browser = webdriver.Firefox(firefox_binary=FirefoxBinary(
            firefox_path='/opt/firefox/firefox'))
        self.addCleanup(lambda: quit_if_possible(oni_browser))
        self.browser = oni_browser
        self.create_pre_authenticated_session('*****@*****.**')

        # Edith goes to the home page and starts a list
        self.browser = edith_browser
        self.browser.get(self.server_url)
        list_page = ListPage(self).add_list_item('Get help')

        # She notices a "Share this list" option
        share_box = list_page.get_share_box()
        self.assertEqual(share_box.get_attribute('placeholder'),
                         '*****@*****.**')

        # She shares her list.
        # The page updates to say that it's shared with Oniciferous:
        list_page.share_list_with('*****@*****.**')

        # Oniciferous now goes to the lists page with his browser
        self.browser = oni_browser
        MyListsPage(self).go_to_my_lists_page()

        # He sees Edith's list in there!
        self.browser.find_element_by_link_text('Get help').click()

        # On the list page, Oniciferous can see says that it's Edith's list
        self.wait_for(
            self.assertEqual(list_page.get_list_owner(), '*****@*****.**'))

        # He adds an item to the list
        list_page.add_list_item('Green Unicorn')

        # When Edith refreshes the page, she sees Oniciferous's addition
        self.browser = edith_browser
        self.browser.refresh()
        list_page.wait_for_row_in_list_table('Green Unicorn')
Ejemplo n.º 10
0
    def test_can_share_a_list_with_another_user(self):
        # Lain is a logged-in user
        self.create_pre_authenticated_session('*****@*****.**')
        lain_browser = self.browser
        self.addCleanup(lambda: quit_if_possible(lain_browser))

        # Her friend Edith is also hanging out on the lists site
        edith_browser = webdriver.Firefox()
        self.addCleanup(lambda: quit_if_possible(edith_browser))
        self.browser = edith_browser
        self.create_pre_authenticated_session('*****@*****.**')

        # Lain goes to the home page and starts a list
        self.browser = lain_browser
        self.browser.get(self.live_server_url)
        list_page = ListPage(self).add_list_item('Get help')

        # She notices a 'Share this list' option
        share_box = list_page.get_share_box()
        self.assertEqual(share_box.get_attribute('placeholder'),
                         '*****@*****.**')

        # She shares her list. The page updates to say that it's shared with Edith
        list_page.share_list_with('*****@*****.**')

        # Edith now goes to the lists page with her browser
        self.browser = edith_browser
        MyListsPage(self).go_to_my_lists_page()

        # She sees Lain's list in there!
        self.browser.find_element_by_link_text('Get help').click()

        # On the list page, Edith can see that it's Lain's list
        self.wait_for(lambda: self.assertEqual(list_page.get_list_owner(),
                                               '*****@*****.**'))

        # She adds an item to the list
        list_page.add_list_item('Hi, Lain!')

        # When Lain refreshes the page, she sees Edith's addition
        self.browser = lain_browser
        self.browser.refresh()
        list_page.wait_for_row_in_list_table('Hi, Lain!', 2)
    def test_can_start_a_list_for_multiple_users(self):
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)

        input_box = list_page.get_item_input_box()
        self.assertEqual(input_box.get_attribute('placeholder'),
                         'Enter a to-do item')

        list_page.add_list_item('Buy peacock feathers')
        list_page.add_list_item('Use peacock feathers to make a fly')

        list_url1 = self.browser.current_url
        self.assertRegex(list_url1, '/lists/.+')

        self.browser.quit()
        self.browser = webdriver.Firefox(executable_path=self.DRIVER_PATH)
        self.browser.get(self.live_server_url)

        page_text = self.browser.find_element_by_tag_name('body').text
        self.assertNotIn('1: Buy peacock feathers', page_text)
        self.assertNotIn('2: Use peacock feathers to make a fly', page_text)

        input_box = list_page.get_item_input_box()
        self.assertEqual(input_box.get_attribute('placeholder'),
                         'Enter a to-do item')

        list_page.add_list_item('Buy milk')

        list_url2 = self.browser.current_url
        self.assertRegex(list_url2, '/lists/.+')

        self.assertNotEqual(list_url1, list_url2)
Ejemplo n.º 12
0
    def test_layout_and_styling(self):
        # Edith goes to the home page
        self.browser.get(self.live_server_url)
        self.browser.set_window_size(1024, 768)
        list_page = ListPage(self)

        # She notices the input box is nicely centered
        input_box = list_page.get_item_input_box()
        self.assertAlmostEqual(
            input_box.location['x'] + input_box.size['width'] / 2,
            512,
            delta=10
        )

        # She starts a new list and sees the input is nicely
        # centered there too
        list_page.add_list_item('testing')
        input_box = list_page.get_item_input_box()
        self.assertAlmostEqual(
            input_box.location['x'] + input_box.size['width'] / 2,
            512,
            delta=10
        )
Ejemplo n.º 13
0
    def test_logged_in_users_lists_are_saved_as_my_lists(self):
        # Edith is a logged-in user
        self.create_pre_authenticated_session('*****@*****.**')

        # She goes to the home page and starts a list
        self.browser.get(self.live_server_url)
        list_page = ListPage(self)
        list_page.add_list_item('Reticulate splines')
        list_page.add_list_item('Immanentize eschaton')
        first_list_url = self.browser.current_url

        # She notices a "My lists" link, for the first time.
        my_list_page = MyListPage(self)
        my_list_page.go_to_my_list_page()

        # She see that her list is in there, named according to its
        # first list item
        self.wait_for(lambda: self.browser.find_element_by_link_text(
            'Reticulate splines'))

        self.browser.find_element_by_link_text('Reticulate splines').click()
        self.wait_for(
            lambda: self.assertEqual(self.browser.current_url, first_list_url))

        # She decides to start another list, just to see
        self.browser.get(self.live_server_url)
        list_page.add_list_item('Click cows')
        second_list_url = self.browser.current_url

        # Under "My lists", her new list appears
        # self.browser.find_element_by_link_text('My lists').click()
        my_list_page.go_to_my_list_page()
        self.wait_for(
            lambda: self.browser.find_element_by_link_text('Click cows'))
        self.browser.find_element_by_link_text('Click cows').click()
        self.wait_for(lambda: self.assertEqual(second_list_url, self.browser.
                                               current_url))

        # She logs out. The "My lists" options disappears
        self.browser.find_element_by_link_text('Log out').click()
        self.wait_for(lambda: self.assertEqual(
            self.browser.find_elements_by_link_text('My lists'), []))