Fakultas Ilmu Komputer UI

Commit 8b9bb730 authored by Yumna Pratista's avatar Yumna Pratista
Browse files

Moved FT into individual files

parent f4ba2048
import os
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
import time
MAX_WAIT = 10
class FunctionalTest(StaticLiveServerTestCase):
def setUp(self):
# chrome_options = Options()
# chrome_options.add_argument('--dns-prefatch-disable')
# chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
# self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
self.browser = webdriver.Firefox()
# self.browser.implicitly_wait(20)
def tearDown(self):
self.browser.quit()
def wait_for_row_in_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)
# def test_can_start_a_list_for_one_user(self):
# # Edith has heard about a cool new online to-do app. She goes
# # The page updates again, and now shows both items on her list
# 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
from selenium.webdriver.common.keys import Keys
from .base import FunctionalTest
MAX_WAIT = 10
class LayoutAndStylingTest(FunctionalTest):
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)
# She notices the input box is nicely centered
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('testing')
inputbox.send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: testing')
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertAlmostEqual(
inputbox.location['x'] + inputbox.size['width'] / 2,
512,
delta=10)
from selenium.webdriver.common.keys import Keys
from unittest import skip
from .base import FunctionalTest
MAX_WAIT = 10
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
# The home page refreshes, and there is an error message saying
# that list items cannot be blank
# She tries again with some text for the item, which now works
# Perversely, she now decides to submit a second blank list item
# She receives a similar warning on the list page
# And she can correct it by filling some text in
self.fail('write me!')
# 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
from selenium.common.exceptions import WebDriverException
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.chrome.options import Options
from app_homepage.models import Item
import time
MAX_WAIT = 10
class NewVisitorTest(StaticLiveServerTestCase):
def setUp(self):
# chrome_options = Options()
# chrome_options.add_argument('--dns-prefatch-disable')
# chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
# self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
self.browser = webdriver.Firefox()
# self.browser.implicitly_wait(20)
def tearDown(self):
self.browser.quit()
def check_for_row_in_list_table(self, row_text):
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])
class NewVisitorTest(FunctionalTest):
def test_can_start_a_list_and_retrieve_it_later(self):
# Edith has heard about a cool new online to-do app. She goes
......@@ -64,30 +41,6 @@ class NewVisitorTest(StaticLiveServerTestCase):
# explanatory text to that effect.
# self.fail('Finish the test!')
def wait_for_row_in_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)
# def test_can_start_a_list_for_one_user(self):
# # Edith has heard about a cool new online to-do app. She goes
# # The page updates again, and now shows both items on her list
# 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
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)
......@@ -139,22 +92,9 @@ class NewVisitorTest(StaticLiveServerTestCase):
self.assertNotIn('Buy peacock feathers', page_text)
self.assertIn('Buy milk', page_text)
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)
# She notices the input box is nicely centered
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('testing')
inputbox.send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: testing')
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertAlmostEqual(
inputbox.location['x'] + inputbox.size['width'] / 2,
512,
delta=10)
def check_for_row_in_list_table(self, row_text):
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])
# if __name__ == '__main__': #
# unittest.main(warnings='ignore') #
\ No newline at end of file
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