コード例 #1
0
    def test_can_start_a_list_for_one_user(self):
        # Emily has heard about a cool new online to-do app. She goes to check out its homepage
        self.browser.get(self.live_server_url)
        
        # 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
        list_page = ListPage(self)
        input_box = list_page.get_item_input_box()
        self.assertEqual(input_box.get_attribute('placeholder'), 'Enter a to-do item')
        
        # She types "Buy cat toys" into a text box (She has multiple cats that love to play)
        input_box.send_keys(E_ITEM_1)
        
        # When she hits enter, the page updates, and now the page lists
        # "1: Buy cat toys" as an item in a to-do list
        input_box.send_keys(Keys.ENTER)

        self.wait_for_row_in_list_table(f'1: {E_ITEM_1}')
        
        # There is still a text box inviting her to add another item. She enters "Surprise cats with toys"
        list_page.enter_list_item(E_ITEM_2)

        # The page updates again, and now shows both items on her list
        self.wait_for_row_in_list_table(f'1: {E_ITEM_1}')
        self.wait_for_row_in_list_table(f'2: {E_ITEM_2}')
コード例 #2
0
    def test_cannot_add_duplicate_items(self):
        # Emily goes to the new home page and starts a new list
        self.browser.get(self.live_server_url)

        list_page = ListPage(self).add_list_item(E_ITEM_1)

        # She accidentally tries to enter a duplicate item
        list_page.enter_list_item(E_ITEM_1)

        # She sees a helpful error message
        self.wait_for(lambda: self.assertEqual(
            self.get_error_element().text,
            "You've already got this in your list"
        ))
コード例 #3
0
    def test_error_messages_are_cleared_on_input(self):
        # Emily starts a list and causes a validation error:
        self.browser.get(self.live_server_url)

        list_page = ListPage(self).add_list_item(E_ITEM_1)

        list_page.enter_list_item(E_ITEM_1)

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

        # She starts typing in the input box to clear the error
        input_box = list_page.get_item_input_box()
        input_box.send_keys(E_ITEM_2)

        # She is pleased to see that the error message disappears
        self.wait_for(lambda: self.assertFalse(
            self.get_error_element().is_displayed()
        ))
コード例 #4
0
    def test_cannot_add_empty_list_items(self):
        # Emily goes to the home page and accidentally tries to submit an empty list item. She hits enter on the empty
        # input box.
        self.browser.get(self.live_server_url)

        list_page = ListPage(self)

        list_page.enter_list_item('')

        # The browser intercepts the request, and does not load the list page
        self.wait_for(lambda: self.browser.find_element_by_css_selector('#id_text:invalid'))

        # She starts typing some text for the new item and the error disappears
        input_box = list_page.get_item_input_box()
        input_box.send_keys(E_ITEM_1)

        self.wait_for(lambda: self.browser.find_element_by_css_selector('#id_text:valid'))

        # And she can submit it successfully
        input_box.send_keys(Keys.ENTER)
        
        self.wait_for_row_in_list_table(f'1: {E_ITEM_1}')
        
        # Perversely, she now decides to submit a second blank list item
        list_page.enter_list_item('')

        # Again the browser will not comply
        self.wait_for_row_in_list_table(f'1: {E_ITEM_1}')
        self.wait_for(lambda: self.browser.find_element_by_css_selector('#id_text:invalid'))

        # And she can correct it filling some text in
        input_box = list_page.get_item_input_box()
        input_box.send_keys(E_ITEM_2)

        self.wait_for(lambda: self.browser.find_element_by_css_selector('#id_text:valid'))

        input_box.send_keys(Keys.ENTER)

        self.wait_for_row_in_list_table(f'1: {E_ITEM_1}')
        self.wait_for_row_in_list_table(f'2: {E_ITEM_2}')