Skip to content

Commit

Permalink
Add OBI_USERNAME and OBI_PASSWORD as environment variables
Browse files Browse the repository at this point in the history
Update conftest login() and navigate_to_login()
Update the config file in util_base.py to reflect the changes
  • Loading branch information
Ayima Okeeva committed Dec 3, 2024
1 parent c202a08 commit 4b79705
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
14 changes: 10 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def navigate_to_login(setup):
browser, wait = setup
login_page = LoginPage(browser, wait)

username = os.environ.get("USERNAME")
password = os.environ.get("PASSWORD")
username = os.environ.get("OBI_USERNAME")
password = os.environ.get("OBI_PASSWORD")

if not username or not password:
raise ValueError("Missing USERNAME or PASSWORD environment variables.")
Expand All @@ -154,9 +154,15 @@ def login(setup, navigate_to_login):
"""Fixture to log in and ensure user is authenticated."""
browser, wait = setup
login_page = navigate_to_login

config = load_config()
username = config['username']
password = config['password']
if not config:
raise ValueError("Failed to load configuration")
username = config.get('username')
password = config.get('password')

if not username or not password:
raise ValueError("Username or password is missing in the configuration!")

login_page.perform_login(username, password)
login_page.wait_for_login_complete()
Expand Down
5 changes: 4 additions & 1 deletion pages/login_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2024 Blue Brain Project/EPFL
#
# SPDX-License-Identifier: Apache-2.0

import logging
import time

from selenium.common import TimeoutException
Expand All @@ -15,6 +15,7 @@
class LoginPage(CustomBasePage):
def __init__(self, browser, wait):
super().__init__(browser, wait)
self.logger = logging.getLogger(__name__)

def navigate_to_homepage(self):
self.browser.delete_all_cookies()
Expand Down Expand Up @@ -53,6 +54,8 @@ def find_submit(self):
return self.wait.until(EC.element_to_be_clickable(LoginPageLocators.SUBMIT))

def perform_login(self, username, password):
self.logger.info("Performing login with the provided credentials.")

username_field = self.find_username_field()
password_field = self.find_password_field()

Expand Down
36 changes: 32 additions & 4 deletions util/util_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,53 @@

def load_config():
try:
# Check if running in CI (e.g., GitHub Actions)
if os.getenv('CI'):
print(""" Running in GitLab CI/CD pipeline""")
username = os.environ['USERNAME']
password = os.environ['PASSWORD']
print("Running in CI environment (GitHub Actions)")
# Use GitHub Secrets - these need to be set in the GitHub repository settings
username = os.environ.get("OBI_USERNAME")
password = os.environ.get("OBI_PASSWORD")
if not username or not password:
raise ValueError("USERNAME or PASSWORD not set in GitHub Secrets.")
config = {
'username': username,
'password': password
}
else:
print("""Running locally""")
# Running locally, use config.json file
print("Running locally")
base_dir = os.path.abspath(os.path.dirname(__file__))
config_path = os.path.join(base_dir, '..', 'util', 'config.json')
with open(config_path, 'r') as f:
config = json.load(f)

return config
except Exception as e:
print(f"Error loading config: {e}")
return None


# def load_config():
# try:
# if os.getenv('CI'):
# print(""" Running in GitLab CI/CD pipeline""")
# username = os.environ['USERNAME']
# password = os.environ['PASSWORD']
# config = {
# 'username': username,
# 'password': password
# }
# else:
# print("""Running locally""")
# base_dir = os.path.abspath(os.path.dirname(__file__))
# config_path = os.path.join(base_dir, '..', 'util', 'config.json')
# with open(config_path, 'r') as f:
# config = json.load(f)
# return config
# except Exception as e:
# print(f"Error loading config: {e}")
# return None




0 comments on commit 4b79705

Please sign in to comment.