Merge "OSH-Infra Selenium Tests Refactor"

This commit is contained in:
Zuul 2019-10-18 17:04:02 +00:00 committed by Gerrit Code Review
commit 0aad14a6f9
9 changed files with 392 additions and 269 deletions

View File

@ -1,6 +1,12 @@
#!/bin/bash #!/bin/bash
set -xe
export CHROMEDRIVER="${CHROMEDRIVER:="/etc/selenium/chromedriver"}"
export ARTIFACTS_DIR="${ARTIFACTS_DIR:="/tmp/artifacts/"}"
export GRAFANA_USER="admin" export GRAFANA_USER="admin"
export GRAFANA_PASSWORD="password" export GRAFANA_PASSWORD="password"
export GRAFANA_URI="http://grafana.osh-infra.svc.cluster.local" export GRAFANA_URI="grafana.osh-infra.svc.cluster.local"
python tools/gate/selenium/grafanaSelenium.py python tools/gate/selenium/grafanaSelenium.py

View File

@ -1,8 +1,16 @@
#!/bin/bash #!/bin/bash
set -xe
export CHROMEDRIVER="${CHROMEDRIVER:="/etc/selenium/chromedriver"}"
export ARTIFACTS_DIR="${ARTIFACTS_DIR:="/tmp/artifacts/"}"
export KIBANA_USER="admin" export KIBANA_USER="admin"
export KIBANA_PASSWORD="changeme" export KIBANA_PASSWORD="changeme"
export KIBANA_LOGSTASH_URI="kibana.osh-infra.svc.cluster.local/app/kibana#/discover?_g=()&_a=(columns:!(_source),index:'logstash-*',interval:auto,query:(match_all:()),sort:!('@timestamp',desc))" export KIBANA_URI="kibana.osh-infra.svc.cluster.local"
export KIBANA_KERNEL_URI="kibana.osh-infra.svc.cluster.local/app/kibana#/discover?_g=()&_a=(columns:!(_source),index:'kernel-*',interval:auto,query:(match_all:()),sort:!('@timestamp',desc))"
export KIBANA_JOURNAL_URI="kibana.osh-infra.svc.cluster.local/app/kibana#/discover?_g=()&_a=(columns:!(_source),index:'journal-*',interval:auto,query:(match_all:()),sort:!('@timestamp',desc))" export KERNEL_QUERY="discover?_g=()&_a=(columns:!(_source),index:'kernel-*',interval:auto,query:(match_all:()),sort:!('@timestamp',desc))"
export JOURNAL_QUERY="discover?_g=()&_a=(columns:!(_source),index:'journal-*',interval:auto,query:(match_all:()),sort:!('@timestamp',desc))"
export LOGSTASH_QUERY="discover?_g=()&_a=(columns:!(_source),index:'logstash-*',interval:auto,query:(match_all:()),sort:!('@timestamp',desc))"
python tools/gate/selenium/kibanaSelenium.py python tools/gate/selenium/kibanaSelenium.py

View File

@ -1,6 +1,12 @@
#!/bin/bash #!/bin/bash
set -xe
export CHROMEDRIVER="${CHROMEDRIVER:="/etc/selenium/chromedriver"}"
export ARTIFACTS_DIR="${ARTIFACTS_DIR:="/tmp/artifacts/"}"
export NAGIOS_USER="nagiosadmin" export NAGIOS_USER="nagiosadmin"
export NAGIOS_PASSWORD="password" export NAGIOS_PASSWORD="password"
export NAGIOS_URI="nagios.osh-infra.svc.cluster.local" export NAGIOS_URI="nagios.osh-infra.svc.cluster.local"
python tools/gate/selenium/nagiosSelenium.py python tools/gate/selenium/nagiosSelenium.py

View File

@ -1,6 +1,12 @@
#!/bin/bash #!/bin/bash
set -xe
export CHROMEDRIVER="${CHROMEDRIVER:="/etc/selenium/chromedriver"}"
export ARTIFACTS_DIR="${ARTIFACTS_DIR:="/tmp/artifacts/"}"
export PROMETHEUS_USER="admin" export PROMETHEUS_USER="admin"
export PROMETHEUS_PASSWORD="changeme" export PROMETHEUS_PASSWORD="changeme"
export PROMETHEUS_URI="prometheus.osh-infra.svc.cluster.local" export PROMETHEUS_URI="prometheus.osh-infra.svc.cluster.local"
python tools/gate/selenium/prometheusSelenium.py python tools/gate/selenium/prometheusSelenium.py

View File

