From 00ba0c59f9e81329c3cd924e938a4cc3c881cea1 Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Mon, 7 Jul 2025 07:21:51 +0200 Subject: [PATCH 1/8] Adding test dir --- selenium_tests/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 selenium_tests/README.md diff --git a/selenium_tests/README.md b/selenium_tests/README.md new file mode 100644 index 00000000..66eccd10 --- /dev/null +++ b/selenium_tests/README.md @@ -0,0 +1 @@ +Here there will be Selenium tests for Sciebo-rdsng From cab0700a0d1a12cde331775eda0948a2d3fb6320 Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Mon, 7 Jul 2025 08:55:49 +0200 Subject: [PATCH 2/8] Add two tests for adding connectors and creating new project --- selenium_tests/README.md | 2 +- selenium_tests/add_connector.py | 140 ++++++++++++++++++++++++++ selenium_tests/new_project.py | 167 ++++++++++++++++++++++++++++++++ 3 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 selenium_tests/add_connector.py create mode 100644 selenium_tests/new_project.py diff --git a/selenium_tests/README.md b/selenium_tests/README.md index 66eccd10..042fd029 100644 --- a/selenium_tests/README.md +++ b/selenium_tests/README.md @@ -1 +1 @@ -Here there will be Selenium tests for Sciebo-rdsng +# Here there will be Selenium tests for Sciebo-rdsng diff --git a/selenium_tests/add_connector.py b/selenium_tests/add_connector.py new file mode 100644 index 00000000..e3d36504 --- /dev/null +++ b/selenium_tests/add_connector.py @@ -0,0 +1,140 @@ +import time +import os +from dotenv import load_dotenv +from selenium.webdriver import ActionChains +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException, NoSuchElementException +load_dotenv() +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" + + +# Set up headless Firefox +options = Options() +options.headless = True +driver = webdriver.Firefox(options=options) + +try: + # 1) Go to the login page + driver.get(LOGIN_URL) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.NAME, "user")) + ) + + # 2) Fill in credentials and submit + driver.find_element(By.NAME, "user").send_keys(USERNAME) + driver.find_element(By.NAME, "password").send_keys(PASSWORD + Keys.RETURN) + + # 3) Wait until redirected to dashboard or home + WebDriverWait(driver, 20).until( + EC.any_of( + EC.url_contains("dashboard"), + EC.url_contains("home") + ) + ) + print("Login successful, on dashboard.") + + # 4) Wait for the menu to render + WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "ul.app-menu-main")) + ) + + # 5) Locate and click the "BridgIT" item under data-app-id="rdsng" + try: + bridgit_link = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.CSS_SELECTOR, "li[data-app-id='rdsng'] > a") + ) + ) + # Scroll it into view then click + driver.execute_script( + "arguments[0].scrollIntoView({block: 'center'});", + bridgit_link + ) + bridgit_link.click() + + WebDriverWait(driver, 10).until( + EC.url_contains("/apps/rdsng/main") + ) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "div.app-main-content")) + ) + print("Clicked on BridgIT menu entry!") + except Exception as e: + print("Failed to find or click the BridgIT menu item:", str(e)) + + # 6) Switch into the iframe + WebDriverWait(driver, 20).until( + EC.frame_to_be_available_and_switch_to_it((By.ID, "app-frame")) + ) + print("Switched into app-frame iframe!") + # 7) Click the settings icon + settings_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[contains(@class,'mi-settings')]]" + )) + ) + settings_btn.click() + print("Clicked settings icon.") + + # 8) Click "Add a new connection..." placeholder + add_conn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.CSS_SELECTOR, + "span.p-select-label.p-placeholder[aria-label='Add a new connection...']" + )) + ) + add_conn.click() + print("Opened new connection dropdown.") + + # 9) Wait for the dropdown list to expand (uses the aria-controls ID) + options_container = WebDriverWait(driver, 20).until( + EC.visibility_of_element_located((By.ID, "pv_id_1_10_list")) + ) + + # 10) Click the second option in the list + second_option = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.CSS_SELECTOR, + "#pv_id_1_10_list li[role='option']:nth-child(2)" + )) + ) + second_option.click() + print("Selected second connection option.") + #time.sleep(10) + # 11) Fill in the connection “Name” field + conn_name = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.NAME, "name")) + ) + conn_name.clear() + conn_name.send_keys("My Connection Name") + print("Filled connection name.") + + # 12) Fill in the connection “Description” textarea + conn_desc = WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.NAME, "description")) + ) + conn_desc.clear() + conn_desc.send_keys("This is a description for my new connection.") + print("Filled connection description.") + + # 13) Click the “Create” button + create_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[text()='Create']]" + )) + ) + create_btn.click() + print("Clicked Create button for new connection!") + + +finally: + driver.quit() diff --git a/selenium_tests/new_project.py b/selenium_tests/new_project.py new file mode 100644 index 00000000..57257680 --- /dev/null +++ b/selenium_tests/new_project.py @@ -0,0 +1,167 @@ +import time +import os +from selenium.webdriver import ActionChains +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException, NoSuchElementException +from dotenv import load_dotenv +load_dotenv() +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" + + + +# Set up headless Firefox +options = Options() +options.headless = True +driver = webdriver.Firefox(options=options) + +try: + # 1) Go to the login page + driver.get(LOGIN_URL) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.NAME, "user")) + ) + + # 2) Fill in credentials and submit + driver.find_element(By.NAME, "user").send_keys(USERNAME) + driver.find_element(By.NAME, "password").send_keys(PASSWORD + Keys.RETURN) + + # 3) Wait until redirected to dashboard or home + WebDriverWait(driver, 20).until( + EC.any_of( + EC.url_contains("dashboard"), + EC.url_contains("home") + ) + ) + print("Login successful, on dashboard.") + + # 4) Wait for the menu to render + WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "ul.app-menu-main")) + ) + + # 5) Locate and click the "BridgIT" item under data-app-id="rdsng" + try: + bridgit_link = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.CSS_SELECTOR, "li[data-app-id='rdsng'] > a") + ) + ) + # Scroll it into view then click + driver.execute_script( + "arguments[0].scrollIntoView({block: 'center'});", + bridgit_link + ) + bridgit_link.click() + + WebDriverWait(driver, 10).until( + EC.url_contains("/apps/rdsng/main") + ) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "div.app-main-content")) + ) + print("Clicked on BridgIT menu entry!") + except Exception as e: + print("Failed to find or click the BridgIT menu item:", str(e)) + + # 6) Switch into the iframe + WebDriverWait(driver, 20).until( + EC.frame_to_be_available_and_switch_to_it((By.ID, "app-frame")) + ) + print("Switched into app-frame iframe!") + + # 7) Click the "New project" button + new_proj_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[aria-label="New project"]')) + ) + new_proj_btn.click() + time.sleep(2) # brief pause for the dialog to appear + + # 8) Wait for the Name field and fill it + name_input = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.NAME, "title")) + ) + name_input.clear() + name_input.send_keys("My Awesome Project") + print("Filled in project name.") + + # 9) Wait for the Description textarea and fill it + desc_area = WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.NAME, "description")) + ) + desc_area.clear() + desc_area.send_keys("This is a description for my awesome project.") + print("Filled in project description.") + # 10) Wait for the "Next" button and click it + next_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[text()='Next']]" + )) + ) + next_btn.click() + # 11) Select the “All files” tree node + all_files_node = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//div[contains(@class,'p-tree-node-content') and .//span[text()='All files']]" + )) + ) + all_files_node.click() + print("Selected 'All files' node.") + + # 12) Click the Next button again + next_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[text()='Next']]" + )) + ) + next_btn.click() + print("Clicked Next button!") + + + + # 13) Click the first (large) checkbox with ActionChains + first_checkbox = WebDriverWait(driver,5).until( + EC.element_to_be_clickable((By.CSS_SELECTOR, "div.p-checkbox-box[data-p='large']")) + ) + ActionChains(driver).move_to_element(first_checkbox).click().perform() + print("Clicked first checkbox with ActionChains.") + + # 14) Click the second (dmp) checkbox with ActionChains + second_checkbox = WebDriverWait(driver, 5).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "input#dmp")) + ) + ActionChains(driver).move_to_element(second_checkbox).click().perform() + print("Clicked 'dmp' checkbox with ActionChains.") + + # 15) Click the arrow‐forward “Next” button + next_arrow = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[contains(@class,'mi-arrow-forward')]]" + )) + ) + next_arrow.click() + print("Clicked the next arrow button.") + # 16) Click the "Create" button + create_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[text()='Create']]" + )) + ) + create_btn.click() + print("Clicked Create button!") + time.sleep(10) + +finally: + driver.quit() + From 4ac9d655d5ede529c5f5f62990ddc66b5a8157f3 Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Mon, 7 Jul 2025 10:48:36 +0200 Subject: [PATCH 3/8] Filling the Data Managment Plan boxses and check the pdf and txt download. --- selenium_tests/download_data.py | 112 ++++++++++++++++++++++++++++ selenium_tests/fill_dmp.py | 127 ++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 selenium_tests/download_data.py create mode 100644 selenium_tests/fill_dmp.py diff --git a/selenium_tests/download_data.py b/selenium_tests/download_data.py new file mode 100644 index 00000000..662b5a24 --- /dev/null +++ b/selenium_tests/download_data.py @@ -0,0 +1,112 @@ +import time +import os +from dotenv import load_dotenv +from selenium.webdriver import ActionChains +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException, NoSuchElementException + +load_dotenv() +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" + +# Set up headless Firefox +options = Options() +options.headless = True +driver = webdriver.Firefox(options=options) + +try: + # 1) Go to the login page + driver.get(LOGIN_URL) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.NAME, "user")) + ) + + # 2) Fill in credentials and submit + driver.find_element(By.NAME, "user").send_keys(USERNAME) + driver.find_element(By.NAME, "password").send_keys(PASSWORD + Keys.RETURN) + + # 3) Wait until redirected to dashboard or home + WebDriverWait(driver, 20).until( + EC.any_of( + EC.url_contains("dashboard"), + EC.url_contains("home") + ) + ) + print("Login successful, on dashboard.") + + # 4) Wait for the menu to render + WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "ul.app-menu-main")) + ) + + # 5) Locate and click the "BridgIT" item under data-app-id="rdsng" + try: + bridgit_link = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.CSS_SELECTOR, "li[data-app-id='rdsng'] > a") + ) + ) + # Scroll it into view then click + driver.execute_script( + "arguments[0].scrollIntoView({block: 'center'});", + bridgit_link + ) + bridgit_link.click() + + WebDriverWait(driver, 10).until( + EC.url_contains("/apps/rdsng/main") + ) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "div.app-main-content")) + ) + print("Clicked on BridgIT menu entry!") + except Exception as e: + print("Failed to find or click the BridgIT menu item:", str(e)) + + # 6) Switch into the iframe + WebDriverWait(driver, 10).until( + EC.frame_to_be_available_and_switch_to_it((By.ID, "app-frame")) + ) + + # 7) Click the “My Awesome Project” card itself using a CSS selector + project_card = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable(( + By.CSS_SELECTOR, + ".projects-listbox-container div[title='My Awesome Project']" + )) + ) + project_card.click() + print("Clicked on 'My Awesome Project'.") + + # 8) Click the “Data Management Plan” tab by its visible label + dmp_tab = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[text()='Data Management Plan']]" + )) + ) + dmp_tab.click() + print("Clicked the Data Management Plan tab.") + + # 9) Click the “PDF” export button + pdf_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[aria-label="PDF"]')) + ) + pdf_btn.click() + print("Clicked PDF export button.") + + # 10) Click the “Plain Text” export button + text_btn = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[aria-label="Plain Text"]')) + ) + text_btn.click() + print("Clicked Plain Text export button.") + +finally: + driver.quit() diff --git a/selenium_tests/fill_dmp.py b/selenium_tests/fill_dmp.py new file mode 100644 index 00000000..d4294c22 --- /dev/null +++ b/selenium_tests/fill_dmp.py @@ -0,0 +1,127 @@ +import time +import os +from dotenv import load_dotenv +from selenium.webdriver import ActionChains +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException, NoSuchElementException +load_dotenv() +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" + + +# Set up headless Firefox +options = Options() +options.headless = True +driver = webdriver.Firefox(options=options) + +try: + # 1) Go to the login page + driver.get(LOGIN_URL) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.NAME, "user")) + ) + + # 2) Fill in credentials and submit + driver.find_element(By.NAME, "user").send_keys(USERNAME) + driver.find_element(By.NAME, "password").send_keys(PASSWORD + Keys.RETURN) + + # 3) Wait until redirected to dashboard or home + WebDriverWait(driver, 20).until( + EC.any_of( + EC.url_contains("dashboard"), + EC.url_contains("home") + ) + ) + print("Login successful, on dashboard.") + + # 4) Wait for the menu to render + WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "ul.app-menu-main")) + ) + + # 5) Locate and click the "BridgIT" item under data-app-id="rdsng" + try: + bridgit_link = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.CSS_SELECTOR, "li[data-app-id='rdsng'] > a") + ) + ) + # Scroll it into view then click + driver.execute_script( + "arguments[0].scrollIntoView({block: 'center'});", + bridgit_link + ) + bridgit_link.click() + + WebDriverWait(driver, 10).until( + EC.url_contains("/apps/rdsng/main") + ) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "div.app-main-content")) + ) + print("Clicked on BridgIT menu entry!") + except Exception as e: + print("Failed to find or click the BridgIT menu item:", str(e)) + + # 6) Switch into the iframe + WebDriverWait(driver, 10).until( + EC.frame_to_be_available_and_switch_to_it((By.ID, "app-frame")) + ) + + # 7) Click the “My Awesome Project” card itself using a CSS selector + project_card = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable(( + By.CSS_SELECTOR, + ".projects-listbox-container div[title='My Awesome Project']" + )) + ) + project_card.click() + print("Clicked on 'My Awesome Project'.") + + + # 8) Click the “Data Management Plan” tab by its visible label + dmp_tab = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable(( + By.XPATH, + "//button[.//span[text()='Data Management Plan']]" + )) + ) + dmp_tab.click() + print("Clicked the Data Management Plan tab.") + # 9) Find and fill **all** textareas on the DMP page + textareas = WebDriverWait(driver, 20).until( + EC.presence_of_all_elements_located((By.CSS_SELECTOR, "textarea.p-textarea")) + ) + + # Prepare as many answers as you expect; extras will get a default. + custom_answers = [ + "Neue Daten entstehen durch automatisierte Sensoraufnahmen im Feld.", + "Ja, wir nutzen existierende Umfragedaten aus früheren Projekten erneut.", + "In welchem Umfang fallen diese an bzw. welches Datenvolumen ist zu erwarten?", + # …add more if you know exactly which questions appear… + ] + + for idx, ta in enumerate(textareas, start=1): + # scroll each into view + driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", ta) + ta.clear() + # pick a custom answer if available, otherwise use a generic fallback + answer = ( + custom_answers[idx-1] + if idx-1 < len(custom_answers) + else f"Automated answer for textarea #{idx}" + ) + ta.send_keys(answer) + print(f"Filled textarea #{idx} with: {answer}") + time.sleep(5) # slight pause so each input registers + + + +finally: + driver.quit() From 0e89a8d0604ea22618806cffb68e6652334dc082 Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Thu, 31 Jul 2025 09:39:31 +0200 Subject: [PATCH 4/8] test to connect to osf --- selenium_tests/osf_connector.py | 172 ++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 selenium_tests/osf_connector.py diff --git a/selenium_tests/osf_connector.py b/selenium_tests/osf_connector.py new file mode 100644 index 00000000..d17f8b26 --- /dev/null +++ b/selenium_tests/osf_connector.py @@ -0,0 +1,172 @@ +import time +import os +from selenium.webdriver import ActionChains +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException, NoSuchElementException +from dotenv import load_dotenv + +load_dotenv() + +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" + +# Set up headless Firefox +options = Options() +options.headless = True +driver = webdriver.Firefox(options=options) + +try: + # 1) Go to the login page + driver.get(LOGIN_URL) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.NAME, "user")) + ) + + # 2) Fill in credentials and submit + driver.find_element(By.NAME, "user").send_keys(USERNAME) + driver.find_element(By.NAME, "password").send_keys(PASSWORD + Keys.RETURN) + + # 3) Wait until redirected to dashboard or home + WebDriverWait(driver, 20).until( + EC.any_of( + EC.url_contains("dashboard"), + EC.url_contains("home") + ) + ) + print("Login successful, on dashboard.") + + # 4) Wait for the menu to render + WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "ul.app-menu-main")) + ) + + # 5) Locate and click the "BridgIT" item under data-app-id="rdsng" + try: + bridgit_link = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.CSS_SELECTOR, "li[data-app-id='rdsng'] > a") + ) + ) + # Scroll it into view then click + driver.execute_script( + "arguments[0].scrollIntoView({block: 'center'});", + bridgit_link + ) + bridgit_link.click() + + WebDriverWait(driver, 10).until( + EC.url_contains("/apps/rdsng/main") + ) + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, "div.app-main-content")) + ) + print("Clicked on BridgIT menu entry!") + except Exception as e: + print("Failed to find or click the BridgIT menu item:", str(e)) + + # 6) Switch into the iframe + WebDriverWait(driver, 20).until( + EC.frame_to_be_available_and_switch_to_it((By.ID, "app-frame")) + ) + print("Switched into app-frame iframe!") + + # 7) Click on settings icon + try: + settings_button = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.XPATH, "/html/body/div[1]/div[2]/div[1]/div[1]/div[2]/button[1]") + ) + ) + settings_button.click() + print("Clicked on settings icon!") + + # Wait a moment for the settings panel to open + time.sleep(2) + + except Exception as e: + print("Failed to find or click the settings icon:", str(e)) + + # 8) Click on connect button + try: + # Store current window handle before clicking + current_window = driver.current_window_handle + print(f"Current window handle: {current_window}") + + connect_button = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.XPATH, "/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/div/div[3]/div[1]/div/div/div/div/div/div/div/div[3]/button/span[1]") + ) + ) + connect_button.click() + print("Clicked on connect button!") + + # Wait for new tab/window to open + WebDriverWait(driver, 10).until(lambda d: len(d.window_handles) > 1) + + # Get all window handles + all_windows = driver.window_handles + print(f"All window handles: {all_windows}") + + # Switch to the new tab (the one that's not the current window) + for window in all_windows: + if window != current_window: + driver.switch_to.window(window) + print(f"Switched to new tab: {window}") + break + + # Wait for the new page to load + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.TAG_NAME, "body")) + ) + + print(f"New tab URL: {driver.current_url}") + print("Successfully switched to the new tab!") + + # 9) Fill in login credentials on the new tab + try: + # Wait for username field to be present and fill it + username_field = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.ID, "username")) + ) + username_field.clear() + username_field.send_keys(USERNAME) + print("Filled username field!") + + # Wait for password field to be present and fill it + password_field = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.ID, "password")) + ) + password_field.clear() + password_field.send_keys(PASSWORD) + print("Filled password field!") + + # Submit the form (you can either press Enter or find a submit button) + # Option 1: Press Enter on password field + password_field.send_keys(Keys.RETURN) + print("Submitted login form!") + + # Option 2: If there's a specific login button, uncomment below: + # login_button = WebDriverWait(driver, 10).until( + # EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']")) + # ) + # login_button.click() + + # Wait for successful login (adjust the condition based on what happens after login) + time.sleep(3) # Give some time for the login to process + print(f"Login completed! Current URL: {driver.current_url}") + + except Exception as e: + print("Failed to fill login credentials on new tab:", str(e)) + + except Exception as e: + print("Failed to find connect button or switch tabs:", str(e)) + +finally: + # Close all windows + driver.quit() From 612670f35d0c55fdb087b00be20709d0efd5d414 Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Mon, 11 Aug 2025 11:10:59 +0200 Subject: [PATCH 5/8] Authorization test --- selenium_tests/auth.py | 146 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 selenium_tests/auth.py diff --git a/selenium_tests/auth.py b/selenium_tests/auth.py new file mode 100644 index 00000000..2c2ceae9 --- /dev/null +++ b/selenium_tests/auth.py @@ -0,0 +1,146 @@ +import time +import os +from selenium.webdriver import ActionChains +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException, NoSuchElementException, StaleElementReferenceException +from dotenv import load_dotenv + +load_dotenv() +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = "https://ncpoc.sciebo.de/apps/rdsng/main" + +# Set up headless Firefox +options = Options() +options.headless = True +driver = webdriver.Firefox(options=options) + +wait = WebDriverWait(driver, 20) + +def switch_to_default(): + try: + driver.switch_to.default_content() + except Exception: + pass + +def find_in_any_frame(by, sel, timeout_each=6): + """ + Try to find element in default content; if not found, try each iframe (one level). + Returns the element and leaves Selenium focused in the correct context. + """ + switch_to_default() + try: + return WebDriverWait(driver, timeout_each).until( + EC.presence_of_element_located((by, sel)) + ) + except TimeoutException: + pass + + frames = driver.find_elements(By.TAG_NAME, "iframe") + for f in frames: + try: + driver.switch_to.frame(f) + el = WebDriverWait(driver, timeout_each).until( + EC.presence_of_element_located((by, sel)) + ) + return el + except TimeoutException: + switch_to_default() + continue + except StaleElementReferenceException: + switch_to_default() + continue + + switch_to_default() + raise TimeoutException(f"Element not found: {by}={sel}") + +try: + # 1) Go to the login page + driver.get(LOGIN_URL) + wait.until(EC.presence_of_element_located((By.NAME, "user"))) + + # 2) Fill in credentials and submit + driver.find_element(By.NAME, "user").send_keys(USERNAME) + driver.find_element(By.NAME, "password").send_keys(PASSWORD + Keys.RETURN) + + time.sleep(2) + print("Opened BridgIT page directly.") + + # 3) Switch into app iframe if present (#app-frame) + try: + WebDriverWait(driver, 10).until( + EC.frame_to_be_available_and_switch_to_it((By.ID, "app-frame")) + ) + print("Switched into app-frame iframe!") + except TimeoutException: + switch_to_default() + print("app-frame not present yet; staying in default content.") + + # 4) Click "Authorize bridgit" + try: + authorize_label_xpath = "//span[contains(@class,'p-button-label') and normalize-space()='Authorize bridgit']" + try: + authorize_span = WebDriverWait(driver, 15).until( + EC.element_to_be_clickable((By.XPATH, authorize_label_xpath)) + ) + except TimeoutException: + switch_to_default() + authorize_span = WebDriverWait(driver, 1).until( + lambda d: find_in_any_frame(By.XPATH, authorize_label_xpath) + ) + + driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", authorize_span) + try: + authorize_span.click() + except Exception: + parent_btn = authorize_span.find_element(By.XPATH, "./ancestor::button[1]") + parent_btn.click() + + print("Clicked 'Authorize bridgit' button successfully!") + except TimeoutException: + print("Authorize bridgit button not found or not clickable (maybe already authorized).") + + # 5) Click "Anmelden" + switch_to_default() + try: + WebDriverWait(driver, 20).until( + EC.any_of( + EC.presence_of_element_located((By.CSS_SELECTOR, "input[type='submit'][value='Anmelden']")), + EC.presence_of_element_located((By.TAG_NAME, "iframe")) + ) + ) + + anmelden_input = find_in_any_frame(By.CSS_SELECTOR, "input[type='submit'][value='Anmelden']") + driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", anmelden_input) + wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit'][value='Anmelden']"))) + anmelden_input.click() + print("Clicked 'Anmelden' submit button.") + except TimeoutException: + print("Could not find the 'Anmelden' button after redirect.") + + # 6) Click "Zugriff gewähren" + switch_to_default() + try: + WebDriverWait(driver, 20).until( + EC.any_of( + EC.presence_of_element_located((By.CSS_SELECTOR, "input[type='submit'][value='Zugriff gewähren']")), + EC.presence_of_element_located((By.TAG_NAME, "iframe")) + ) + ) + + zugriff_input = find_in_any_frame(By.CSS_SELECTOR, "input[type='submit'][value='Zugriff gewähren']") + driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", zugriff_input) + wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit'][value='Zugriff gewähren']"))) + zugriff_input.click() + print("Clicked 'Zugriff gewähren' submit button.") + except TimeoutException: + print("Could not find the 'Zugriff gewähren' button after redirect.") + time.sleep(10) + +finally: + driver.quit() From 4983dd868d57cf8987bd91ef73f170c23e7d672e Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Mon, 18 Aug 2025 09:32:14 +0200 Subject: [PATCH 6/8] add env template --- selenium_tests/.env | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 selenium_tests/.env diff --git a/selenium_tests/.env b/selenium_tests/.env new file mode 100644 index 00000000..d116fb9f --- /dev/null +++ b/selenium_tests/.env @@ -0,0 +1,3 @@ +RDS_USER=user +RDS_PASS=pass +RDS_URL=url From 3993d93e07727f6a0b02a99f7fd784a151d8a661 Mon Sep 17 00:00:00 2001 From: Soroush9978! Date: Mon, 18 Aug 2025 09:33:49 +0200 Subject: [PATCH 7/8] rename files and use url as env variable --- selenium_tests/add_connector.py | 3 ++- selenium_tests/auth.py | 2 +- selenium_tests/{download_data.py => download_dmp_data.py} | 2 +- selenium_tests/{fill_dmp.py => fill_data_dmp.py} | 2 +- selenium_tests/new_project.py | 2 +- selenium_tests/osf_connector.py | 6 +++--- 6 files changed, 9 insertions(+), 8 deletions(-) rename selenium_tests/{download_data.py => download_dmp_data.py} (98%) rename selenium_tests/{fill_dmp.py => fill_data_dmp.py} (98%) diff --git a/selenium_tests/add_connector.py b/selenium_tests/add_connector.py index e3d36504..5169ca4f 100644 --- a/selenium_tests/add_connector.py +++ b/selenium_tests/add_connector.py @@ -12,7 +12,8 @@ load_dotenv() USERNAME = os.getenv("RDS_USER") PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" +LOGIN_URL = os.getenv("RDS_URL") + # Set up headless Firefox diff --git a/selenium_tests/auth.py b/selenium_tests/auth.py index 2c2ceae9..712983af 100644 --- a/selenium_tests/auth.py +++ b/selenium_tests/auth.py @@ -13,7 +13,7 @@ load_dotenv() USERNAME = os.getenv("RDS_USER") PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = "https://ncpoc.sciebo.de/apps/rdsng/main" +LOGIN_URL = os.getenc("RDS_URL") # Set up headless Firefox options = Options() diff --git a/selenium_tests/download_data.py b/selenium_tests/download_dmp_data.py similarity index 98% rename from selenium_tests/download_data.py rename to selenium_tests/download_dmp_data.py index 662b5a24..1b2a00e1 100644 --- a/selenium_tests/download_data.py +++ b/selenium_tests/download_dmp_data.py @@ -13,7 +13,7 @@ load_dotenv() USERNAME = os.getenv("RDS_USER") PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" +LOGIN_URL = os.getenv("RDS_URL") # Set up headless Firefox options = Options() diff --git a/selenium_tests/fill_dmp.py b/selenium_tests/fill_data_dmp.py similarity index 98% rename from selenium_tests/fill_dmp.py rename to selenium_tests/fill_data_dmp.py index d4294c22..c1e71a69 100644 --- a/selenium_tests/fill_dmp.py +++ b/selenium_tests/fill_data_dmp.py @@ -12,7 +12,7 @@ load_dotenv() USERNAME = os.getenv("RDS_USER") PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" +LOGIN_URL = os.getenv("RDS_URL") # Set up headless Firefox diff --git a/selenium_tests/new_project.py b/selenium_tests/new_project.py index 57257680..51d13457 100644 --- a/selenium_tests/new_project.py +++ b/selenium_tests/new_project.py @@ -12,7 +12,7 @@ load_dotenv() USERNAME = os.getenv("RDS_USER") PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" +LOGIN_URL = os.getenv("RDS_URL") diff --git a/selenium_tests/osf_connector.py b/selenium_tests/osf_connector.py index d17f8b26..009ac7d7 100644 --- a/selenium_tests/osf_connector.py +++ b/selenium_tests/osf_connector.py @@ -12,9 +12,9 @@ load_dotenv() -USERNAME = os.getenv("RDS_USER") -PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = "https://rds-ng-internal.uni-muenster.de/login?clear=1" +USERNAME = os.getenv("RDS_USER") +PASSWORD = os.getenv("RDS_PASS") +LOGIN_URL = os.getenv("RDS_URL") # Set up headless Firefox options = Options() From 68cf72576b0cf61355769773287ecc0ceb54c7f8 Mon Sep 17 00:00:00 2001 From: Soroush Date: Mon, 18 Aug 2025 09:41:49 +0200 Subject: [PATCH 8/8] Update auth.py --- selenium_tests/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selenium_tests/auth.py b/selenium_tests/auth.py index 712983af..82ac8a14 100644 --- a/selenium_tests/auth.py +++ b/selenium_tests/auth.py @@ -13,7 +13,7 @@ load_dotenv() USERNAME = os.getenv("RDS_USER") PASSWORD = os.getenv("RDS_PASS") -LOGIN_URL = os.getenc("RDS_URL") +LOGIN_URL = os.getenv("RDS_URL") # Set up headless Firefox options = Options()