-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sciebo_connect.py
199 lines (162 loc) · 8.21 KB
/
test_sciebo_connect.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
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
""" Selenium tests for Sciebo
Author: Richard Freitag <freitag@sunet.se>
Selenium tests to log on to the Sciebo test node, performing various operations to ensure basic operation
"""
import xmlrunner
import unittest
import sunetnextcloud
from webdav3.client import Client
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
import os
import time
# 'prod' for production environment, 'test' for test environment
g_testtarget = os.environ.get('NextcloudTestTarget')
g_sciebourl = 'https://sns-testing.sciebo.de'
g_driverTimeout = 30
class TestSciebo(unittest.TestCase):
def test_sciebo_rds_authorization(self):
delay = 30 # seconds
drv = sunetnextcloud.TestTarget(g_testtarget)
loginurl = g_sciebourl
print("Login url: ", loginurl)
sciebouserenv = "SCIEBO_USER"
sciebouser = os.environ.get(sciebouserenv)
sciebopwdenv = "SCIEBO_USER_PASSWORD"
nodepwd = os.environ.get(sciebopwdenv)
osfuserenv = "OSF_TEST_USER"
osfuser = os.environ.get(osfuserenv)
osfpwdenv = "OSF_TEST_USER_PASSWORD"
osfpwd = os.environ.get(osfpwdenv)
zenodouserenv = "ZENODO_TEST_USER"
zenodouser = os.environ.get(zenodouserenv)
zenodopwdenv = "ZENODO_TEST_USER_PASSWORD"
zenodopwd = os.environ.get(zenodopwdenv)
skipZenodoConnection = True
try:
options = Options()
driver = webdriver.Chrome(options=options)
except:
self.logger.error(f'Error initializing Chrome driver')
self.assertTrue(False)
driver.maximize_window()
# driver2 = webdriver.Firefox()
driver.get(loginurl)
# Store the ID of the original window
original_window = driver.current_window_handle
print(f'Window handle: {original_window}')
wait = WebDriverWait(driver, delay)
wait.until(EC.presence_of_element_located((By.ID, 'user'))).send_keys(sciebouser)
wait.until(EC.presence_of_element_located((By.ID, 'password'))).send_keys(nodepwd + Keys.ENTER)
try:
myElem = wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'All files')))
print("All files visible!")
except TimeoutException:
print("Loading of all files took too much time!")
burgerButton = driver.find_element(by=By.CLASS_NAME, value='burger')
burgerButton.click()
time.sleep(1)
rdsAppButton = driver.find_element(by=By.XPATH, value='//a[@href="'+ '/apps/rds/' +'"]')
rdsAppButton.click()
time.sleep(1)
try:
print("Waiting for rds frame")
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "rds-editor")))
print("RDS iframe loaded")
except:
print("RDS iframe not loaded")
time.sleep(3)
# Getting started button
try:
driver.find_element(by=By.XPATH, value='/html/body/div/div/div/main/div/div/div/div[1]/div/button/span/span')
needsToConnect = True
except:
print("Sciebo is already connected")
needsToConnect = False
if needsToConnect:
try:
print("Try to find getting started button...")
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/div/div[1]/div/button/span/span'))).click()
print("Getting started button visible!")
except TimeoutException:
print("Unable to find getting started button!")
# Loop through until we find a new window handle
for window_handle in driver.window_handles:
if window_handle != original_window:
driver.switch_to.window(window_handle)
break
print("Switched to authentication window")
wait.until(EC.presence_of_element_located((By.ID, 'user'))).send_keys(sciebouser)
wait.until(EC.presence_of_element_located((By.ID, 'password'))).send_keys(nodepwd + Keys.ENTER)
# Click authorize
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="body-login"]/div[1]/div/span/form/button'))).click()
time.sleep(3)
print("Switch back to original window")
driver.switch_to.window(original_window)
try:
print("Waiting for rds frame")
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "rds-editor")))
print("RDS iframe loaded")
except:
print("RDS iframe not loaded")
# Now go for the repository connections
# Click repositories
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/nav/div[1]/div[2]/div/a[3]/div[2]/div'))).click()
try:
buttons = driver.find_elements(By.XPATH, "//button")
for button in buttons:
if button.text == 'CONNECT':
print("Connecting...")
button.click()
# Loop through until we find a new window handle
for window_handle in driver.window_handles:
if window_handle != original_window:
driver.switch_to.window(window_handle)
break
isZenodo = False
isOsf = False
try:
driver.find_element(By.ID, value='username')
isOsf = True
except:
isZenodo = True
if isZenodo:
print("Connect to Zenodo")
if skipZenodoConnection == True:
driver.close()
else:
wait.until(EC.presence_of_element_located((By.ID, 'email'))).send_keys(zenodouser)
wait.until(EC.presence_of_element_located((By.ID, 'password'))).send_keys(zenodopwd + Keys.ENTER)
# Allow connection
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.CLASS_NAME, 'btn-success'))).click()
print("Switch back to main window and make sure that the RDS frame is active")
driver.switch_to.window(driver.window_handles[-1])
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "rds-editor")))
print("RDS iframe active")
time.sleep(3)
if isOsf:
print("Connect to OSF")
wait.until(EC.presence_of_element_located((By.ID, 'username'))).send_keys(osfuser)
wait.until(EC.presence_of_element_located((By.ID, 'password'))).send_keys(osfpwd + Keys.ENTER)
# Allow connection
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="allow"]/span'))).click()
print(f'Done connecting to OSF')
print("Switch back to main window and make sure that the RDS frame is active")
driver.switch_to.window(driver.window_handles[-1])
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "rds-editor")))
print("RDS iframe active")
time.sleep(3)
except:
print("Error trying to connect to one of the repositories")
print("All connections established")
time.sleep(3)
if __name__ == '__main__':
# unittest.main()
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))