@ -1,95 +1,90 @@
import logging # Copyright 2019 The Openstack-Helm Authors.
import os
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys import sys
from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from seleniumtester import SeleniumTester
# Create logger, console handler and formatter st = SeleniumTester('Grafana')
logger = logging.getLogger('Grafana Selenium Tests')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Set the formatter and add the handler username = st.get_variable('GRAFANA_USER')
ch.setFormatter(formatter) password = st.get_variable('GRAFANA_PASSWORD')
logger.addHandler(ch) grafana_uri = st.get_variable('GRAFANA_URI')
grafana_url = 'http://{}'.format(grafana_uri)
# Get Grafana admin user name try:
if "GRAFANA_USER" in os.environ: st.logger.info('Attempting to connect to Grafana')
grafana_user = os.environ['GRAFANA_USER'] st.browser.get(grafana_url)
logger.info('Found Grafana username') el = WebDriverWait(st.browser, 15).until(
else: EC.title_contains('Grafana')
logger.critical('Grafana username environment variable not set') )
sys.exit(1) st.logger.info('Connected to Grafana')
except TimeoutException:
st.logger.critical('Timed out waiting to connect to Grafana')
st.browser.quit()
sys.exit(1)
if "GRAFANA_PASSWORD" in os.environ: try:
grafana_password = os.environ['GRAFANA_PASSWORD'] st.logger.info('Attempting to login to Grafana')
logger.info('Found Grafana password') st.browser.find_element_by_name('username').send_keys(username)
else: st.browser.find_element_by_name('password').send_keys(password)
logger.critical('Grafana password environment variable not set') st.browser.find_element_by_css_selector(
sys.exit(1) 'body > grafana-app > div.main-view > div > div:nth-child(1) > div > '
'div > div.login-inner-box > form > div.login-button-group > button'
).click()
st.logger.info("Successfully logged in to Grafana")
except NoSuchElementException:
st.logger.error("Failed to log in to Grafana")
st.browser.quit()
sys.exit(1)
if "GRAFANA_URI" in os.environ: try:
grafana_uri = os.environ['GRAFANA_URI'] st.logger.info('Attempting to visit Nodes dashboard')
logger.info('Found Grafana URI') st.click_link_by_name('Home')
else: st.click_link_by_name('Nodes')
logger.critical('Grafana URI environment variable not set') el = WebDriverWait(st.browser, 15).until(
sys.exit(1) EC.presence_of_element_located(
(By.XPATH, '/html/body/grafana-app/div[2]/div/div[1]/div/div/'
'div[1]/dashboard-grid/div/div[1]/div/plugin-component/'
'panel-plugin-graph/grafana-panel/div/div[2]')
)
)
st.take_screenshot('Grafana Nodes')
except TimeoutException:
st.logger.error('Failed to load Nodes dashboard')
st.browser.quit()
sys.exit(1)
options = Options() try:
options.add_argument('--headless') st.logger.info('Attempting to visit Cluster Status dashboard')
options.add_argument('--no-sandbox') st.click_link_by_name('Nodes')
options.add_argument('--window-size=1920x1080') st.click_link_by_name('Kubernetes Cluster Status')
el = WebDriverWait(st.browser, 15).until(
EC.presence_of_element_located(
(By.XPATH, '/html/body/grafana-app/div[2]/div/div[1]/div/'
'div/div[1]/dashboard-grid/div/div[5]/div/plugin-component/'
'panel-plugin-singlestat/grafana-panel/div')
)
)
st.take_screenshot('Grafana Cluster Status')
except TimeoutException:
st.logger.error('Failed to load Cluster Status dashboard')
st.browser.quit()
sys.exit(1)
browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) st.browser.quit()
browser.get(grafana_uri)
username = browser.find_element_by_name('username')
username.send_keys(grafana_user)
password = browser.find_element_by_name('password')
password.send_keys(grafana_password)
login = browser.find_element_by_css_selector('body > grafana-app > div.main-view > div > div:nth-child(1) > div > div > div.login-inner-box > form > div.login-button-group > button')
login.click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.LINK_TEXT, 'Home'))
)
homeBtn = browser.find_element_by_link_text('Home')
homeBtn.click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.LINK_TEXT, 'Nodes'))
)
nodeBtn = browser.find_element_by_link_text('Nodes')
nodeBtn.click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.XPATH, '/html/body/grafana-app/div[2]/div/div[1]/div/div/div[1]/dashboard-grid/div/div[1]/div/plugin-component/panel-plugin-graph/grafana-panel/div/div[2]'))
)
browser.save_screenshot('/tmp/artifacts/Grafana_Nodes.png')
nodeBtn = browser.find_element_by_link_text('Nodes')
nodeBtn.click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.LINK_TEXT, 'Kubernetes Cluster Status'))
)
healthBtn = browser.find_element_by_link_text('Kubernetes Cluster Status')
healthBtn.click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.XPATH, '/html/body/grafana-app/div[2]/div/div[1]/div/div/div[1]/dashboard-grid/div/div[5]/div/plugin-component/panel-plugin-singlestat/grafana-panel/div'))
)
browser.save_screenshot('/tmp/artifacts/Grafana_ClusterStatus.png')

