Add _wait_till_text_present_in_element method
* add selenium configuration group * add implicit/explicit wait and set page timeout Partially implements blueprint: selenium-integration-testing Change-Id: If39a5dcbac45635ad9988edfdc1830aeabc663a4
This commit is contained in:
parent
60cfc4e234
commit
e5ab83caf3
@ -11,7 +11,9 @@
|
||||
# under the License.
|
||||
|
||||
import selenium.common.exceptions as Exceptions
|
||||
from selenium.webdriver.support import expected_conditions
|
||||
import selenium.webdriver.support.ui as Support
|
||||
from selenium.webdriver.support import wait
|
||||
|
||||
|
||||
class BaseWebObject(object):
|
||||
@ -19,6 +21,7 @@ class BaseWebObject(object):
|
||||
def __init__(self, driver, conf):
|
||||
self.driver = driver
|
||||
self.conf = conf
|
||||
self.explicit_wait = self.conf.selenium.explicit_wait
|
||||
|
||||
def _is_element_present(self, *locator):
|
||||
try:
|
||||
@ -57,4 +60,14 @@ class BaseWebObject(object):
|
||||
self.driver.implicitly_wait(0)
|
||||
|
||||
def _turn_on_implicit_wait(self):
|
||||
self.driver.implicitly_wait(self.conf.dashboard.page_timeout)
|
||||
self.driver.implicitly_wait(self.conf.selenium.page_timeout)
|
||||
|
||||
def _wait_till_text_present_in_element(self, locator, text):
|
||||
condition = expected_conditions.text_to_be_present_in_element(locator,
|
||||
text)
|
||||
try:
|
||||
wait.WebDriverWait(self.driver, self.explicit_wait).\
|
||||
until(condition)
|
||||
except Exceptions.TimeoutException:
|
||||
return False
|
||||
return True
|
||||
|
@ -25,9 +25,6 @@ DashboardGroup = [
|
||||
cfg.StrOpt('help_url',
|
||||
default='http://docs.openstack.org/',
|
||||
help="Dashboard help page url"),
|
||||
cfg.IntOpt('page_timeout',
|
||||
default=10,
|
||||
help="Timeout in seconds"),
|
||||
]
|
||||
|
||||
IdentityGroup = [
|
||||
@ -50,7 +47,19 @@ IdentityGroup = [
|
||||
|
||||
AvailableServiceGroup = [
|
||||
cfg.BoolOpt('sahara',
|
||||
default=False),
|
||||
default=False)
|
||||
]
|
||||
|
||||
SeleniumGroup = [
|
||||
cfg.IntOpt('implicit_wait',
|
||||
default=10,
|
||||
help="Implicit wait timeout in seconds"),
|
||||
cfg.IntOpt('explicit_wait',
|
||||
default=10,
|
||||
help="Explicit wait timeout in seconds"),
|
||||
cfg.IntOpt('page_timeout',
|
||||
default=30,
|
||||
help="Page load timeout in seconds"),
|
||||
]
|
||||
|
||||
|
||||
@ -69,5 +78,6 @@ def get_config():
|
||||
cfg.CONF.register_opts(DashboardGroup, group="dashboard")
|
||||
cfg.CONF.register_opts(IdentityGroup, group="identity")
|
||||
cfg.CONF.register_opts(AvailableServiceGroup, group="service_available")
|
||||
cfg.CONF.register_opts(SeleniumGroup, group="selenium")
|
||||
|
||||
return cfg.CONF
|
||||
|
@ -33,7 +33,8 @@ class BaseTestCase(testtools.TestCase):
|
||||
self.driver = webdriver.WebDriverWrapper()
|
||||
self.driver.maximize_window()
|
||||
self.conf = config.get_config()
|
||||
self.driver.implicitly_wait(self.conf.dashboard.page_timeout)
|
||||
self.driver.implicitly_wait(self.conf.selenium.implicit_wait)
|
||||
self.driver.set_page_load_timeout(self.conf.selenium.page_timeout)
|
||||
else:
|
||||
msg = "The INTEGRATION_TESTS env variable is not set."
|
||||
raise self.skipException(msg)
|
||||
|
@ -12,9 +12,21 @@ login_url=http://localhost/auth/login/
|
||||
# Dashboard help page url (string value)
|
||||
help_url=http://docs.openstack.org/
|
||||
|
||||
[selenium]
|
||||
# Timeout in seconds to wait for a page to become available
|
||||
# (integer value)
|
||||
page_timeout=10
|
||||
page_timeout=30
|
||||
|
||||
# Implicit timeout to wait until element become available,
|
||||
# this timeout is used for every find_element, find_elements call.
|
||||
# (integer value)
|
||||
implicit_wait=10
|
||||
|
||||
# Explicit timeout is used for long lasting operations,
|
||||
# methods using explicit timeout are usually prefixed with 'wait',
|
||||
# those methods ignore implicit_wait when looking up web elements.
|
||||
# (integer value)
|
||||
explicit_wait=300
|
||||
|
||||
[identity]
|
||||
# Username to use for non-admin API requests. (string value)
|
||||
|
@ -15,6 +15,7 @@ from openstack_dashboard.test.integration_tests import basewebobject
|
||||
|
||||
class PageObject(basewebobject.BaseWebObject):
|
||||
"""Base class for page objects."""
|
||||
|
||||
def __init__(self, driver, conf):
|
||||
"""Constructor."""
|
||||
super(PageObject, self).__init__(driver, conf)
|
||||
|
Loading…
Reference in New Issue
Block a user