forked from cos-archives/osf-ui-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_example_tests.py
99 lines (76 loc) · 2.9 KB
/
ui_example_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
97
98
99
"""
sample usage of selenium in OSF context
Note: As of version 2 Selenium does not have native ability to
grab HTTP response codes. So, we have a few options:
1. Ignore them, and either
a) look at the final page user is redirected to
b) look for specific ids in the redirected page (like below)
2. Use an odd NetCaptcher hack with Firefox. But, this limits us
to using Firefox. Terrible.
3. Setup a proxy server to handle the get requests and inject the info we want
"BrowserMob Proxy" is recommended. Seems hackish.
Base package: https://github.com/lightbody/browsermob-proxy
Python wrapper: https://github.com/AutomatedTester/browsermob-proxy-py
4. Alter actual OSF pages to place 'web responses' in the page source
custom meta-tags or something else. Seems hackish.
"""
import unittest
# Selenium imports
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
# Project imports
import util
import config
class SampleOSFUITests(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Start WebDriver
cls.driver = webdriver.Firefox()
#
cls.driver.implicitly_wait(5)
# Create user account and login
cls.user_data = util.create_user(cls.driver)
util.login(
cls.driver,
cls.user_data['username'],
cls.user_data['password']
)
# Create test project and store URL
cls.project_url = util.create_project(cls.driver)
# Log out
util.logout(cls.driver)
@classmethod
def tearDownClass(cls):
# Need to login again to delete project
util.login(
cls.driver,
cls.user_data['username'],
cls.user_data['password']
)
# Delete test project
util.delete_project(cls.driver)
# Close WebDriver
cls.driver.close()
def test_unauthorized_access_private_project(self):
"""
test user attempt to access a private repo w/o permission
checks alert message box text against expected alert message
"""
# point the browser at test project
self.driver.get(self.project_url)
# grab text from alert box presented to user
alerts = util.get_alert_boxes(self.driver, 'you are not authorized')
self.assertEqual(len(alerts), 1)
def test_attempted_access_nonexistent_project(self):
"""
test user attempt to access a non-existent
checks alert message box text against expected alert message
"""
# point the browser at a non-existent project
self.driver.get('%s/project/fakeproject/' % (config.osf_home))
# Must be exactly one matching alert
alerts = util.get_alert_boxes(self.driver, 'not a valid project')
self.assertEqual(len(alerts), 1)
# Run tests
if __name__ == '__main__':
unittest.main()