Initial commit - Selenium automation framework
This commit is contained in:
@@ -0,0 +1,231 @@
|
||||
import time
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
from tests.regression.ui_helpers import (
|
||||
click_select2_option_by_text,
|
||||
open_bootstrap_nav_submenu,
|
||||
select_select2_value_by_container_id,
|
||||
wait_for_select2_option_by_text,
|
||||
)
|
||||
|
||||
|
||||
TRADING_MARKET_LABELS = {
|
||||
"GDAM": "GDAM Order Entry",
|
||||
"DAM": "DAM Order Entry",
|
||||
"HPDAM": "HPDAM Order Entry",
|
||||
}
|
||||
|
||||
TRADING_MARKET_HREFS = {
|
||||
"GDAM": "../IDAS/GDAMOrderEntry.aspx",
|
||||
"DAM": "../IDAS/DAMOrderEntry.aspx",
|
||||
"HPDAM": "../IDAS/HPDAMOrderEntry.aspx",
|
||||
}
|
||||
|
||||
|
||||
BIDDING_SCREEN_LABELS = {
|
||||
"single_bid": "Single Bid",
|
||||
"block_bid": "Block Bid",
|
||||
}
|
||||
|
||||
|
||||
BLOCK_BULK_UPLOAD_HREF = "../FrontOffice/BulkOrderUploadIDAS.aspx"
|
||||
|
||||
|
||||
def open_idas_market_page(driver, trading_market):
|
||||
|
||||
open_bootstrap_nav_submenu(
|
||||
driver,
|
||||
"Trading",
|
||||
"IDAS",
|
||||
TRADING_MARKET_HREFS[trading_market]
|
||||
)
|
||||
|
||||
wait = WebDriverWait(driver, 20)
|
||||
wait.until(
|
||||
EC.any_of(
|
||||
EC.url_contains("OrderEntry.aspx"),
|
||||
EC.visibility_of_element_located((By.XPATH, "//a[normalize-space()='Single Bid']")),
|
||||
EC.visibility_of_element_located((By.ID, "s2id_ddlproduct"))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def open_idas_block_bulk_upload_page(driver):
|
||||
|
||||
open_bootstrap_nav_submenu(
|
||||
driver,
|
||||
"Trading",
|
||||
"IDAS",
|
||||
"BulkOrderUploadIDAS.aspx"
|
||||
)
|
||||
|
||||
wait = WebDriverWait(driver, 20)
|
||||
wait.until(
|
||||
EC.any_of(
|
||||
EC.url_contains("BulkOrderUploadIDAS.aspx"),
|
||||
EC.visibility_of_element_located((By.XPATH, "//*[contains(normalize-space(),'IDAS Bulk Order Upload')]")),
|
||||
EC.visibility_of_element_located((By.ID, "validateOrder"))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def open_idas_market_page_direct(driver, trading_market):
|
||||
|
||||
current_url = urlparse(driver.current_url)
|
||||
base_url = f"{current_url.scheme}://{current_url.netloc}"
|
||||
order_entry_path = TRADING_MARKET_HREFS[trading_market].replace("../", "/")
|
||||
|
||||
driver.get(f"{base_url}{order_entry_path}")
|
||||
|
||||
wait = WebDriverWait(driver, 20)
|
||||
wait.until(
|
||||
EC.any_of(
|
||||
EC.url_contains("OrderEntry.aspx"),
|
||||
EC.visibility_of_element_located((By.XPATH, "//a[normalize-space()='Single Bid']")),
|
||||
EC.visibility_of_element_located((By.ID, "s2id_ddlproduct"))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def open_bidding_screen(driver, bidding_screen):
|
||||
|
||||
if bidding_screen == "single_bid":
|
||||
return
|
||||
|
||||
tab_label = BIDDING_SCREEN_LABELS[bidding_screen]
|
||||
wait = WebDriverWait(driver, 20)
|
||||
|
||||
active_or_visible_tab = wait.until(
|
||||
EC.visibility_of_element_located(
|
||||
(
|
||||
By.XPATH,
|
||||
f"//*[self::a or self::button or self::span][normalize-space()='{tab_label}']"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
tab_classes = (active_or_visible_tab.get_attribute("class") or "").lower()
|
||||
if "active" in tab_classes:
|
||||
return
|
||||
|
||||
tab = wait.until(
|
||||
EC.element_to_be_clickable(
|
||||
(
|
||||
By.XPATH,
|
||||
f"//*[self::a or self::button or self::span][normalize-space()='{tab_label}']"
|
||||
)
|
||||
)
|
||||
)
|
||||
try:
|
||||
tab.click()
|
||||
except Exception:
|
||||
driver.execute_script("arguments[0].click();", tab)
|
||||
|
||||
|
||||
def select_bidding_filters(
|
||||
driver,
|
||||
product_code,
|
||||
tm_id,
|
||||
tac_id,
|
||||
product_to_tm_delay_seconds=0,
|
||||
tm_to_tac_delay_seconds=0,
|
||||
tm_timeout_seconds=30,
|
||||
tm_attempts=3,
|
||||
tac_timeout_seconds=15,
|
||||
tac_attempts=2,
|
||||
bidding_screen_ready_wait_seconds=10
|
||||
):
|
||||
|
||||
if bidding_screen_ready_wait_seconds > 0:
|
||||
time.sleep(bidding_screen_ready_wait_seconds)
|
||||
wait_for_bidding_product_configuration(driver)
|
||||
select_select2_value_by_container_id(driver, "s2id_ddlproduct", product_code, exact=True)
|
||||
if product_to_tm_delay_seconds > 0:
|
||||
time.sleep(product_to_tm_delay_seconds)
|
||||
wait_for_select2_option_by_text(
|
||||
driver,
|
||||
"s2id_ddlTMID",
|
||||
tm_id,
|
||||
timeout_seconds=tm_timeout_seconds,
|
||||
attempts=tm_attempts
|
||||
)
|
||||
click_select2_option_by_text(driver, "s2id_ddlTMID", tm_id)
|
||||
if tm_to_tac_delay_seconds > 0:
|
||||
time.sleep(tm_to_tac_delay_seconds)
|
||||
wait_for_select2_option_by_text(
|
||||
driver,
|
||||
"s2id_ddlTACID",
|
||||
tac_id,
|
||||
timeout_seconds=tac_timeout_seconds,
|
||||
attempts=tac_attempts
|
||||
)
|
||||
click_select2_option_by_text(driver, "s2id_ddlTACID", tac_id)
|
||||
|
||||
|
||||
def select_bidding_filters_for_trading_member(
|
||||
driver,
|
||||
product_code,
|
||||
tac_id,
|
||||
tac_timeout_seconds=15,
|
||||
tac_attempts=2,
|
||||
bidding_screen_ready_wait_seconds=10
|
||||
):
|
||||
|
||||
if bidding_screen_ready_wait_seconds > 0:
|
||||
time.sleep(bidding_screen_ready_wait_seconds)
|
||||
wait_for_bidding_product_configuration(driver)
|
||||
select_select2_value_by_container_id(driver, "s2id_ddlproduct", product_code, exact=True)
|
||||
wait_for_select2_option_by_text(
|
||||
driver,
|
||||
"s2id_ddlTACID",
|
||||
tac_id,
|
||||
timeout_seconds=tac_timeout_seconds,
|
||||
attempts=tac_attempts
|
||||
)
|
||||
click_select2_option_by_text(driver, "s2id_ddlTACID", tac_id)
|
||||
|
||||
|
||||
def select_bidding_product_and_tm(
|
||||
driver,
|
||||
product_code,
|
||||
tm_id,
|
||||
product_to_tm_delay_seconds=0,
|
||||
tm_timeout_seconds=30,
|
||||
tm_attempts=3,
|
||||
bidding_screen_ready_wait_seconds=10
|
||||
):
|
||||
|
||||
if bidding_screen_ready_wait_seconds > 0:
|
||||
time.sleep(bidding_screen_ready_wait_seconds)
|
||||
wait_for_bidding_product_configuration(driver)
|
||||
select_select2_value_by_container_id(driver, "s2id_ddlproduct", product_code, exact=True)
|
||||
if product_to_tm_delay_seconds > 0:
|
||||
time.sleep(product_to_tm_delay_seconds)
|
||||
wait_for_select2_option_by_text(
|
||||
driver,
|
||||
"s2id_ddlTMID",
|
||||
tm_id,
|
||||
timeout_seconds=tm_timeout_seconds,
|
||||
attempts=tm_attempts
|
||||
)
|
||||
click_select2_option_by_text(driver, "s2id_ddlTMID", tm_id)
|
||||
|
||||
|
||||
def wait_for_bidding_product_configuration(driver, timeout_seconds=60):
|
||||
|
||||
wait = WebDriverWait(driver, timeout_seconds)
|
||||
wait.until(
|
||||
lambda _driver: not any(
|
||||
element.is_displayed()
|
||||
for element in _driver.find_elements(
|
||||
By.XPATH,
|
||||
"//*[contains(translate(normalize-space(), "
|
||||
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), "
|
||||
"'begin product configuration')]"
|
||||
)
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user