Make selenium tests backwards compatible

Make using pre-selenium v4 syntax an option. See:

https: //review.opendev.org/c/openstack/openstack-helm-infra/+/883894/5/nagios/templates/bin/_selenium-tests.py.tpl
Change-Id: I982029e620d944458ac0a4670189534023a6f972
This commit is contained in:
Ritchie, Frank (fr801x) 2023-08-24 14:59:28 -04:00
parent dc200450ea
commit e325bd6bcb
4 changed files with 15 additions and 1 deletions

View File

@ -15,7 +15,7 @@ apiVersion: v1
appVersion: v1.0.0
description: OpenStack-Helm Nagios
name: nagios
version: 0.1.8
version: 0.1.9
home: https://www.nagios.org
sources:
- https://opendev.org/openstack/openstack-helm-addons

View File

@ -22,7 +22,9 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
{{- if .Values.selenium_v4 }}
from selenium.webdriver.chrome.service import Service
{{- end }}
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ScreenshotException
@ -51,7 +53,11 @@ def get_variable(env_var):
def click_link_by_name(link_name):
try:
logger.info("Clicking '{}' link".format(link_name))
{{- if .Values.selenium_v4 }}
link = browser.find_element(By.LINK_TEXT, link_name)
{{- else }}
link = browser.find_element_by_text_link(link_name)
{{- end }}
link.click()
except NoSuchElementException:
logger.error("Failed clicking '{}' link".format(link_name))
@ -80,8 +86,12 @@ options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1920x1080')
{{- if .Values.selenium_v4 }}
service = Service(executable_path=chrome_driver)
browser = webdriver.Chrome(service=service, options=options)
{{- else }}
browser = webdriver.Chrome(chrome_driver, chrome_options=options)
{{- end }}
try:
logger.info('Attempting to connect to Nagios')

View File

@ -29,6 +29,9 @@ images:
- dep_check
- image_repo_sync
# Use selenium v4 syntax
selenium_v4: true
labels:
nagios:
node_selector_key: openstack-control-plane

View File

@ -9,4 +9,5 @@ nagios:
- 0.1.6 Added OCI registry authentication
- 0.1.7 Upgrade osh-selenium image to latest-ubuntu_focal
- 0.1.8 Use helm toolkit for readiness probes
- 0.1.9 Make using selenium v4 syntax optional
...