View File

@ -1,74 +1,79 @@
import logging # Copyright 2019 The Openstack-Helm Authors.
import os
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys import sys
from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import TimeoutException from selenium.common.exceptions import TimeoutException
from seleniumtester import SeleniumTester
logger = logging.getLogger('Kibana Selenium Tests') st = SeleniumTester('Kibana')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter) username = st.get_variable('KIBANA_USER')
logger.addHandler(ch) password = st.get_variable('KIBANA_PASSWORD')
kibana_uri = st.get_variable('KIBANA_URI')
kibana_url = 'http://{0}:{1}@{2}'.format(username, password, kibana_uri)
artifacts = '/tmp/artifacts/' try:
if not os.path.exists(artifacts): st.logger.info('Attempting to connect to Kibana')
os.makedirs(artifacts) st.browser.get(kibana_url)
el = WebDriverWait(st.browser, 45).until(
EC.title_contains('Kibana')
)
st.logger.info('Connected to Kibana')
except TimeoutException:
st.logger.critical('Timed out waiting for Kibana')
st.browser.quit()
sys.exit(1)
kernel_query = st.get_variable('KERNEL_QUERY')
journal_query = st.get_variable('JOURNAL_QUERY')
logstash_query = st.get_variable('LOGSTASH_QUERY')
def get_variable(env_var): queries = [(kernel_query, 'Kernel'),
if env_var in os.environ: (journal_query, 'Journal'),
logger.info('Found "{}"'.format(env_var)) (logstash_query, 'Logstash')]
return os.environ[env_var]
else:
logger.critical('Variable "{}" is not defined!'.format(env_var))
sys.exit(1)
for query, name in queries:
kibana_user = get_variable('KIBANA_USER')
kibana_password = get_variable('KIBANA_PASSWORD')
kibana_journal_uri = get_variable('KIBANA_JOURNAL_URI')
kibana_kernel_uri = get_variable('KIBANA_KERNEL_URI')
kibana_logstash_uri = get_variable('KIBANA_LOGSTASH_URI')
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1920x1080')
targets = [(kibana_kernel_uri, 'Kernel'),
(kibana_journal_uri, 'Journal'),
(kibana_logstash_uri, 'Logstash')]
for target, name in targets:
retry = 3 retry = 3
while retry > 0: while retry > 0:
prefix = '' query_url = '{}/app/kibana#/{}'.format(kibana_url, query)
browser = webdriver.Chrome(
'/etc/selenium/chromedriver', chrome_options=options)
url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, target)
browser.get(url)
try: try:
WebDriverWait(browser, 60).until( st.logger.info('Attempting to query {} index'.format(name))
st.browser.get(query_url)
WebDriverWait(st.browser, 60).until(
EC.presence_of_element_located( EC.presence_of_element_located(
(By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/' (By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/'
'discover-app/div/div[2]/div[2]/div/div[2]/div[2]/' 'discover-app/div/div[2]/div[2]/div/div[2]/div[2]/'
'doc-table/div/table/tbody/tr[1]/td[2]')) 'doc-table/div/table/tbody/tr[1]/td[2]')
)
) )
logger.info('{} index loaded successfully'.format(name)) st.logger.info('{} index loaded successfully'.format(name))
st.take_screenshot('Kibana {} Index'.format(name))
retry = 0 retry = 0
except TimeoutException: except TimeoutException:
logger.error('Error occured loading {} index'.format(name)) if retry > 1:
prefix = 'Error_' st.logger.warning('Timed out loading {} index'.format(name))
browser.save_screenshot( else:
artifacts + '{}Kibana_{}.png'.format(prefix, name)) st.logger.error('Could not load {} index'.format(name))
browser.quit()
retry -= 1 retry -= 1
if retry <= 0:
# Reset test condition
st.browser.get(kibana_url)
st.browser.quit()

View File

