-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional_tests.py
executable file
·96 lines (75 loc) · 3.33 KB
/
functional_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import unittest
import os
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
staging_server = os.environ.get('STAGING_SERVER')
if staging_server:
self.live_server_url = 'http://' + staging_server#https?
print('!', self.live_server_url)
#self.browser.implicitly_wait(10)
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])
def est_can_start_a_list_for_one_user(self):
self.browser.get(self.live_server_url + ':8000')
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')
self.assertEqual(
inputbox.get_attribute('placeholder'),
'Enter a to-do item'
)
inputbox.send_keys('Buy peacock feathers')
#inputbox.send_keys(Keys.ENTER)
time.sleep(2)
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(2)
self.check_for_row_in_list_table('1: Buy peacock feathers')
self.check_for_row_in_list_table('2: Use peacock feathers to make a fly')
self.fail('Finish the test!')
def est_multiple_users_can_start_lists_at_different_urls(self):
self.browser.get(self.live_server_url + ':8000')
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Buy peacock feathers')
#inputbox.send_keys(Keys.ENTER)
time.sleep(2)
current_url = self.browser.current_url
last_url = current_url
#self.assertRegex(current_url, '/lists/.+')
self.browser.quit()
self.browser = webdriver.Firefox()
self.browser.get(self.live_server_url + ':8000')
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)
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Buy milk')
#inputbox.send_keys(keys.ENTER)
self.check_for_row_in_list_table('1: Buy milk')
current_url = self.browser.current_url
self.assertRegex(current_url, '/lists/.+')
self.assertNotEqual(current_url, last_url)
page_text = self.browser.find_element_by_tag_name('body').text
self.assertNotIn('Buy peacock feathers', page_text)
self.assertIn('Buy milk', page_text)
def test_layout_and_styling(self):
self.browser.get(self.live_server_url + ':8000')
self.browser.set_window_size(1024, 768)
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertAlmostEqual(
inputbox.location['x'] + inputbox.size['width'] / 2,
512,
delta=10
)
if __name__ == '__main__':
unittest.main(warnings='ignore')