From da4e10f0adcd37f35d72b2ccb0eabd941a9e02d5 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Tue, 8 Mar 2016 15:00:56 +0300 Subject: [PATCH] Refactor some table rows & cells waits in i9n tests Abstract away the logic for waiting table row to become deleted and table cell to change its status common for different integration tests Page Objects into 2 TableRegion methods. Change-Id: Ib28708ffe5201f3dc595f842e24eda955ba339fc --- .../admin/system/volumes/volumetypespage.py | 18 ++++------------ .../pages/project/compute/imagespage.py | 12 ++--------- .../pages/project/compute/instancespage.py | 20 ++++-------------- .../compute/volumes/volumesnapshotspage.py | 20 ++++-------------- .../project/compute/volumes/volumespage.py | 21 ++++--------------- .../pages/project/network/networkspage.py | 12 ++--------- .../pages/project/network/routerspage.py | 12 ++--------- .../test/integration_tests/regions/tables.py | 16 ++++++++++++++ .../integration_tests/tests/test_volumes.py | 2 +- 9 files changed, 39 insertions(+), 94 deletions(-) diff --git a/openstack_dashboard/test/integration_tests/pages/admin/system/volumes/volumetypespage.py b/openstack_dashboard/test/integration_tests/pages/admin/system/volumes/volumetypespage.py index c29648acf0..6af25d1203 100644 --- a/openstack_dashboard/test/integration_tests/pages/admin/system/volumes/volumetypespage.py +++ b/openstack_dashboard/test/integration_tests/pages/admin/system/volumes/volumetypespage.py @@ -10,8 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from selenium.common import exceptions - 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 @@ -110,17 +108,9 @@ class VolumetypesPage(basepage.BaseNavigationPage): return bool(self._get_row_with_volume_type_name(name)) def is_qos_spec_deleted(self, name): - try: - getter = lambda: self._get_row_with_qos_spec_name(name) - self.wait_till_element_disappears(getter) - except exceptions.TimeoutException: - return False - return True + return self.qos_specs_table.is_row_deleted( + lambda: self._get_row_with_qos_spec_name(name)) def is_volume_type_deleted(self, name): - try: - getter = lambda: self._get_row_with_volume_type_name(name) - self.wait_till_element_disappears(getter) - except exceptions.TimeoutException: - return False - return True + return self.volume_types_table.is_row_deleted( + lambda: self._get_row_with_volume_type_name(name)) diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py index df8b60f363..7217e1c793 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/imagespage.py @@ -10,8 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from selenium.common import exceptions - 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 @@ -129,14 +127,8 @@ class ImagesPage(basepage.BaseNavigationPage): def is_image_active(self, name): row = self._get_row_with_image_name(name) - - def cell_getter(): - return row.cells[self.IMAGES_TABLE_STATUS_COLUMN] - try: - self._wait_till_text_present_in_element(cell_getter, 'Active') - except exceptions.TimeoutException: - return False - return True + return self.images_table.is_cell_status( + lambda: row.cells[self.IMAGES_TABLE_STATUS_COLUMN], 'Active') def wait_until_image_active(self, name): self._wait_until(lambda x: self.is_image_active(name)) diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/instancespage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/instancespage.py index cdfcc4e37a..ad74f75280 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/compute/instancespage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/instancespage.py @@ -9,8 +9,6 @@ # 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 import exceptions - 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 @@ -108,23 +106,13 @@ class InstancesPage(basepage.BaseNavigationPage): confirm_delete_instances_form.submit() def is_instance_deleted(self, name): - try: - getter = lambda: self._get_row_with_instance_name(name) - self.wait_till_element_disappears(getter) - except exceptions.TimeoutException: - return False - return True + return self.instances_table.is_row_deleted( + lambda: self._get_row_with_instance_name(name)) def is_instance_active(self, name): row = self._get_row_with_instance_name(name) - - def cell_getter(): - return row.cells[self.INSTANCES_TABLE_STATUS_COLUMN] - try: - self._wait_till_text_present_in_element(cell_getter, 'Active') - except exceptions.TimeoutException: - return False - return True + return self.instances_table.is_cell_status( + lambda: row.cells[self.INSTANCES_TABLE_STATUS_COLUMN], 'Active') def _get_source_name(self, instance, boot_source, conf): diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumesnapshotspage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumesnapshotspage.py index 0468d37e4d..1dab97bcc8 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumesnapshotspage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumesnapshotspage.py @@ -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 @@ -81,24 +80,13 @@ class VolumesnapshotsPage(basepage.BaseNavigationPage): confirm_form.submit() def is_volume_snapshot_deleted(self, name): - try: - getter = lambda: self._get_row_with_volume_snapshot_name(name) - self.wait_till_element_disappears(getter) - except exceptions.TimeoutException: - return False - return True + return self.volumesnapshots_table.is_row_deleted( + lambda: self._get_row_with_volume_snapshot_name(name)) def is_volume_snapshot_available(self, name): row = self._get_row_with_volume_snapshot_name(name) - - def cell_getter(): - return row.cells[self.SNAPSHOT_TABLE_STATUS_COLUMN] - - try: - self._wait_till_text_present_in_element(cell_getter, 'Available') - except exceptions.TimeoutException: - return False - return True + return self.volumesnapshots_table.is_cell_status( + lambda: row.cells[self.SNAPSHOT_TABLE_STATUS_COLUMN], 'Available') def get_volume_name(self, snapshot_name): row = self._get_row_with_volume_snapshot_name(snapshot_name) diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumespage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumespage.py index dedfd61c1d..1881013f3b 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumespage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/volumes/volumespage.py @@ -10,8 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from selenium.common import exceptions - 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 @@ -120,23 +118,12 @@ class VolumesPage(basepage.BaseNavigationPage): def is_volume_status(self, name, status): row = self._get_row_with_volume_name(name) - - def cell_getter(): - return row.cells[self.VOLUMES_TABLE_STATUS_COLUMN] - - try: - self._wait_till_text_present_in_element(cell_getter, status) - except exceptions.TimeoutException: - return False - return True + return self.volumes_table.is_cell_status( + lambda: row.cells[self.VOLUMES_TABLE_STATUS_COLUMN], status) def is_volume_deleted(self, name): - try: - getter = lambda: self._get_row_with_volume_name(name) - self.wait_till_element_disappears(getter) - except exceptions.TimeoutException: - return False - return True + return self.volumes_table.is_row_deleted( + lambda: self._get_row_with_volume_name(name)) def _get_source_name(self, volume_form, volume_source_type, conf, volume_source): diff --git a/openstack_dashboard/test/integration_tests/pages/project/network/networkspage.py b/openstack_dashboard/test/integration_tests/pages/project/network/networkspage.py index fe30d55531..9acb7a02ef 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/network/networkspage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/network/networkspage.py @@ -10,8 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from selenium.common import exceptions - 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 @@ -109,11 +107,5 @@ class NetworksPage(basepage.BaseNavigationPage): def is_network_active(self, name): row = self._get_row_with_network_name(name) - - def cell_getter(): - return row.cells[self.NETWORKS_TABLE_STATUS_COLUMN] - try: - self._wait_till_text_present_in_element(cell_getter, 'Active') - except exceptions.TimeoutException: - return False - return True + return self.networks_table.is_cell_status( + lambda: row.cells[self.NETWORKS_TABLE_STATUS_COLUMN], 'Active') diff --git a/openstack_dashboard/test/integration_tests/pages/project/network/routerspage.py b/openstack_dashboard/test/integration_tests/pages/project/network/routerspage.py index 7229d66474..3daf3fc4da 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/network/routerspage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/network/routerspage.py @@ -10,8 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from selenium.common import exceptions - 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 @@ -72,11 +70,5 @@ class RoutersPage(basepage.BaseNavigationPage): def is_router_active(self, name): row = self._get_row_with_router_name(name) - - def cell_getter(): - return row.cells[self.ROUTERS_TABLE_STATUS_COLUMN] - try: - self._wait_till_text_present_in_element(cell_getter, 'Active') - except exceptions.TimeoutException: - return False - return True + return self.routers_table.is_cell_status( + lambda: row.cells[self.ROUTERS_TABLE_STATUS_COLUMN], 'Active') diff --git a/openstack_dashboard/test/integration_tests/regions/tables.py b/openstack_dashboard/test/integration_tests/regions/tables.py index dadf35284a..21b69cba8e 100644 --- a/openstack_dashboard/test/integration_tests/regions/tables.py +++ b/openstack_dashboard/test/integration_tests/regions/tables.py @@ -131,6 +131,22 @@ class TableRegion(baseregion.BaseRegion): return [RowRegion(self.driver, self.conf, elem, self.column_names) for elem in self._get_elements(*self._rows_locator)] + def is_row_deleted(self, row_getter): + try: + self.wait_till_element_disappears(row_getter) + except exceptions.TimeoutException: + return False + except IndexError: + return True + return True + + def is_cell_status(self, cell_getter, status): + try: + self._wait_till_text_present_in_element(cell_getter, status) + except exceptions.TimeoutException: + return False + return True + def is_next_link_available(self): try: self._turn_off_implicit_wait() diff --git a/openstack_dashboard/test/integration_tests/tests/test_volumes.py b/openstack_dashboard/test/integration_tests/tests/test_volumes.py index a1deba4656..d6f2523583 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_volumes.py +++ b/openstack_dashboard/test/integration_tests/tests/test_volumes.py @@ -90,7 +90,7 @@ class TestVolumes(helpers.TestCase): count = 3 items_per_page = 1 volumes_names = ["{0}_{1}".format(self.VOLUME_NAME, i) for i in - xrange(count)] + range(count)] for volume_name in volumes_names: volumes_page.create_volume(volume_name) volumes_page.find_message_and_dismiss(messages.INFO)