horizon/openstack_dashboard/test/integration_tests/regions/messages.py
Akihiro Motoki e5d09edc20 Use python3-style super()
In python3, super() does not always require a class and self reference.
In other words, super() is enough for most cases.
This is much simpler and it is time to switch it to the newer style.

pylint provides a check for this.
Let's enable 'super-with-arguments' check.

NOTE: _prepare_mappings() method of FormRegion in
openstack_dashboard/test/integration_tests/regions/forms.py is refactored.
super() (without explicit class and self referece) does not work when
a subclass method calls a same method in a parent class multiple times.
It looks better to prepare a separate method to provide a common logic.

Change-Id: Id9512a14be9f20dbd5ebd63d446570c7b7c825ff
2020-10-15 14:37:20 +09:00

46 lines
1.6 KiB
Python

# 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.
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common import by
from openstack_dashboard.test.integration_tests.regions import baseregion
ERROR = 'alert-danger'
INFO = 'alert-info'
SUCCESS = 'alert-success'
class MessageRegion(baseregion.BaseRegion):
_close_locator = (by.By.CSS_SELECTOR, 'a.close')
def _msg_locator(self, level):
return (by.By.CSS_SELECTOR, 'div.alert.%s' % level)
def __init__(self, driver, conf, level=SUCCESS):
self._default_src_locator = self._msg_locator(level)
# NOTE(nhelgeson): Running selenium on remote servers
# requires extra time to wait for message to pop up.
driver.implicitly_wait(conf.selenium.message_implicit_wait)
try:
super().__init__(driver, conf)
except NoSuchElementException:
self.src_elem = None
finally:
self._turn_on_implicit_wait()
def exists(self):
return self._is_element_displayed(self.src_elem)
def close(self):
self._get_element(*self._close_locator).click()