71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
import pytest
|
|
|
|
from tests.step_actions import StepActions
|
|
from tests.helpers import login, select_ui_dropdown, open_trading_maintenance_page
|
|
from tests.config_reader import get_setup_configs
|
|
from tests.locators import Locator
|
|
|
|
|
|
def get_session_window(config):
|
|
|
|
session_config = config.get("setup", {}).get("session", {})
|
|
start_offset_minutes = session_config.get("start_offset_minutes", 7)
|
|
end_time = session_config.get("end_time", "20:30")
|
|
|
|
start_datetime = datetime.now() + timedelta(minutes=start_offset_minutes)
|
|
today = datetime.now().strftime("%d/%m/%Y")
|
|
|
|
return start_datetime.strftime("%d/%m/%Y %H:%M"), f"{today} {end_time}"
|
|
|
|
|
|
def create_session(driver, step, config):
|
|
|
|
open_trading_maintenance_page(driver, Locator.tradingsession)
|
|
step.capture("trading_session")
|
|
|
|
step.click((By.XPATH, Locator.addsessionbtn), "add_session")
|
|
|
|
select_ui_dropdown(driver, "meInstanceId", config["product"]["me_instance"])
|
|
|
|
step.capture("select_product")
|
|
|
|
start_date_time, end_date_time = get_session_window(config)
|
|
|
|
step.type((By.XPATH, Locator.inputstartdate), start_date_time, "start_date")
|
|
|
|
step.type((By.XPATH, Locator.inputenddate), end_date_time, "end_date")
|
|
|
|
step.click((By.XPATH, Locator.sessionsavebtn), "save_session")
|
|
|
|
|
|
@pytest.mark.session
|
|
@pytest.mark.parametrize("config", get_setup_configs("session"), ids=lambda c: c["product_name"])
|
|
def test_session(driver, test_context, config, request):
|
|
|
|
# The full setup command runs session-only products (such as RA) through
|
|
# test_combined_setup.py so they share the same browser/login context.
|
|
invocation = " ".join(str(arg).replace("\\", "/") for arg in request.config.invocation_params.args)
|
|
if "tests/setup" in invocation and "tests/setup/sessions" not in invocation and "test_session.py" not in invocation:
|
|
pytest.skip("Handled by the shared full setup flow")
|
|
|
|
wait = WebDriverWait(driver, 20)
|
|
|
|
step = StepActions(driver, wait, test_context)
|
|
|
|
driver.get(config["url"])
|
|
step.capture("open_application")
|
|
|
|
login(
|
|
driver,
|
|
config["login"]["username"],
|
|
config["login"]["password"]
|
|
)
|
|
|
|
step.capture("login")
|
|
|
|
create_session(driver, step, config)
|