Timur Sufiev c573b5b316 Introduce field mappings for FormRegion descendants in i9n tests
This change is similar to the change that introduced decorators for
binding table-level and row-level actions to real table buttons - this
time for forms. Its aim is to provide means to reference a form field
in test using a name different from the one that exists in real
html.

Now it is possible to provide a dictionary for simple FormRegion,
where key is the name to be used in test and the value is used for
binding this name to a real html field widget. Also it is feasible to
provide values other than strings in that dictionary - in this case
they are mean to be a Python class. This Python class will be
initialized as any BaseRegion is usually initialized and then the
value's key will be used for referencing this object. This is useful
when dealing with non-standard widgets in forms (like Membership
widget in Create/Edit Project form or Networks widget in Launch
Instance form).

The old syntax for fields names in tests (the tuple of strings) is
still compatible with new FormRegion-s. It is treated as we had simply
used the same name both for referencing field and for binding it to a
real widget.

Changing TabbedForm region's tabs to be referenced by name instead of
index is out of the scope of this change, but should be done in future.
If not done, we're going to encounter problems with different tabs being
shown or not shown based on RBAC/ enabled settings/ etc.

Implements blueprint: integration-tests-improvements-part1
Change-Id: If3658119176d03dcd0742101ae2922f8e61ba757
2016-01-23 06:47:35 +00:00

84 lines
3.0 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.webdriver.common import by
from openstack_dashboard.test.integration_tests.pages import basepage
from openstack_dashboard.test.integration_tests.pages.settings import \
changepasswordpage
from openstack_dashboard.test.integration_tests.regions import forms
class UsersettingsPage(basepage.BaseNavigationPage):
DEFAULT_LANGUAGE = "en"
DEFAULT_TIMEZONE = "UTC"
DEFAULT_PAGESIZE = "20"
DEFAULT_LOGLINES = "35"
DEFAULT_SETTINGS = {
"language": DEFAULT_LANGUAGE,
"timezone": DEFAULT_TIMEZONE,
"pagesize": DEFAULT_PAGESIZE,
"loglines": DEFAULT_LOGLINES
}
SETTINGS_FORM_FIELDS = (
"language", "timezone", "pagesize", "instance_log_length")
_settings_form_locator = (by.By.ID, 'user_settings_modal')
_change_password_tab_locator = (by.By.CSS_SELECTOR,
'a[href*="/settings/password/"]')
def __init__(self, driver, conf):
super(UsersettingsPage, self).__init__(driver, conf)
self._page_title = "User Settings"
@property
def settings_form(self):
src_elem = self._get_element(*self._settings_form_locator)
return forms.FormRegion(
self.driver, self.conf, src_elem=src_elem,
field_mappings=self.SETTINGS_FORM_FIELDS)
@property
def changepassword(self):
return changepasswordpage.ChangePasswordPage(self.driver, self.conf)
@property
def change_password_tab(self):
return self._get_element(*self._change_password_tab_locator)
def change_language(self, lang=DEFAULT_LANGUAGE):
self.settings_form.language.value = lang
self.settings_form.submit()
def change_timezone(self, timezone=DEFAULT_TIMEZONE):
self.settings_form.timezone.value = timezone
self.settings_form.submit()
def change_pagesize(self, size=DEFAULT_PAGESIZE):
self.settings_form.pagesize.value = size
self.settings_form.submit()
def change_loglines(self, lines=DEFAULT_LOGLINES):
self.settings_form.instance_log_length.value = lines
self.settings_form.submit()
def return_to_default_settings(self):
self.change_language()
self.change_timezone()
self.change_pagesize()
self.change_loglines()
def go_to_change_password_page(self):
self.change_password_tab.click()
return changepasswordpage.ChangePasswordPage(self.driver, self.conf)