openstack-helm-infra/tools/gate/selenium/nagiosSelenium.py
Steven Fitzpatrick c2f3486ca4 OSH-Infra Selenium Tests Refactor
This change would update the LMA selenium tests to share a more similar
structure. Additional logging is introduced, and the scripts will fail
gracefully if the targeted service cannot be reached.

Change-Id: Ief7f69b952b2f0e33b7b738bb76083247766f662
2019-10-17 18:23:42 +00:00

77 lines
2.4 KiB
Python
Executable File

# 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 sys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from seleniumtester import SeleniumTester
st = SeleniumTester('Nagios')
username = st.get_variable('NAGIOS_USER')
password = st.get_variable('NAGIOS_PASSWORD')
nagios_uri = st.get_variable('NAGIOS_URI')
nagios_url = 'http://{0}:{1}@{2}'.format(username, password, nagios_uri)
try:
st.logger.info('Attempting to connect to Nagios')
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)
try:
st.logger.info('Switching Focus to Navigation side frame')
sideFrame = st.browser.switch_to.frame('side')
except NoSuchElementException:
st.logger.error('Failed selecting side frame')
st.browser.quit()
sys.exit(1)
try:
st.logger.info('Attempting to visit Services page')
st.click_link_by_name('Services')
st.take_screenshot('Nagios Services')
except TimeoutException:
st.logger.error('Failed to load Services page')
st.browser.quit()
sys.exit(1)
try:
st.logger.info('Attempting to visit Host Groups page')
st.click_link_by_name('Host Groups')
st.take_screenshot('Nagios Host Groups')
except TimeoutException:
st.logger.error('Failed to load Host Groups page')
st.browser.quit()
sys.exit(1)
try:
st.logger.info('Attempting to visit Hosts page')
st.click_link_by_name('Hosts')
st.take_screenshot('Nagios Hosts')
except TimeoutException:
st.logger.error('Failed to load Hosts page')
st.browser.quit()
sys.exit(1)
st.browser.quit()