From 6e7681a607835a3d13096c7ef97c71f43775d9d3 Mon Sep 17 00:00:00 2001 From: ravikumar-venkatesan Date: Wed, 11 Jun 2014 09:17:10 +0000 Subject: [PATCH] Adds keypair create,delete integration tests I have added test_keypair.py which tests create keypair and delete keypair methods. And to allow this I have added keypairpage.py with two methods to create and delete keypairs. I have added accesssecuritypage.py which has_click_on_keypair_link method. Partially implements blueprint: selenium-integration-testing Change-Id: I9f8680fb51aa7dcf249e7487efa46240200a0ef2 --- .../pages/accesssecuritypage.py | 41 ++++++++++ .../test/integration_tests/pages/basepage.py | 27 +++++++ .../integration_tests/pages/keypairpage.py | 77 +++++++++++++++++++ .../integration_tests/pages/projectpage.py | 10 +++ .../integration_tests/tests/test_keypair.py | 35 +++++++++ 5 files changed, 190 insertions(+) create mode 100644 openstack_dashboard/test/integration_tests/pages/accesssecuritypage.py create mode 100644 openstack_dashboard/test/integration_tests/pages/keypairpage.py create mode 100644 openstack_dashboard/test/integration_tests/tests/test_keypair.py diff --git a/openstack_dashboard/test/integration_tests/pages/accesssecuritypage.py b/openstack_dashboard/test/integration_tests/pages/accesssecuritypage.py new file mode 100644 index 0000000000..c865297cee --- /dev/null +++ b/openstack_dashboard/test/integration_tests/pages/accesssecuritypage.py @@ -0,0 +1,41 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P +# All Rights Reserved. +# +# 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 import keypairpage + + +class AccessSecurityPage(basepage.BasePage): + + _keypair_link_locator = ( + by.By.CSS_SELECTOR, + 'a[href*="?tab=access_security_tabs__keypairs_tab"]') + + def __init__(self, driver, conf): + super(AccessSecurityPage, self).__init__(driver, conf) + self._page_title = "Access & Security" + + @property + def keypair_link(self): + return self.get_element(*self._keypair_link_locator) + + def _click_on_keypair_link(self): + self.keypair_link.click() + + def go_to_keypair_page(self): + self._click_on_keypair_link() + return keypairpage.KeypairPage(self.driver, self.conf) diff --git a/openstack_dashboard/test/integration_tests/pages/basepage.py b/openstack_dashboard/test/integration_tests/pages/basepage.py index 03e73a0d0c..2f1c2edb21 100644 --- a/openstack_dashboard/test/integration_tests/pages/basepage.py +++ b/openstack_dashboard/test/integration_tests/pages/basepage.py @@ -32,6 +32,10 @@ class BasePage(pageobject.PageObject): def is_logged_in(self): return self.topbar.is_logged_in + @property + def navaccordion(self): + return BasePage.NavigationAccordionRegion(self.driver, self.conf) + def go_to_login_page(self): self.driver.get(self.login_url) @@ -92,3 +96,26 @@ class BasePage(pageobject.PageObject): @property def is_logged_in(self): return self.is_element_visible(*self._user_indicator_locator) + + class NavigationAccordionRegion(pageobject.PageObject): + # TODO(sunlim): change Xpath to CSS + _project_bar_locator = ( + by.By.XPATH, + ".//*[@id='main_content']//div[contains(text(),'Project')]") + + _project_access_security_locator = ( + by.By.CSS_SELECTOR, 'a[href*="/project/access_and_security/"]') + + @property + def project_bar(self): + return self.get_element(*self._project_bar_locator) + + def _click_on_project_bar(self): + self.project_bar.click() + + @property + def access_security(self): + return self.get_element(*self._project_access_security_locator) + + def _click_on_access_security(self): + self.access_security.click() diff --git a/openstack_dashboard/test/integration_tests/pages/keypairpage.py b/openstack_dashboard/test/integration_tests/pages/keypairpage.py new file mode 100644 index 0000000000..fb757a31d8 --- /dev/null +++ b/openstack_dashboard/test/integration_tests/pages/keypairpage.py @@ -0,0 +1,77 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P +# All Rights Reserved. +# +# 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 + + +class KeypairPage(basepage.BasePage): + + _keypair_create_button_locator = (by.By.CSS_SELECTOR, + '#keypairs__action_create') + _keypair_name_field_locator = (by.By.CSS_SELECTOR, '#id_name') + _keypair_submit_button_locator = (by.By.CSS_SELECTOR, + '.btn.btn-primary.pull-right') + _keypair_delete_cnf_button_locator = (by.By.CSS_SELECTOR, + '.btn.btn-primary') + + def __init__(self, driver, conf): + super(KeypairPage, self).__init__(driver, conf) + self._page_title = "Access & Security" + + @property + def keypair_create(self): + return self.get_element(*self._keypair_create_button_locator) + + @property + def keypair_name_field(self): + return self.get_element(*self._keypair_name_field_locator) + + @property + def keypair_submit_button(self): + return self.get_element(*self._keypair_submit_button_locator) + + @property + def keypair_delete_cnf_button(self): + return self.get_element(*self._keypair_delete_cnf_button_locator) + + def _click_on_keypair_create(self): + self.keypair_create.click() + + def _click_on_keypair_submit_button(self): + self.keypair_submit_button.click() + + def _click_on_keypair_delete_cnf_button(self): + self.keypair_delete_cnf_button.click() + + def get_keypair_status(self, keypair_name): + keypair_locator = (by.By.CSS_SELECTOR, + '#keypairs__row__%s' % keypair_name) + keypair_status = self.is_element_present(*keypair_locator) + return keypair_status + + def create_keypair(self, keypair_name): + self._click_on_keypair_create() + self.keypair_name_field.send_keys(keypair_name) + self._click_on_keypair_submit_button() + + def delete_keypair(self, keypair_name): + keypair_delete_check_locator = ( + by.By.CSS_SELECTOR, + "#keypairs__row_%s__action_delete" % keypair_name) + self.driver.find_element( + *keypair_delete_check_locator).click() + self._click_on_keypair_delete_cnf_button() diff --git a/openstack_dashboard/test/integration_tests/pages/projectpage.py b/openstack_dashboard/test/integration_tests/pages/projectpage.py index 60bb3f3d2a..d37c421f82 100644 --- a/openstack_dashboard/test/integration_tests/pages/projectpage.py +++ b/openstack_dashboard/test/integration_tests/pages/projectpage.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from openstack_dashboard.test.integration_tests.pages import accesssecuritypage from openstack_dashboard.test.integration_tests.pages import basepage from openstack_dashboard.test.integration_tests.pages import settingspage @@ -23,3 +24,12 @@ class ProjectPage(basepage.BasePage): self.topbar.user_dropdown_menu.click() self.topbar.settings_link.click() return settingspage.SettingsPage(self.driver, self.conf) + + def go_to_accesssecurity_page(self): + access_security_locator_flag = self.is_element_visible( + self.navaccordion._project_access_security_locator) + if not access_security_locator_flag: + self.navaccordion.project_bar.click() + self.navaccordion.access_security.click() + return accesssecuritypage.AccessSecurityPage( + self.driver, self.conf) diff --git a/openstack_dashboard/test/integration_tests/tests/test_keypair.py b/openstack_dashboard/test/integration_tests/tests/test_keypair.py new file mode 100644 index 0000000000..1c2edf4d52 --- /dev/null +++ b/openstack_dashboard/test/integration_tests/tests/test_keypair.py @@ -0,0 +1,35 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P +# All Rights Reserved. +# +# 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. + +import random + +from openstack_dashboard.test.integration_tests import helpers + + +class TestKeypair(helpers.TestCase): + """Checks that the user is able to create/delete keypair.""" + KEYPAIR_NAME = 'horizonkeypair' + str(random.randint(0, 1000)) + + def test_keypair(self): + accesssecurity_page = self.home_pg.go_to_accesssecurity_page() + keypair_page = accesssecurity_page.go_to_keypair_page() + + keypair_page.create_keypair(self.KEYPAIR_NAME) + accesssecurity_page = self.home_pg.go_to_accesssecurity_page() + keypair_page = accesssecurity_page.go_to_keypair_page() + self.assertTrue(keypair_page.get_keypair_status(self.KEYPAIR_NAME)) + + keypair_page.delete_keypair(self.KEYPAIR_NAME) + self.assertFalse(keypair_page.get_keypair_status(self.KEYPAIR_NAME))