Simplify tables page regions

Remove two redundancies: _get_rows() calls in BasicTableRegion
descendants and table_locator property (because it's derivative of
table name which is always specified).

Implements blueprint: integration-tests-improvements-part1

Change-Id: Ic8e4d44beb1ae5f99c096fc796420f2f8306feb0
This commit is contained in:
Timur Sufiev 2015-12-23 20:31:57 +03:00
parent 14ce229259
commit cc1213aa47
10 changed files with 38 additions and 78 deletions
openstack_dashboard/test/integration_tests

@ -10,8 +10,6 @@
# 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.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables
@ -21,8 +19,6 @@ class FlavorsPage(basepage.BaseNavigationPage):
DEFAULT_ID = "auto"
FLAVORS_TABLE_NAME_COLUMN_INDEX = 0
_flavors_table_locator = (by.By.ID, 'flavors')
FLAVORS_TABLE_NAME = "flavors"
FLAVORS_TABLE_ACTIONS = ("create", "delete")
FLAVORS_TABLE_ROW_ACTIONS = {
@ -45,9 +41,7 @@ class FlavorsPage(basepage.BaseNavigationPage):
@property
def flavors_table(self):
src_elem = self._get_element(*self._flavors_table_locator)
return tables.ComplexActionTableRegion(self.driver,
self.conf, src_elem,
return tables.ComplexActionTableRegion(self.driver, self.conf,
self.FLAVORS_TABLE_NAME,
self.FLAVORS_TABLE_ACTIONS,
self.FLAVORS_TABLE_ROW_ACTIONS)

@ -19,8 +19,6 @@ from openstack_dashboard.test.integration_tests.regions import tables
class ProjectsPage(basepage.BaseNavigationPage):
_projects_table_locator = (by.By.CSS_SELECTOR, 'table#tenants')
_create_project_cancel_button_locator = (
by.By.CSS_SELECTOR,
'a.btn.btn-default.secondary.cancel.close')
@ -56,13 +54,10 @@ class ProjectsPage(basepage.BaseNavigationPage):
@property
def projects_table(self):
src_elem = self._get_element(*self._projects_table_locator)
return tables.ComplexActionTableRegion(self.driver,
self.conf, src_elem,
return tables.ComplexActionTableRegion(self.driver, self.conf,
self.PROJECTS_TABLE_NAME,
self.PROJECTS_TABLE_ACTIONS,
self.PROJECTS_TABLE_ROW_ACTIONS
)
self.PROJECTS_TABLE_ROW_ACTIONS)
@property
def create_project_form(self):

@ -10,8 +10,6 @@
# 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.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables
@ -19,8 +17,6 @@ from openstack_dashboard.test.integration_tests.regions import tables
class UsersPage(basepage.BaseNavigationPage):
_users_table_locator = (by.By.CSS_SELECTOR, 'table#users')
USERS_TABLE_NAME_COLUMN_INDEX = 0
USERS_TABLE_NAME = "users"
@ -45,13 +41,10 @@ class UsersPage(basepage.BaseNavigationPage):
@property
def users_table(self):
src_elem = self._get_element(*self._users_table_locator)
return tables.ComplexActionTableRegion(self.driver,
self.conf, src_elem,
return tables.ComplexActionTableRegion(self.driver, self.conf,
self.USERS_TABLE_NAME,
self.USERS_TABLE_ACTIONS,
self.USERS_TABLE_ROW_ACTIONS
)
self.USERS_TABLE_ROW_ACTIONS)
@property
def create_user_form(self):

@ -25,8 +25,6 @@ from openstack_dashboard.test.integration_tests.regions import tables
class FloatingipsPage(basepage.BaseNavigationPage):
FLOATING_IPS_TABLE_NAME_COLUMN_INDEX = 0
_floating_ips_table_locator = (by.By.ID, 'floating_ips')
_floatingips_fadein_popup_locator = (
by.By.CSS_SELECTOR, '.alert.alert-success.alert-dismissable.fade.in>p')
@ -48,9 +46,8 @@ class FloatingipsPage(basepage.BaseNavigationPage):
@property
def floatingips_table(self):
src_elem = self._get_element(*self._floating_ips_table_locator)
return tables.ComplexActionTableRegion(
self.driver, self.conf, src_elem,
self.driver, self.conf,
self.FLOATING_IPS_TABLE_NAME,
self.FLOATING_IPS_TABLE_ACTIONS,
self.FLOATING_IPS_TABLE_ROW_ACTION)

@ -13,8 +13,6 @@
# 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.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables
@ -22,8 +20,6 @@ from openstack_dashboard.test.integration_tests.regions import tables
class KeypairsPage(basepage.BaseNavigationPage):
_key_pairs_table_locator = (by.By.ID, 'keypairs')
KEY_PAIRS_TABLE_NAME = "keypairs"
KEY_PAIRS_TABLE_ACTIONS = ("create", "import", "delete")
KEY_PAIRS_TABLE_ROW_ACTION = "delete"
@ -41,9 +37,7 @@ class KeypairsPage(basepage.BaseNavigationPage):
@property
def keypairs_table(self):
src_elem = self._get_element(*self._key_pairs_table_locator)
return tables.SimpleActionsTableRegion(self.driver, self.conf,
src_elem,
self.KEY_PAIRS_TABLE_NAME,
self.KEY_PAIRS_TABLE_ACTIONS,
self.KEY_PAIRS_TABLE_ROW_ACTION)

@ -10,8 +10,6 @@
# 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.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables
@ -21,8 +19,6 @@ class SecuritygroupsPage(basepage.BaseNavigationPage):
SECURITYGROUPS_TABLE_NAME_COLUMN_INDEX = 0
_securitygroups_table_locator = (by.By.ID, 'security_groups')
SECURITYGROUPS_TABLE_NAME = "security_groups"
SECURITYGROUPS_TABLE_ACTIONS = ("create", "delete")
SECURITYGROUPS_TABLE_ROW_ACTIONS = {
@ -43,9 +39,8 @@ class SecuritygroupsPage(basepage.BaseNavigationPage):
@property
def securitygroups_table(self):
src_elem = self._get_element(*self._securitygroups_table_locator)
return tables.ComplexActionTableRegion(
self.driver, self.conf, src_elem,
self.driver, self.conf,
self.SECURITYGROUPS_TABLE_NAME,
self.SECURITYGROUPS_TABLE_ACTIONS,
self.SECURITYGROUPS_TABLE_ROW_ACTIONS)

@ -11,7 +11,6 @@
# under the License.
from selenium.common import exceptions
from selenium.webdriver.common import by
from openstack_dashboard.test.integration_tests.pages import basepage
from openstack_dashboard.test.integration_tests.regions import forms
@ -27,8 +26,6 @@ class ImagesPage(basepage.BaseNavigationPage):
IMAGES_TABLE_NAME_COLUMN_INDEX = 0
IMAGES_TABLE_STATUS_COLUMN_INDEX = 2
_images_table_locator = (by.By.ID, 'images')
IMAGES_TABLE_NAME = "images"
IMAGES_TABLE_ACTIONS = ("create", "delete")
IMAGES_TABLE_ROW_ACTIONS = {
@ -53,13 +50,10 @@ class ImagesPage(basepage.BaseNavigationPage):
@property
def images_table(self):
src_elem = self._get_element(*self._images_table_locator)
return tables.ComplexActionTableRegion(self.driver,
self.conf, src_elem,
return tables.ComplexActionTableRegion(self.driver, self.conf,
self.IMAGES_TABLE_NAME,
self.IMAGES_TABLE_ACTIONS,
self.IMAGES_TABLE_ROW_ACTIONS
)
self.IMAGES_TABLE_ROW_ACTIONS)
@property
def create_image_form(self):

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from selenium.common import exceptions
from selenium.webdriver.common import by
from openstack_dashboard.test.integration_tests.pages import basepage
from openstack_dashboard.test.integration_tests.regions import forms
@ -28,8 +27,6 @@ class InstancesPage(basepage.BaseNavigationPage):
DEFAULT_VOL_DELETE_ON_INSTANCE_DELETE = False
DEFAULT_SECURITY_GROUP = True
_instances_table_locator = (by.By.CSS_SELECTOR, 'table#instances')
INSTANCES_TABLE_NAME = "instances"
INSTANCES_TABLE_ACTIONS = ("launch_ng", "launch", "delete",
('start', 'stop', "reboot"))
@ -64,9 +61,7 @@ class InstancesPage(basepage.BaseNavigationPage):
@property
def instances_table(self):
src_elem = self._get_element(*self._instances_table_locator)
return tables.ComplexActionTableRegion(self.driver,
self.conf, src_elem,
return tables.ComplexActionTableRegion(self.driver, self.conf,
self.INSTANCES_TABLE_NAME,
self.INSTANCES_TABLE_ACTIONS,
self.INSTANCES_TABLE_ROW_ACTIONS

@ -17,10 +17,10 @@ from openstack_dashboard.test.integration_tests.regions import tables
class OverviewPage(basepage.BaseNavigationPage):
_usage_table_locator = (by.By.ID, 'project_usage')
_date_form_locator = (by.By.ID, 'date_form')
USAGE_TABLE_ACTIONS = ("csv_summary",)
USAGE_TABLE_NAME = 'project_usage'
def __init__(self, driver, conf):
super(OverviewPage, self).__init__(driver, conf)
@ -28,8 +28,8 @@ class OverviewPage(basepage.BaseNavigationPage):
@property
def usage_table(self):
src_elem = self._get_element(*self._usage_table_locator)
return tables.ActionsTableRegion(self.driver, self.conf, src_elem,
return tables.ActionsTableRegion(self.driver, self.conf,
self.USAGE_TABLE_NAME,
self.USAGE_TABLE_ACTIONS)
@property

@ -125,6 +125,13 @@ class BasicTableRegion(baseregion.BaseRegion):
_search_button_locator = (by.By.CSS_SELECTOR,
'div.table_search.client > button')
def _table_locator(self, table_name):
return by.By.CSS_SELECTOR, 'table#%s' % table_name
def __init__(self, driver, conf, table_name):
self._default_src_locator = self._table_locator(table_name)
super(BasicTableRegion, self).__init__(driver, conf)
@property
def heading(self):
return self._get_element(*self._heading_locator)
@ -174,10 +181,12 @@ class BasicTableRegion(baseregion.BaseRegion):
btn = self._get_element(*self._search_button_locator)
btn.click()
def _get_rows(self):
rows = []
for elem in self._get_elements(*self._rows_locator):
rows.append(RowRegion(self.driver, self.conf, elem))
def _make_row(self, elem):
return RowRegion(self.driver, self.conf, elem)
def _get_rows(self, *args):
elements = self._get_elements(*self._rows_locator)
return [self._make_row(elem) for elem in elements]
class ActionsTableRegion(BasicTableRegion):
@ -189,8 +198,8 @@ class ActionsTableRegion(BasicTableRegion):
' div.table_actions > a')
# private methods
def __init__(self, driver, conf, src_elm, table_name, action_names):
super(ActionsTableRegion, self).__init__(driver, conf, src_elm)
def __init__(self, driver, conf, table_name, action_names):
super(ActionsTableRegion, self).__init__(driver, conf, table_name)
self._action_id_pattern = "%s__action_%%s" % table_name
self.action_names = action_names
self._init_actions()
@ -215,32 +224,26 @@ class ActionsTableRegion(BasicTableRegion):
class SimpleActionsTableRegion(ActionsTableRegion):
"""Table which rows has buttons in action column."""
def __init__(self, driver, conf, src_elm, table_name, action_names,
def __init__(self, driver, conf, table_name, action_names,
row_action_name):
super(SimpleActionsTableRegion, self).__init__(
driver, conf, src_elm, table_name, action_names)
driver, conf, table_name, action_names)
self.row_action_name = row_action_name
def _get_rows(self):
rows = []
for elem in self._get_elements(*self._rows_locator):
rows.append(BtnActionRowRegion(self.driver, self.conf, elem,
self.row_action_name))
return rows
def _make_row(self, elem):
return BtnActionRowRegion(self.driver, self.conf, elem,
self.row_action_name)
class ComplexActionTableRegion(ActionsTableRegion):
"""Table which has button and selectbox in the action column."""
def __init__(self, driver, conf, src_elm, table_name,
def __init__(self, driver, conf, table_name,
action_names, row_action_names):
super(ComplexActionTableRegion, self).__init__(
driver, conf, src_elm, table_name, action_names)
driver, conf, table_name, action_names)
self.row_action_names = row_action_names
def _get_rows(self):
rows = []
for elem in self._get_elements(*self._rows_locator):
rows.append(ComplexActionRowRegion(self.driver, self.conf, elem,
self.row_action_names))
return rows
def _make_row(self, elem):
return ComplexActionRowRegion(self.driver, self.conf, elem,
self.row_action_names)