@ -1,70 +1,76 @@
import os # Copyright 2019 The Openstack-Helm Authors.
import logging
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from seleniumtester import SeleniumTester
st = SeleniumTester('Nagios')
# Create logger, console handler and formatter username = st.get_variable('NAGIOS_USER')
logger = logging.getLogger('Nagios Selenium Tests') password = st.get_variable('NAGIOS_PASSWORD')
logger.setLevel(logging.DEBUG) nagios_uri = st.get_variable('NAGIOS_URI')
ch = logging.StreamHandler() nagios_url = 'http://{0}:{1}@{2}'.format(username, password, nagios_uri)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Set the formatter and add the handler try:
ch.setFormatter(formatter) st.logger.info('Attempting to connect to Nagios')
logger.addHandler(ch) st.browser.get(nagios_url)
el = WebDriverWait(st.browser, 15).until(
EC.title_contains('Nagios')
)
st.logger.info('Connected to Nagios')
except TimeoutException:
st.logger.critical('Timed out waiting for Nagios')
st.browser.quit()
sys.exit(1)
# Get Grafana admin user name try:
if "NAGIOS_USER" in os.environ: st.logger.info('Switching Focus to Navigation side frame')
nagios_user = os.environ['NAGIOS_USER'] sideFrame = st.browser.switch_to.frame('side')
logger.info('Found Nagios username') except NoSuchElementException:
else: st.logger.error('Failed selecting side frame')
logger.critical('Nagios username environment variable not set') st.browser.quit()
sys.exit(1) sys.exit(1)
if "NAGIOS_PASSWORD" in os.environ: try:
nagios_password = os.environ['NAGIOS_PASSWORD'] st.logger.info('Attempting to visit Services page')
logger.info('Found Nagios password') st.click_link_by_name('Services')
else: st.take_screenshot('Nagios Services')
logger.critical('Nagios password environment variable not set') except TimeoutException:
sys.exit(1) st.logger.error('Failed to load Services page')
st.browser.quit()
sys.exit(1)
if "NAGIOS_URI" in os.environ: try:
nagios_uri = os.environ['NAGIOS_URI'] st.logger.info('Attempting to visit Host Groups page')
logger.info('Found Nagios URI') st.click_link_by_name('Host Groups')
else: st.take_screenshot('Nagios Host Groups')
logger.critical('Nagios URI environment variable not set') except TimeoutException:
sys.exit(1) st.logger.error('Failed to load Host Groups page')
st.browser.quit()
sys.exit(1)
options = Options() try:
options.add_argument('--headless') st.logger.info('Attempting to visit Hosts page')
options.add_argument('--no-sandbox') st.click_link_by_name('Hosts')
options.add_argument('--window-size=1920x1080') st.take_screenshot('Nagios Hosts')
except TimeoutException:
st.logger.error('Failed to load Hosts page')
st.browser.quit()
sys.exit(1)
browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) st.browser.quit()
browser.get('http://'+nagios_user+':'+nagios_password+'@'+nagios_uri)
sideFrame = browser.switch_to.frame('side')
services = browser.find_element_by_link_text('Services')
services.click()
el = WebDriverWait(browser, 15)
browser.save_screenshot('/tmp/artifacts/Nagios_Services.png')
hostGroups = browser.find_element_by_link_text('Host Groups')
hostGroups.click()
el = WebDriverWait(browser, 15)
browser.save_screenshot('/tmp/artifacts/Nagios_HostGroups.png')
hosts = browser.find_element_by_link_text('Hosts')
hosts.click()
el = WebDriverWait(browser, 15)
browser.save_screenshot('/tmp/artifacts/Nagios_Hosts.png')

View File

