diff --git a/openstack_dashboard/test/integration_tests/helpers.py b/openstack_dashboard/test/integration_tests/helpers.py index 8ff5c7d51e..95ecbb0a57 100644 --- a/openstack_dashboard/test/integration_tests/helpers.py +++ b/openstack_dashboard/test/integration_tests/helpers.py @@ -12,6 +12,7 @@ import os import time +import traceback import uuid import testtools @@ -43,6 +44,8 @@ def gen_random_resource_name(resource="", timestamp=True): class BaseTestCase(testtools.TestCase): + CONFIG = config.get_config() + def setUp(self): if os.environ.get('INTEGRATION_TESTS', False): # Start a virtual display server for running the tests headless. @@ -57,14 +60,38 @@ class BaseTestCase(testtools.TestCase): # Start the Selenium webdriver and setup configuration. self.driver = webdriver.WebDriverWrapper() self.driver.maximize_window() - self.conf = config.get_config() - self.driver.implicitly_wait(self.conf.selenium.implicit_wait) - self.driver.set_page_load_timeout(self.conf.selenium.page_timeout) + self.driver.implicitly_wait(self.CONFIG.selenium.implicit_wait) + self.driver.set_page_load_timeout( + self.CONFIG.selenium.page_timeout) + self.addOnException(self._dump_page_html_source) else: msg = "The INTEGRATION_TESTS env variable is not set." raise self.skipException(msg) super(BaseTestCase, self).setUp() + def _dump_page_html_source(self, exc_info): + content = None + try: + pg_source = self._get_page_html_source() + content = testtools.content.Content( + testtools.content_type.ContentType('text', 'html'), + lambda: pg_source) + except Exception: + exc_traceback = traceback.format_exc() + content = testtools.content.text_content(exc_traceback) + finally: + self.addDetail("PageHTMLSource.html", content) + + def _get_page_html_source(self): + """Gets html page source. + + self.driver.page_source is not used on purpose because it does not + display html code generated/changed by javascript. + """ + + html_elem = self.driver.find_element_by_tag_name("html") + return html_elem.get_attribute("innerHTML").encode("UTF-8") + def tearDown(self): if os.environ.get('INTEGRATION_TESTS', False): self.driver.quit() @@ -75,11 +102,15 @@ class BaseTestCase(testtools.TestCase): class TestCase(BaseTestCase): + TEST_USER_NAME = BaseTestCase.CONFIG.identity.username + TEST_PASSWORD = BaseTestCase.CONFIG.identity.password + def setUp(self): super(TestCase, self).setUp() - self.login_pg = loginpage.LoginPage(self.driver, self.conf) + self.login_pg = loginpage.LoginPage(self.driver, self.CONFIG) self.login_pg.go_to_login_page() - self.home_pg = self.login_pg.login() + self.home_pg = self.login_pg.login(self.TEST_USER_NAME, + self.TEST_PASSWORD) def tearDown(self): try: @@ -90,18 +121,7 @@ class TestCase(BaseTestCase): super(TestCase, self).tearDown() -class AdminTestCase(BaseTestCase): - def setUp(self): - super(AdminTestCase, self).setUp() - self.login_pg = loginpage.LoginPage(self.driver, self.conf) - self.login_pg.go_to_login_page() - self.home_pg = self.login_pg.login( - user=self.conf.identity.admin_username, - password=self.conf.identity.admin_password) +class AdminTestCase(TestCase): - def tearDown(self): - try: - if self.home_pg.is_logged_in: - self.home_pg.log_out() - finally: - super(AdminTestCase, self).tearDown() + TEST_USER_NAME = TestCase.CONFIG.identity.admin_username + TEST_PASSWORD = TestCase.CONFIG.identity.admin_password diff --git a/openstack_dashboard/test/integration_tests/tests/test_dashboard_help_redirection.py b/openstack_dashboard/test/integration_tests/tests/test_dashboard_help_redirection.py index aed19606a7..1db8c87466 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_dashboard_help_redirection.py +++ b/openstack_dashboard/test/integration_tests/tests/test_dashboard_help_redirection.py @@ -21,7 +21,7 @@ class TestDashboardHelp(helpers.TestCase): self.home_pg.go_to_help_page() self.home_pg.switch_window() - self.assertEqual(self.conf.dashboard.help_url, + self.assertEqual(self.CONFIG.dashboard.help_url, self.home_pg.get_url_current_page(), "help link did not redirect to the right URL") diff --git a/openstack_dashboard/test/integration_tests/tests/test_login.py b/openstack_dashboard/test/integration_tests/tests/test_login.py index 0159b0dec5..5c242b9e05 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_login.py +++ b/openstack_dashboard/test/integration_tests/tests/test_login.py @@ -21,7 +21,7 @@ class TestLogin(helpers.BaseTestCase): * checks that the user home page loads without error """ def test_login(self): - login_pg = loginpage.LoginPage(self.driver, self.conf) + login_pg = loginpage.LoginPage(self.driver, self.CONFIG) login_pg.go_to_login_page() home_pg = login_pg.login() if not home_pg.is_logged_in: diff --git a/openstack_dashboard/test/integration_tests/tests/test_password_change.py b/openstack_dashboard/test/integration_tests/tests/test_password_change.py index 42c49f8e3a..802faba7af 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_password_change.py +++ b/openstack_dashboard/test/integration_tests/tests/test_password_change.py @@ -33,11 +33,11 @@ class TestPasswordChange(helpers.TestCase): passwordchange_page = self.home_pg.go_to_settings_changepasswordpage() try: - passwordchange_page.change_password(self.conf.identity.password, + passwordchange_page.change_password(self.TEST_PASSWORD, NEW_PASSWORD) - self.home_pg = self.login_pg.login( - user=self.conf.identity.username, password=NEW_PASSWORD) + self.home_pg = self.login_pg.login(user=self.TEST_USER_NAME, + password=NEW_PASSWORD) self.assertTrue(self.home_pg.is_logged_in, "Failed to login with new password") finally: @@ -51,13 +51,13 @@ class TestPasswordChange(helpers.TestCase): passwordchange_page = self.home_pg.go_to_settings_changepasswordpage() try: - passwordchange_page.change_password(self.conf.identity.password, + passwordchange_page.change_password(self.TEST_PASSWORD, NEW_PASSWORD) self.assertTrue( self.login_pg.is_logout_reason_displayed(), "The logout reason message was not found on the login page") finally: - self.login_pg.login(user=self.conf.identity.username, + self.login_pg.login(user=self.TEST_USER_NAME, password=NEW_PASSWORD) self._reset_password() self._login() diff --git a/openstack_dashboard/test/integration_tests/tests/test_sahara_image_registry.py b/openstack_dashboard/test/integration_tests/tests/test_sahara_image_registry.py index ad93fa3682..29fe76c426 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_sahara_image_registry.py +++ b/openstack_dashboard/test/integration_tests/tests/test_sahara_image_registry.py @@ -28,7 +28,7 @@ class TestSaharaImageRegistry(helpers.TestCase): def test_image_register_unregister(self): """Test the image registration in Sahara.""" image_reg_pg = self.home_pg.go_to_dataprocessing_imageregistrypage() - image_reg_pg.register_image(IMAGE_NAME, self.conf.scenario.ssh_user, + image_reg_pg.register_image(IMAGE_NAME, self.CONFIG.scenario.ssh_user, "Test description") self.assertTrue(image_reg_pg.is_image_registered(IMAGE_NAME), "Image was not registered.") diff --git a/openstack_dashboard/test/integration_tests/tests/test_user_create_delete.py b/openstack_dashboard/test/integration_tests/tests/test_user_create_delete.py index c531567a27..58ea5e7187 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_user_create_delete.py +++ b/openstack_dashboard/test/integration_tests/tests/test_user_create_delete.py @@ -20,7 +20,7 @@ class TestUser(helpers.AdminTestCase): def test_create_delete_user(self): users_page = self.home_pg.go_to_identity_userspage() - password = self.conf.identity.password + password = self.TEST_PASSWORD users_page.create_user(self.USER_NAME, password=password, project='admin', role='admin') self.assertTrue(users_page.is_user_present(self.USER_NAME))