Fakultas Ilmu Komputer UI

Commit a914a575 authored by Yumna Pratista's avatar Yumna Pratista
Browse files

Finishing off FT

parent 8b9bb730
......@@ -42,4 +42,14 @@ class FunctionalTest(StaticLiveServerTestCase):
# self.wait_for_row_in_list_table('1: Buy peacock feathers')
# self.wait_for_row_in_list_table('2: Use peacock feathers to make a fly')
# # Satisfied, she goes back to sleep
\ No newline at end of file
# # Satisfied, she goes back to sleep
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)
\ No newline at end of file
from selenium.webdriver.common.keys import Keys
from .base import FunctionalTest
import time
MAX_WAIT = 10
......
from selenium.webdriver.common.keys import Keys
from unittest import skip
from .base import FunctionalTest
import time
MAX_WAIT = 10
......@@ -9,19 +10,43 @@ class ItemValidationTest(FunctionalTest):
def test_cannot_add_empty_list_items(self):
# Edith 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)
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
# The home page refreshes, and there is an error message saying
# that list items cannot be blank
# The home page refreshes, and there is an error message saying
# that list items cannot be blank
self.wait_for(lambda: self.assertEqual(
self.browser.find_element_by_css_selector('.has-error').text,
"You can't have an empty list item"
))
# She tries again with some text for the item, which now works
self.browser.find_element_by_id('id_new_item').send_keys('Buy milk')
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
# Perversely, she now decides to submit a second blank list item
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
# She receives a similar warning on the list page
self.wait_for(lambda: self.assertEqual(
self.browser.find_element_by_css_selector('.has-error').text,
"You can't have an empty list item"
))
# And she can correct it by filling some text in
self.fail('write me!')
self.browser.find_element_by_id('id_new_item').send_keys('Make tea')
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
self.wait_for_row_in_list_table('2: Make tea')
# She tries again with some text for the item, which now works
self.fail('finish this test!')
# if __name__ == '__main__': #
# unittest.main(warnings='ignore') #
\ No newline at end of file
# if __name__ == '__main__': #
# unittest.main(warnings='ignore') #
\ No newline at end of file
from .base import FunctionalTest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
MAX_WAIT = 10
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment