Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
common:
environment:
local:
url: http://localhost:8080/
username: user
password: 12345678
travis:
url: http://localhost:8080/
username: user
password: 12345678
12 changes: 10 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest
import requests
from requests.exceptions import ConnectionError
Expand All @@ -9,6 +10,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from utils.config import Config


REMOTE_URL = 'http://127.0.0.1:4444/wd/hub'
Expand Down Expand Up @@ -65,10 +67,16 @@ def init_driver(request):
print('Please pass the correct browser name: {}'.format(request.param))
raise Exception('driver is not found')

config = Config()
url = os.getenv('URL') if os.getenv('URL', None) else config.url
username = os.getenv('USERNAME') if os.getenv('USERNAME', None) else config.username
password = os.getenv('PASSWORD') if os.getenv('PASSWORD', None) else config.password

driver.get(url)
driver.implicitly_wait(5)
driver.get(TD.BASE_URL)
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, 'j_username'))).send_keys(TD.LOGIN)
driver.find_element(By.CSS_SELECTOR, 'input[name="j_password"]').send_keys(TD.PASSWORD)
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, 'j_username'))).send_keys(username)
driver.find_element(By.CSS_SELECTOR, 'input[name="j_password"]').send_keys(password)
driver.find_element(By.CSS_SELECTOR, 'input[name="Submit"]').click()
request.cls.driver = driver

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
selenium
webdriver_manager
webdriver_manager
strictyaml
53 changes: 53 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import strictyaml as yaml
from collections import namedtuple


class Config:
"""
Class for initializing config
"""

config_file = os.environ.get('CONFIG', 'data/config.yaml').lower()
default_config = os.path.join(os.path.dirname(os.path.abspath(__file__)), config_file)

@staticmethod
def get_yaml(file: str):
# Check that file exists in specified path
if not os.path.exists(file):
print(f'Config file not found: {file}')
raise Exception('Config file not found')
# Reading file
f = open(file, 'r').read()
print(f'Loading file: {file}')
conf = yaml.load(f)
return conf.data

@staticmethod
def get_config(file: str = default_config):
"""
Method for parsing config file
:param file: path to config
:return: config object with the same structure as yaml file
"""
# Getting environment variable for running tests, if non set up default will be set to local
env = os.environ.get('ENV', 'local').lower()
# Allowing to set staging env values to stage, stg or staging
if env.lower() == 'travis':
env = 'travis'
# If not proper config specified
print(f'Picking environment: {env}')
print(f'Loading config file: {file}')
# Loading yaml file
conf = Config.get_yaml(file)
# Setting up local config for appropriate environment
env_config = conf['environment'][env.lower()]

return Config.get_object_from_dict(env_config), env

@staticmethod
def get_object_from_dict(dictionary):
for k, v in dictionary.items():
if isinstance(v, dict):
dictionary[k] = Config.get_object_from_dict(v)
return namedtuple('object', dictionary.keys())(*dictionary.values())