-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sciebo_disconnect.py
141 lines (114 loc) · 6.02 KB
/
test_sciebo_disconnect.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
""" 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
debugSleep = 3
class TestSciebo(unittest.TestCase):
def test_sciebo_rds_disconnect(self):
delay = g_driverTimeout # 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)
osfButtonIndex = '1'
zenodoButtonIndex = '2'
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
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)
try:
driver.find_element(by=By.XPATH, value='//*[@id="v-navigation-drawer"]/div[1]/div[4]/div/div/div[2]/div')
isConnected = True
except:
print("Settings button not found")
isConnected = False
if isConnected:
# 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()
# Check if we need an OSF connection
osfConnected = True
try:
print(driver.find_element(by=By.XPATH, value=f'//*[@id="inspire"]/div/main/div/div/main/div/div/div[2]/div[{osfButtonIndex}]/div[2]/div/div[2]/div/button/span/span[contains(text(),\'Disconnect\')]'))
except:
osfConnected = False
print("Not connected to OSF")
# Check if we need a Zenodo connection
zenodoConnected = True
try:
print(driver.find_element(by=By.XPATH, value=f'//*[@id="inspire"]/div/main/div/div/main/div/div/div[2]/div[{zenodoButtonIndex}]/div[2]/div/div[2]/div/button/span/span[contains(text(),\'Disconnect\')]'))
except:
zenodoConnected = False
print("Not connected to Zenodo")
if osfConnected:
print("Disconnect from OSF")
# Connect button for OSF
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, f'/html/body/div/div/div/main/div/div/main/div/div/div[2]/div[{osfButtonIndex}]/div[2]/div/div[2]/div/button/span/span'))).click()
if zenodoConnected:
print("Disconnect from Zenodo")
# Connect button for OSF
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, f'/html/body/div/div/div/main/div/div/main/div/div/div[2]/div[{zenodoButtonIndex}]/div[2]/div/div[2]/div/button/span/span'))).click()
# Click on settings button
print("Click on settings button")
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="v-navigation-drawer"]/div[1]/div[4]/div/div/div[2]/div'))).click()
print("Click remove account")
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="inspire"]/div[2]/div/div/div[2]/button/span/span'))).click()
print("Check box")
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="inspire"]/div[1]/main/div/div/div/div/div/div[1]/div/div/div[1]/div/div'))).click()
print("Click delete RDS account")
WebDriverWait(driver, g_driverTimeout).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="inspire"]/div[1]/main/div/div/div/div/div/div[2]/button/span/span'))).click()
print("Done...")
time.sleep(3)
if __name__ == '__main__':
# unittest.main()
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))