Skip to content

Commit 4522417

Browse files
committed
fix functional tests
1 parent 1d41184 commit 4522417

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

tests/tests_functional.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,19 @@ def test_signup_login(self):
2626
username_field.send_keys('user')
2727
password1_field.send_keys('pass12345')
2828
password2_field.send_keys('wrong12345')
29-
signup_btn = modal.find_element_by_class_name('submit-btn')
30-
signup_btn.click()
29+
form.submit()
3130

3231
# User sees error in form
33-
error = modal.find_element_by_class_name('help-block').text
34-
self.assertEqual(error, 'The two password fields didn\'t match.')
32+
error = self.wait_for(class_name='help-block')
33+
self.assertEqual(error.text, 'The two password fields didn\'t match.')
3534

3635
# User fills in and submits sign up form correctly
3736
form = modal.find_element_by_tag_name('form')
3837
password1_field = form.find_element_by_id('id_password1')
3938
password2_field = form.find_element_by_id('id_password2')
4039
password1_field.send_keys('pass12345')
4140
password2_field.send_keys('pass12345')
42-
signup_btn = modal.find_element_by_class_name('submit-btn')
43-
signup_btn.click()
41+
form.submit()
4442

4543
# User sees success message after page redirection
4644
redirect_url = self.browser.current_url
@@ -61,8 +59,7 @@ def test_signup_login(self):
6159
password_field = form.find_element_by_id('id_password')
6260
username_field.send_keys('wrong')
6361
password_field.send_keys('pass12345')
64-
login_btn = modal.find_element_by_class_name('submit-btn')
65-
login_btn.click()
62+
form.submit()
6663

6764
# User sees error in form
6865
error = self.wait_for(class_name='invalid').text
@@ -78,8 +75,7 @@ def test_signup_login(self):
7875
password_field = form.find_element_by_id('id_password')
7976
username_field.send_keys('user')
8077
password_field.send_keys('pass12345')
81-
login_btn = modal.find_element_by_class_name('submit-btn')
82-
login_btn.click()
78+
form.submit()
8379

8480
# User sees log out button after page redirection
8581
logout_btn_txt = self.wait_for(element_id='logout-btn').text
@@ -112,6 +108,7 @@ def test_create_object(self):
112108

113109
# User fills in and submits the form with wrong date format
114110
form = self.wait_for(tag='form')
111+
115112
title_field = form.find_element_by_id('id_title')
116113
publication_date_field = form.find_element_by_id('id_publication_date')
117114
author_field = form.find_element_by_id('id_author')
@@ -127,22 +124,20 @@ def test_create_object(self):
127124
pages_field.send_keys(464)
128125
book_type_select.select_by_index(1)
129126

130-
create_btn = modal.find_element_by_class_name('submit-btn')
131-
create_btn.click()
132-
133-
self.wait_for(class_name='help-block')
127+
form.submit()
134128

135129
# User sees error in form
136130
error = self.wait_for(class_name='help-block').text
137131
self.assertEqual(error, 'Enter a valid date in YYYY-MM-DD format.')
138132

139133
# User corrects the date and submits the form
140134
form = modal.find_element_by_tag_name('form')
135+
141136
publication_date_field = form.find_element_by_id('id_publication_date')
142137
publication_date_field.clear()
143138
publication_date_field.send_keys('2019-01-01')
144-
create_btn = modal.find_element_by_class_name('submit-btn')
145-
create_btn.click()
139+
140+
form.submit()
146141

147142
# User sees success message after page redirection
148143
redirect_url = self.browser.current_url
@@ -173,18 +168,19 @@ def test_filter_object(self):
173168
# Update filter modal opens
174169
modal = self.wait_for(element_id='modal')
175170

176-
# User changes price and book type
171+
# User changes book type
172+
form = modal.find_element_by_tag_name('form')
173+
177174
book_type = self.browser.find_element_by_id("id_type")
178175
book_type_select = Select(book_type)
179-
book_type_select.select_by_index(2)
176+
book_type_select.select_by_index(0)
180177

181-
filter_btn = modal.find_element_by_class_name('submit-btn')
182-
filter_btn.click()
178+
form.submit()
183179

184-
# User is redirected to the index with a querystring with the filter
185-
self.wait_for(element_id='filter-book')
180+
# User is redirected to the homepage with a querystring with the filter
181+
self.wait_for(class_name='filtered-books')
186182
redirect_url = self.browser.current_url
187-
self.assertRegex(redirect_url, '/?type=3$')
183+
self.assertRegex(redirect_url, '/?type=1$')
188184

189185
def test_update_object(self):
190186
# User visits homepage
@@ -198,6 +194,7 @@ def test_update_object(self):
198194

199195
# User changes price and book type
200196
form = modal.find_element_by_tag_name('form')
197+
201198
title_field = form.find_element_by_id('id_title')
202199
title_field.clear()
203200
book_type = form.find_element_by_id('id_book_type')
@@ -206,15 +203,14 @@ def test_update_object(self):
206203
title_field.send_keys('Life of Jane and John Doe')
207204
book_type_select.select_by_index(2)
208205

209-
update_btn = modal.find_element_by_class_name('submit-btn')
210-
update_btn.click()
206+
form.submit()
211207

212208
# User sees success message after page redirection
213209
redirect_url = self.browser.current_url
214210
self.assertRegex(redirect_url, '/')
215211

216212
# Slice removes '\nx' since alert is dismissible and contains 'times' button
217-
success_msg = self.browser.find_element_by_class_name('alert').text[:-2]
213+
success_msg = self.wait_for(class_name='alert').text[:-2]
218214
self.assertEqual(success_msg, 'Success: Book was updated.')
219215

220216
# User sees updated book in table
@@ -265,10 +261,7 @@ def test_delete_object(self):
265261

266262
# Delete book modal opens
267263
modal = self.wait_for(element_id='modal')
268-
269-
# User sees modal content
270-
modal_body = modal.find_element_by_class_name('modal-body')
271-
delete_text = modal_body.find_element_by_class_name('delete-text').text
264+
delete_text = modal.find_element_by_class_name('delete-text').text
272265
self.assertEqual(
273266
delete_text, 'Are you sure you want to delete book with title Life of John Doe?'
274267
)
@@ -282,8 +275,8 @@ def test_delete_object(self):
282275
self.assertRegex(redirect_url, '/')
283276

284277
# Slice removes '\nx' since alert is dismissible and contains 'times' button
285-
success_msg = self.browser.find_element_by_class_name('alert').text[:-2]
286-
self.assertEqual(success_msg, 'Success: Book was deleted.')
278+
alert = self.wait_for(class_name='alert')
279+
self.assertEqual(alert.text[:-2], 'Success: Book was deleted.')
287280

288281
# User sees 'No books added yet.'
289282
no_books = self.browser.find_element_by_class_name('no-books')

0 commit comments

Comments
 (0)