Add UI Tests for Deleting Multiple Images.

Added new scenario for deleting multiple images.

The scenario tests that each image is deleted
separately. Afterward, it tests that all the
images are deleted together.

Change-Id: Ib5292e3347101a19f5cc01dbc4999584508186c4
Partial-Bug: #1596196
This commit is contained in:
Felipe Monteiro 2016-12-16 17:07:37 -05:00
parent 561dc10a70
commit 24ee71f94e
2 changed files with 74 additions and 6 deletions

View File

@ -275,7 +275,7 @@ class UITestCase(BaseDeps):
ui.WebDriverWait(self.driver, sec).until( ui.WebDriverWait(self.driver, sec).until(
EC.presence_of_element_located((method, value))) EC.presence_of_element_located((method, value)))
except exc.TimeoutException: except exc.TimeoutException:
self.fail("Element {0} is not preset on the page".format(value)) self.fail("Element {0} is not present on the page".format(value))
def check_element_not_on_page(self, method, value): def check_element_not_on_page(self, method, value):
self.driver.implicitly_wait(3) self.driver.implicitly_wait(3)
@ -284,7 +284,7 @@ class UITestCase(BaseDeps):
self.driver.find_element(method, value) self.driver.find_element(method, value)
except (exc.NoSuchElementException, exc.ElementNotVisibleException): except (exc.NoSuchElementException, exc.ElementNotVisibleException):
present = False present = False
self.assertFalse(present, u"Element {0} is preset on the page" self.assertFalse(present, u"Element {0} is present on the page"
" while it should't".format(value)) " while it should't".format(value))
self.driver.implicitly_wait(30) self.driver.implicitly_wait(30)
@ -294,7 +294,7 @@ class UITestCase(BaseDeps):
ui.WebDriverWait(self.driver, sec).until( ui.WebDriverWait(self.driver, sec).until(
EC.presence_of_element_located(locator)) EC.presence_of_element_located(locator))
except exc.TimeoutException: except exc.TimeoutException:
self.fail("Alert is not preset on the page") self.fail("Alert is not present on the page")
self.assertIn(message, self.driver.find_element(*locator).text) self.assertIn(message, self.driver.find_element(*locator).text)
@ -427,13 +427,15 @@ class ImageTestCase(PackageBase):
glance_endpoint = cls.service_catalog.url_for(service_type='image') glance_endpoint = cls.service_catalog.url_for(service_type='image')
cls.glance = gclient.Client('1', endpoint=glance_endpoint, cls.glance = gclient.Client('1', endpoint=glance_endpoint,
session=cls.keystone_client.session) session=cls.keystone_client.session)
cls.images = []
cls.image_title = 'New Image ' + str(time.time()) cls.image_title = 'New Image ' + str(time.time())
cls.image = cls.upload_image(cls.image_title) cls.image = cls.upload_image(cls.image_title)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
super(ImageTestCase, cls).tearDownClass() super(ImageTestCase, cls).tearDownClass()
cls.glance.images.delete(cls.image.id) for image in cls.images:
cls.glance.images.delete(image.id)
@classmethod @classmethod
def upload_image(cls, title): def upload_image(cls, title):
@ -449,6 +451,7 @@ class ImageTestCase(PackageBase):
except Exception: except Exception:
logger.error("Unable to create or update image in Glance") logger.error("Unable to create or update image in Glance")
raise raise
cls.images.append(image)
return image return image
def select_and_click_element(self, element): def select_and_click_element(self, element):

View File

@ -476,12 +476,77 @@ class TestSuiteImage(base.ImageTestCase):
self.go_to_submenu('Images') self.go_to_submenu('Images')
self.driver.find_element_by_xpath( self.driver.find_element_by_xpath(
c.DeleteImageMeta.format(self.image_title)).click() c.DeleteImageMeta.format(self.image_title)).click()
self.driver.find_element_by_xpath(c.ConfirmDeletion).click() with self.wait_for_page_reload():
self.driver.find_element_by_xpath(c.ConfirmDeletion).click()
self.wait_for_alert_message()
self.check_element_not_on_page(by.By.XPATH, self.check_element_not_on_page(by.By.XPATH,
c.TestImage.format(self.image_title)) c.TestImage.format(self.image_title))
self.repair_image() self.repair_image()
def test_delete_multiple_images(self):
"""Test ability to delete multiple images.
Scenario:
1. Create 3 randomly named images.
2. Navigate to Images page.
3. For each randomly created image:
a. Select current image and click on "Delete Metadata". Each
image is deleted separately.
4. Re-create 3 randomly named images.
5. Refresh page.
6. Select topmost checkbox and click on "Delete Metadata". All
images are deleted together.
7. For each randomly created image:
a. Check that the current image was deleted.
8. Check that ``self.image_title`` was also deleted.
"""
default_image_title = self.image_title
image_titles = []
for i in range(3):
image_title = self.gen_random_resource_name('image')
image_titles.append(image_title)
self.upload_image(image_title)
self.navigate_to('Manage')
self.go_to_submenu('Images')
# Check each checkbox in the table and delete each image one by one.
for image_title in image_titles:
self.wait_element_is_clickable(
by.By.XPATH, c.DeleteImageMeta.format(image_title)).click()
with self.wait_for_page_reload():
self.driver.find_element_by_xpath(c.ConfirmDeletion).click()
self.wait_for_alert_message()
self.check_element_not_on_page(
by.By.XPATH, c.TestImage.format(image_title))
self.check_element_on_page(
by.By.XPATH, c.TestImage.format(default_image_title))
# Re-create 3 randomly named images.
image_titles = []
for i in range(3):
image_title = self.gen_random_resource_name('image')
image_titles.append(image_title)
self.upload_image(image_title)
# Check the topmost checkbox, then delete all images at the same time.
self.go_to_submenu('Images')
self.wait_element_is_clickable(by.By.CSS_SELECTOR,
'label[for="ui-id-1"]').click()
self.wait_element_is_clickable(by.By.ID,
'marked_images__action_delete').click()
with self.wait_for_page_reload():
self.driver.find_element_by_xpath(c.ConfirmDeletion).click()
self.wait_for_alert_message()
for image_title in image_titles:
self.check_element_not_on_page(
by.By.XPATH, c.TestImage.format(image_title))
self.check_element_not_on_page(
by.By.XPATH, c.TestImage.format(default_image_title))
self.repair_image() # Restore the class-level image that was deleted.
class TestSuiteFields(base.FieldsTestCase): class TestSuiteFields(base.FieldsTestCase):
def test_check_domain_name_field_validation(self): def test_check_domain_name_field_validation(self):