-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rds_nextcloud_local.py
278 lines (221 loc) · 13.2 KB
/
test_rds_nextcloud_local.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
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
273
274
275
276
277
278
""" 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
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
from datetime import datetime
# 'prod' for production environment, 'test' for test environment
g_testtarget = os.environ.get('NextcloudTestTarget')
g_rdslocal_nextcloud_url = 'https://test-nextcloud.localdomain.test/'
g_delay = 30
class TestRdsNextcloudLocal(unittest.TestCase):
def test_rds_nextcloud_local_login(self):
drv = sunetnextcloud.TestTarget(g_testtarget)
loginurl = g_rdslocal_nextcloud_url
print("Login url: ", loginurl)
sciebouserenv = "RDSLOCAL_NEXTCLOUD_USER"
sciebouser = os.environ.get(sciebouserenv)
sciebopwdenv = "RDSLOCAL_NEXTCLOUD_USER_PASSWORD"
nodepwd = os.environ.get(sciebopwdenv)
# We test locally, so we need to disable some of the certificate checks
chromeOptions = Options()
chromeOptions.add_argument("--disable-web-security")
chromeOptions.add_argument("--allow-running-insecure-content")
chromeOptions.add_argument("--ignore-ssl-errors=yes")
chromeOptions.add_argument("--ignore-certificate-errors")
chromeOptions.add_argument("--allow-insecure-localhost")
driver = webdriver.Chrome(options=chromeOptions)
driver.maximize_window()
# driver2 = webdriver.Firefox()
driver.get(loginurl)
wait = WebDriverWait(driver, g_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:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
print("Page is ready!")
proceed = True
except TimeoutException:
print("Loading took too much time!")
proceed = False
self.assertTrue(proceed)
def test_rds_nextcloud_local_project(self):
drv = sunetnextcloud.TestTarget(g_testtarget)
loginurl = g_rdslocal_nextcloud_url
print("Login url: ", loginurl)
sciebouserenv = "RDSLOCAL_NEXTCLOUD_USER"
sciebouser = os.environ.get(sciebouserenv)
sciebopwdenv = "RDSLOCAL_NEXTCLOUD_USER_PASSWORD"
nodepwd = os.environ.get(sciebopwdenv)
# We test locally, so we need to disable some of the certificate checks
chromeOptions = Options()
chromeOptions.add_argument("--disable-web-security")
chromeOptions.add_argument("--allow-running-insecure-content")
chromeOptions.add_argument("--ignore-ssl-errors=yes")
chromeOptions.add_argument("--ignore-certificate-errors")
chromeOptions.add_argument("--allow-insecure-localhost")
driver = webdriver.Chrome(options=chromeOptions)
driver.maximize_window()
# driver2 = webdriver.Firefox()
driver.get(loginurl)
wait = WebDriverWait(driver, g_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:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
print("Page is ready!")
proceed = True
except TimeoutException:
print("Loading took too much time!")
proceed = False
self.assertTrue(proceed)
try:
# rdsAppButton = driver.find_element(by=By.XPATH, value='//a[@href="'+ '/index.php/apps/rds/' +'"]')
rdsAppButton = driver.find_element(by=By.XPATH, value='//a[@href="'+ '/apps/rds/' +'"]')
rdsAppButton.click()
proceed = True
except TimeoutException:
print("Loading RDS took too much time!")
proceed = False
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")
# WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, ''))).click()
# Projects
# print(driver.find_element(by=By.XPATH, value='//*[@id="inspire"]/div/main/div/div/main/div/div/div[2]/div[2]/div[2]/div/div[2]/div/button/span/span[contains(text(),\'Connect\')]'))
# /html/body/div/div/div/nav/div[1]/div[2]/div/a[2]/div[2]/div[contains(text(),\'Projects\')]
print("Select projects from menu")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/nav/div[1]/div[2]/div/a[2]/div[2]/div[contains(text(),\'Projects\')]'))).click()
# New project
# /html/body/div/div/div/main/div/div/main/div/div/div/div[1]/div[3]/button/span
print("New project")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/main/div/div/div/div[1]/div[3]/button/span'))).click()
# Pick folder
# /html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div[2]/div/div/div[2]/div[2]/button/span
print("Click on pick folder")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div[2]/div/div/div[2]/div[2]/button/span'))).click()
# Folder RDSTest
# /html/body/div[5]/div[1]/ul/li[2]/div/span[1][contains(text(),\'RDSTest\')]
time.sleep(3)
# Span class is called 'filename'
# folderPickerFrame = driver.find_element(By.XPATH, '//iframe[1]')
# driver.switch_to.frame(folderPickerFrame)
# We need to switch to the parent frame to use RDS here
print("Switch to parent frame")
driver.switch_to.parent_frame()
print("Wait for folder RDSTest to be visible")
WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element((By.CLASS_NAME, "oc-dialog-title"), "Choose source folder"))
print("Visible!")
wait.until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div[1]/div/table/tbody/tr[3]/td[1]')))
# wait.until(EC.presence_of_element_located((By.XPATH, '/html/body/div[5]/div[1]/ul/li[2]/div/span[1]')))
print("Select folder RDSTest")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div[1]/div/table/tbody/tr[3]/td[1]'))).click()
print("Choose folder")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="body-user"]/div[1]/div[2]/button'))).click()
print("Switch back to RDS frame")
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")
# Input field always has a random ID
# //*[@id="input-101"]
# WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, ''))).click()
print("Input project name")
# projectInput = driver.find_element(By.XPATH, "//*[contains(@id, 'input-')]")
# print(projectInput)
# print("Here...")
tsProject = "Sunet Drive Test Project - " + datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(@id, 'input-')]"))).send_keys(tsProject)
# OSF repository
print("Select OSF to publish")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div[4]/div/div/div[2]/div[3]/div/div/div/div[3]'))).click()
# Continue button
print("Continue")
# /html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[3]/div/div/button/span
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[3]/div/div/button/span'))).click()
print("Switch back to Describo frame")
try:
print("Waiting for describo frame")
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "describoWindow")))
print("Describo iframe loaded")
except:
print("Describo iframe not loaded")
time.sleep(3)
# OSF Settings
print("Wait for OSF Settings and click")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id=\"tab-OSF settings\"]/span"))).click()
time.sleep(1)
# Check if we have to delete entries:
checkForOsfEntries = True
while checkForOsfEntries == True:
try:
deleteButton = driver.find_element(by=By.CLASS_NAME, value='el-button--danger')
deleteButton.click()
print("Deleting existing entries")
time.sleep(1)
except:
print("No more entries to delete, continue")
checkForOsfEntries = False
# OSF Text
# /html/body/div[1]/div/div/div[2]/div[2]/div[2]/div[1]/div/div/div/div[2]/div[2]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/div/div[1]/div/button/span
print("Click on +Text")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="pane-OSF settings"]/div/div[1]/div/div[2]/div[1]/div[1]/div/div[1]/div/button/span'))).click()
# OSF Add Text, again random number ID
print("Add OSF Title")
# wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(@id, 'el-id-')]"))).send_keys("OSF Title")
tsTitle = "RDS Sunet Drive Title - " + datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
wait.until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Add text']"))).send_keys(tsTitle + Keys.ENTER)
# //*[@id="el-id-4106-2"]
# WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="el-id-2110-7"]'))).click()
time.sleep(3)
print("Click on +Select for Osfcategory")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id=\"pane-OSF settings\"]/div/div[2]/div/div[2]/div[1]/div[1]/div/div[1]/div/button/span"))).click()
print("Click on category dropdown menu")
wait.until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Select']"))).click()
time.sleep(1)
print("Click on third entry in category list")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@id, 'el-popper-container-')]/div/div/div/div[1]/ul/li[3]"))).click()
time.sleep(1)
# print("Select data category")
# wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id=\"el-popper-container-254\"]/div/div/div/div[1]/ul/li[3]"))).click()
# time.sleep(1)
print("Click on +TextArea for OSF Description")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id=\"pane-OSF settings\"]/div/div[3]/div/div[2]/div[1]/div[1]/div/div[1]/div/button"))).click()
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'el-textarea__inner'))).send_keys("OSF Project Description")
print("Switch to parent frame")
driver.switch_to.parent_frame()
print("Click on continue button")
# /html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[3]/div/button[2]/span
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[3]/div/button[2]/span'))).click()
print("Click on publish button")
# /html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[3]/div/button[2]/span
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/main/div/div/main/div/div/div/div[2]/div/div/div/div[3]/div/button[2]/span'))).click()
try:
print("Waiting for publication notification")
WebDriverWait(driver, 60).until(EC.text_to_be_present_in_element((By.CLASS_NAME, "v-snack__content"), "successfully published"))
print("Looks like the data has been published! Well done!")
except:
print("Timeout while waiting for publication")
print("Done...")
time.sleep(3)
if __name__ == '__main__':
# unittest.main()
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))