Make selenium v4 syntax optional

Make selenium v4 syntax optional using the same pattern as

https://review.opendev.org/c/openstack/openstack-helm-infra/+/892708

See:

https: //review.opendev.org/c/openstack/openstack-helm-infra/+/883894/5/grafana/templates/bin/_selenium-tests.py.tpl
Change-Id: I744b721750c474db9fecbd46280d30cfb8347a6f
This commit is contained in:
Ritchie, Frank (fr801x) 2023-08-30 16:10:44 -04:00
parent f234218dba
commit 6df0925b25
4 changed files with 17 additions and 1 deletions

View File

@ -15,7 +15,7 @@ apiVersion: v1
appVersion: v9.2.10
description: OpenStack-Helm Grafana
name: grafana
version: 0.1.21
version: 0.1.22
home: https://grafana.com/
sources:
- https://github.com/grafana/grafana

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
@ -57,8 +59,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 }}
logger.info("Attempting to open Grafana dashboard")
try:
@ -74,9 +80,15 @@ except TimeoutException:
logger.info("Attempting to log into Grafana dashboard")
try:
{{- if .Values.selenium_v4 }}
browser.find_element(By.NAME, 'user').send_keys(username)
browser.find_element(By.NAME, 'password').send_keys(password)
browser.find_element(By.CSS_SELECTOR, '[aria-label="Login button"]').click()
{{- else }}
browser.find_element_by_name('user').send_keys(username)
browser.find_element_by_name('password').send_keys(password)
browser.find_element_by_css_selector('[aria-label="Login button"]').click()
{{- end }}
logger.info("Successfully logged in to Grafana")
except NoSuchElementException:
logger.error("Failed to log in to Grafana")

View File

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

View File

@ -22,4 +22,5 @@ grafana:
- 0.1.19 Update grafana to 9.2.10
- 0.1.20 Upgrade osh-selenium image to latest-ubuntu_focal
- 0.1.21 Fix run migrator job deployment condition
- 0.1.22 Make selenium v4 syntax optional
...