-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
272 lines (197 loc) · 11.3 KB
/
test.py
File metadata and controls
272 lines (197 loc) · 11.3 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Standard library imports
import unittest
# 3rd party imports
from selenium import webdriver
# Local file imports
from Resources.page import (HomePage, RegisterPage, LoginPage, ProfilePage,
CreatePostPage, IndividualPostPage, ConfirmDeletePostPage, AboutPage)
from TestingData.testingData import (HomePageTestingData, RegisterPageTestingData,
LoginPageTestingData, ProfilePageTestingData, CreatePostTestingData)
# Base testing class for setUp() and tearDown() methods
class BaseTest(unittest.TestCase):
driver = None
def setUp(self):
# Below two lines for opening Chrome window during dev/testing
#self.driver = webdriver.Chrome()
#self.driver.maximize_window()
# Below lines needed for headless testing to enable continuous integration
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('headless')
chrome_options.add_argument('window-size=1920x1080')
self.driver = webdriver.Chrome(options=chrome_options)
def tearDown(self):
pass
self.driver.close()
# Tests for logging in and updating user information
class RegisterPageTests(BaseTest):
# Test that correct error message shows when registering with a taken username
def test_register_existing_user_name(self):
homePage = HomePage(self.driver)
homePage.click_register_button()
registerPage = RegisterPage(homePage.driver)
registerPage.sign_up(RegisterPageTestingData.REGISTERED_USERNAME,
RegisterPageTestingData.VALID_EMAIL,
RegisterPageTestingData.MATCHING_PASSWORD_ONE,
RegisterPageTestingData.MATCHING_PASSWORD_TWO)
assert registerPage.check_for_username_error() == 0
# Test that correct error message shows when the two password fields do not match during registration
def test_register_not_matching_passwords(self):
homePage = HomePage(self.driver)
homePage.click_register_button()
registerPage = RegisterPage(homePage.driver)
registerPage.sign_up(RegisterPageTestingData.UNREGISTERED_USERNAME,
RegisterPageTestingData.VALID_EMAIL,
RegisterPageTestingData.NOT_MATCHING_PASSWORD_ONE,
RegisterPageTestingData.NOT_MATCHING_PASSWORD_TWO)
assert registerPage.check_for_password_no_match_error() == 0
class LoginPageTests(BaseTest):
# Test that a registered user can successfully login
def test_login_successful(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(LoginPageTestingData.REGISTERED_USERNAME,
LoginPageTestingData.CORRECT_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
assert redirectHomePage.check_if_logged_in() == 0
# Test that we cannot log in with a non-existent user
def test_no_matching_username_during_login(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(LoginPageTestingData.UNREGISTERED_USERNAME,
LoginPageTestingData.CORRECT_PASSWORD)
assert loginPage.check_for_login_error() == 0
# Test that we cannot successfully login a user with the wrong password
def test_wrong_password_during_login(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(LoginPageTestingData.REGISTERED_USERNAME,
LoginPageTestingData.INCORRECT_PASSWORD)
assert loginPage.check_for_login_error() == 0
class UserProfileTests(BaseTest):
# Test that we can successfully update the username of a user
def test_update_username_success(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_profile_button()
profilePage = ProfilePage(redirectHomePage.driver)
profilePage.set_username(ProfilePageTestingData.NEW_TEST_USERNAME)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_success() == 0
assert profilePage.get_username() == ProfilePageTestingData.NEW_TEST_USERNAME
# Reset test user with original values, we do not want to keep the updated values so we can reproduce tests.
profilePage.set_username(ProfilePageTestingData.ORIGINAL_TEST_USERNAME)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_success() == 0
assert profilePage.get_username() == ProfilePageTestingData.ORIGINAL_TEST_USERNAME
# Test that we can successfully update the email address of a user
def test_update_email_success(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_profile_button()
profilePage = ProfilePage(redirectHomePage.driver)
profilePage.set_email(ProfilePageTestingData.NEW_TEST_EMAIL)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_success() == 0
assert profilePage.get_email() == ProfilePageTestingData.NEW_TEST_EMAIL
# Reset test user with original values, we do not want to keep the updated values so we can reproduce tests.
profilePage.set_email(ProfilePageTestingData.ORIGINAL_TEST_EMAIL)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_success() == 0
assert profilePage.get_email() == ProfilePageTestingData.ORIGINAL_TEST_EMAIL
# Test that we cannot update a user's username to another user's username
def test_update_username_error(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_profile_button()
profilePage = ProfilePage(redirectHomePage.driver)
profilePage.set_username(ProfilePageTestingData.CONFLICTING_USERNAME)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_username_error() == 0
# Test that we can successfully update a user's profile picture
def test_update_profile_picture_success(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_profile_button()
profilePage = ProfilePage(redirectHomePage.driver)
profilePage.choose_new_profile_picture(ProfilePageTestingData.VALID_PICTURE_PATH)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_success() == 0
# Test that we can successfully update a user's profile picture
def test_update_profile_picture_error(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_profile_button()
profilePage = ProfilePage(redirectHomePage.driver)
profilePage.choose_new_profile_picture(ProfilePageTestingData.INVALID_PICTURE_PATH)
profilePage.click_update_button()
assert profilePage.check_for_update_profile_picture_error() == 0
class CreatePostTests(BaseTest):
# Test that can successfully create a post
def test_create_post_success(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_create_post_button()
createPostPage = CreatePostPage(redirectHomePage.driver)
createPostPage.set_post_title(CreatePostTestingData.TEST_POST_TITLE)
createPostPage.set_post_content(CreatePostTestingData.TEST_POST_CONTENT)
createPostPage.click_post_button()
individualPostPage = IndividualPostPage(createPostPage.driver)
assert individualPostPage.check_for_post_success() == 0
# Delete this test post so we do not populate application with unnecessary test posts
individualPostPage.click_delete_post_button()
confirmDeletePostPage = ConfirmDeletePostPage(individualPostPage.driver)
confirmDeletePostPage.click_confirm_delete_button()
class UpdatePostTests(BaseTest):
# Test that ensures a user can access (edit or delete) a post they own
def test_can_access_own_posts(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_post_link_by_title(HomePageTestingData.TEST_USER_OWNED_POST_TITLE)
individualPostPage = IndividualPostPage(redirectHomePage.driver)
assert individualPostPage.check_if_user_made_post() == 0
# Test that ensures a user cannot update (edit or delete) a post they do not own
def test_cannot_access_other_user_posts(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
redirectHomePage = HomePage(loginPage.driver)
redirectHomePage.click_post_link_by_title(HomePageTestingData.TEST_USER_NOT_OWNED_POST_TITLE)
individualPostPage = IndividualPostPage(redirectHomePage.driver)
assert individualPostPage.check_if_user_made_post() == -1
class AboutPageTests(BaseTest):
# Test that we can render the about page successfully
def test_can_render_about_page(self):
homePage = HomePage(self.driver)
homePage.click_login_button()
loginPage = LoginPage(homePage.driver)
loginPage.login(ProfilePageTestingData.ORIGINAL_TEST_USERNAME, ProfilePageTestingData.ORIGINAL_TEST_PASSWORD)
loginPage.click_about_page_button()
aboutPage = AboutPage(loginPage.driver)
assert aboutPage.check_for_about_page_info() == 0
if __name__ == "__main__":
unittest.main()