@ -1,79 +1,68 @@
import os # Copyright 2019 The Openstack-Helm Authors.
import logging
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys import sys
from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import TimeoutException
from seleniumtester import SeleniumTester
# Create logger, console handler and formatter st = SeleniumTester('Prometheus')
logger = logging.getLogger('Prometheus Selenium Tests')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Set the formatter and add the handler username = st.get_variable('PROMETHEUS_USER')
ch.setFormatter(formatter) password = st.get_variable('PROMETHEUS_PASSWORD')
logger.addHandler(ch) prometheus_uri = st.get_variable('PROMETHEUS_URI')
prometheus_url = 'http://{}:{}@{}'.format(username, password, prometheus_uri)
# Get Grafana admin user name try:
if "PROMETHEUS_USER" in os.environ: st.logger.info('Attempting to connect to Prometheus')
prometheus_user = os.environ['PROMETHEUS_USER'] st.browser.get(prometheus_url)
logger.info('Found Prometheus username') el = WebDriverWait(st.browser, 15).until(
else: EC.title_contains('Prometheus')
logger.critical('Prometheus username environment variable not set') )
sys.exit(1) st.logger.info('Connected to Prometheus')
st.take_screenshot('Prometheus Dashboard')
except TimeoutException:
st.logger.critical('Timed out waiting for Prometheus')
st.browser.quit()
sys.exit(1)
if "PROMETHEUS_PASSWORD" in os.environ: try:
prometheus_password = os.environ['PROMETHEUS_PASSWORD'] st.logger.info('Attempting to view Runtime Information')
logger.info('Found Prometheus password') st.click_link_by_name('Status')
else: st.click_link_by_name('Runtime & Build Information')
logger.critical('Prometheus password environment variable not set') el = WebDriverWait(st.browser, 15).until(
sys.exit(1) EC.presence_of_element_located((By.XPATH, '/html/body/div/table[1]'))
)
st.take_screenshot('Prometheus Runtime Info')
except TimeoutException:
st.logger.error('Failed to load Runtime Information page')
st.browser.quit()
sys.exit(1)
if "PROMETHEUS_URI" in os.environ: try:
prometheus_uri = os.environ['PROMETHEUS_URI'] st.logger.info('Attempting to view Runtime Information')
logger.info('Found Prometheus URI') st.click_link_by_name('Status')
else: st.click_link_by_name('Command-Line Flags')
logger.critical('Prometheus URI environment variable not set') el = WebDriverWait(st.browser, 15).until(
sys.exit(1) EC.presence_of_element_located((By.XPATH, '/html/body/div/table'))
)
st.take_screenshot('Prometheus Command Line Flags')
except TimeoutException:
st.logger.error('Failed to load Command Line Flags page')
st.browser.quit()
sys.exit(1)
options = Options() st.browser.quit()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1920x1080')
browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options)
browser.get("http://"+prometheus_user+":"+prometheus_password+"@"+prometheus_uri)
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.NAME, 'submit'))
)
browser.save_screenshot('/tmp/artifacts/Prometheus_Dash.png')
statusBtn = browser.find_element_by_link_text('Status')
statusBtn.click()
browser.find_element_by_link_text('Runtime & Build Information').click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.XPATH, '/html/body/div/table[1]'))
)
browser.save_screenshot('/tmp/artifacts/Prometheus_RuntimeInfo.png')
statusBtn = browser.find_element_by_link_text('Status')
statusBtn.click()
browser.find_element_by_link_text('Command-Line Flags').click()
el = WebDriverWait(browser, 15).until(
EC.presence_of_element_located((By.XPATH, '/html/body/div/table'))
)
browser.save_screenshot('/tmp/artifacts/Prometheus_CommandLineFlags.png')

View File

@ -0,0 +1,102 @@
# Copyright 2019 The Openstack-Helm Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import logging
import sys
from selenium import webdriver
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
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ScreenshotException
class SeleniumTester():
def __init__(self, name):
self.logger = self.get_logger(name)
self.chrome_driver = self.get_variable('CHROMEDRIVER')
self.artifacts_dir = self.get_variable('ARTIFACTS_DIR')
self.initialize_artifiacts_dir()
self.browser = self.get_browser()
def get_logger(self, name):
logger = logging.getLogger('{} Selenium Tests'.format(name))
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
# Set the formatter and add the handler
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
def get_variable(self, env_var):
if env_var in os.environ:
self.logger.info('Found "{}"'.format(env_var))
return os.environ[env_var]
else:
self.logger.critical(
'Variable "{}" is not defined!'.format(env_var)
)
sys.exit(1)
def get_browser(self):
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1920x1080')
browser = webdriver.Chrome(self.chrome_driver, chrome_options=options)
return browser
def initialize_artifiacts_dir(self):
if self.artifacts_dir and not os.path.exists(self.artifacts_dir):
os.makedirs(self.artifacts_dir)
self.logger.info(
'Created {} for test artifacts'.format(self.artifacts_dir)
)
def click_link_by_name(self, link_name):
try:
el = WebDriverWait(self.browser, 15).until(
EC.presence_of_element_located((By.LINK_TEXT, link_name))
)
self.logger.info("Clicking '{}' link".format(link_name))
link = self.browser.find_element_by_link_text(link_name)
link.click()
except (TimeoutException, NoSuchElementException):
self.logger.error("Failed clicking '{}' link".format(link_name))
self.browser.quit()
sys.exit(1)
def take_screenshot(self, page_name):
file_name = page_name.replace(' ', '_')
try:
el = WebDriverWait(self.browser, 15)
self.browser.save_screenshot(
'{}{}.png'.format(self.artifacts_dir, file_name)
)
self.logger.info(
"Successfully captured {} screenshot".format(page_name)
)
except ScreenshotException:
self.logger.error(
"Failed to capture {} screenshot".format(page_name)
)
self.browser.quit()
sys.exit(1)