Fakultas Ilmu Komputer UI

Commit 0a45f69e authored by Yumna Pratista's avatar Yumna Pratista
Browse files

end of lab 3

parent 05bcb100
from selenium import webdriver
import unittest
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import WebDriverException
from django.test import LiveServerTestCase
import time
MAX_WAIT = 10
class NewVisitorTest(LiveServerTestCase):
def setUp(self):
......@@ -18,9 +21,53 @@ class NewVisitorTest(LiveServerTestCase):
self.assertIn(row_text, [row_text for row in rows])
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get(self.live_server_url)
# Edith has heard about a cool new online to-do app. She goes
# to check out its homepage
# self.browser.get('http://localhost:8000')
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)
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Buy peacock feathers')
inputbox.send_keys(Keys.ENTER)
time.sleep(5)
# The page updates again, and now shows both items on her list
self.wait_for_row_int_list_table('1: Buy peacock feathers')
# She is invited to enter a to-do item straight away
# 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)
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Use peacock feathers to make a fly')
inputbox.send_keys(Keys.ENTER)
time.sleep(5)
# The page updates again, and now shows both items on her list
self.wait_for_row_int_list_table('1: Buy peacock feathers')
self.wait_for_row_int_list_table('2: Use peacock feathers to make a fly')
# Edith wonders whether the site will remember her list. Then she sees
# that the site has generated a unique URL for her -- there is some
# explanatory text to that effect.
# self.fail('Finish the test!')
def wait_for_row_int_list_table(self, row_text):
start_time = time.time()
while True:
try:
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertIn(row_text, [row.text for row in rows])
return
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
time.sleep(0.5)
self.fail('Finish the test!')
# if __name__ == '__main__': #
......
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