From f20ee9e1412380dc24ee25a4ba8b8b92b7617c03 Mon Sep 17 00:00:00 2001 From: Serhii Tsymbaliuk Date: Sep 24 2018 07:14:58 +0000 Subject: Fix test_user::test_login_without_username (Web UI test) Reviewed-By: Alexander Bokovoy Reviewed-By: Petr Vobornik Reviewed-By: Tibor Dudlak --- diff --git a/ipatests/test_webui/test_automember.py b/ipatests/test_webui/test_automember.py index 5b07849..a6b48a2 100644 --- a/ipatests/test_webui/test_automember.py +++ b/ipatests/test_webui/test_automember.py @@ -95,7 +95,8 @@ class test_automember(UI_driver): self.init_app() host_util = host_tasks() - host_util.setup(self.driver, self.config) + host_util.driver = self.driver + host_util.config = self.config domain = self.config.get('ipa_domain') host1 = 'web1.%s' % domain host2 = 'web2.%s' % domain diff --git a/ipatests/test_webui/test_hostgroup.py b/ipatests/test_webui/test_hostgroup.py index 5655986..3899e13 100644 --- a/ipatests/test_webui/test_hostgroup.py +++ b/ipatests/test_webui/test_hostgroup.py @@ -59,7 +59,9 @@ class test_hostgroup(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config + host.prep_data2() # prepare # ------- @@ -101,7 +103,9 @@ class test_hostgroup(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config + host.prep_data2() # add # --- @@ -163,7 +167,8 @@ class test_hostgroup(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config self.add_record(hostgroup.ENTITY, hostgroup.DATA6) self.add_record(hostgroup.ENTITY, hostgroup.DATA7, navigate=False) diff --git a/ipatests/test_webui/test_idviews.py b/ipatests/test_webui/test_idviews.py index 7e7d905..ca64e36 100644 --- a/ipatests/test_webui/test_idviews.py +++ b/ipatests/test_webui/test_idviews.py @@ -96,7 +96,9 @@ class test_idviews(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config + host.prep_data() self.add_record(HOST_ENTITY, host.data) self.add_record(hostgroup.ENTITY, hostgroup.DATA) diff --git a/ipatests/test_webui/test_netgroup.py b/ipatests/test_webui/test_netgroup.py index 6f1c61e..d6c3c28 100644 --- a/ipatests/test_webui/test_netgroup.py +++ b/ipatests/test_webui/test_netgroup.py @@ -293,7 +293,10 @@ class test_netgroup(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config + host.prep_data() + host.prep_data2() self.add_record(netgroup.ENTITY, netgroup.DATA2) self.add_record(user.ENTITY, user.DATA) diff --git a/ipatests/test_webui/test_selinuxusermap.py b/ipatests/test_webui/test_selinuxusermap.py index af93cb6..dda4788 100644 --- a/ipatests/test_webui/test_selinuxusermap.py +++ b/ipatests/test_webui/test_selinuxusermap.py @@ -68,7 +68,10 @@ class test_selinuxusermap(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config + host.prep_data() + host.prep_data2() self.add_record(user.ENTITY, user.DATA) self.add_record(user.ENTITY, user.DATA2, navigate=False) diff --git a/ipatests/test_webui/test_sudo.py b/ipatests/test_webui/test_sudo.py index eb6430f..4aae2f1 100644 --- a/ipatests/test_webui/test_sudo.py +++ b/ipatests/test_webui/test_sudo.py @@ -53,7 +53,10 @@ class test_sudo(UI_driver): """ self.init_app() host = host_tasks() - host.setup(self.driver, self.config) + host.driver = self.driver + host.config = self.config + host.prep_data() + host.prep_data2() self.add_record(netgroup.ENTITY, netgroup.DATA2) diff --git a/ipatests/test_webui/test_trust.py b/ipatests/test_webui/test_trust.py index 621b2d4..57d7e7a 100644 --- a/ipatests/test_webui/test_trust.py +++ b/ipatests/test_webui/test_trust.py @@ -124,7 +124,8 @@ class test_trust(trust_tasks): self.init_app() r_tasks = range_tasks() - r_tasks.setup(self.driver, self.config) + r_tasks.driver = self.driver + r_tasks.config = self.config r_tasks.get_shifts() range_add = r_tasks.get_add_data('') base_id = range_add[2][2] diff --git a/ipatests/test_webui/test_user.py b/ipatests/test_webui/test_user.py index 0099574..bffa34b 100644 --- a/ipatests/test_webui/test_user.py +++ b/ipatests/test_webui/test_user.py @@ -416,7 +416,10 @@ class test_user(user_tasks): @screenshot def test_login_without_username(self): - + """ + Try to login with no username provided + """ + self.driver.delete_all_cookies() self.init_app(login='', password='xxx123') alert_e = self.find('.alert[data-name="username"]', diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py index 6d2d120..a5967b0 100644 --- a/ipatests/test_webui/ui_driver.py +++ b/ipatests/test_webui/ui_driver.py @@ -123,20 +123,22 @@ class UI_driver(object): if NO_SELENIUM: raise nose.SkipTest('Selenium not installed') - def setup(self, driver=None, config=None): + cls.driver = None + cls.config = None + cls.load_config() + if not cls.driver: + cls.driver = cls.get_driver() + + def setup(self): self.request_timeout = 60 - self.driver = driver - self.config = config - if not config: - self.load_config() - if not self.driver: - self.driver = self.get_driver() self.driver.maximize_window() - def teardown(self): - self.driver.quit() + @classmethod + def teardown_class(cls): + cls.driver.quit() - def load_config(self): + @classmethod + def load_config(cls): """ Load configuration @@ -149,15 +151,15 @@ class UI_driver(object): if not NO_YAML and os.path.isfile(path): try: with open(path, 'r') as conf: - self.config = yaml.load(conf) + cls.config = yaml.load(conf) except yaml.YAMLError as e: raise nose.SkipTest("Invalid Web UI config.\n%s" % e) except IOError as e: raise nose.SkipTest("Can't load Web UI test config: %s" % e) else: - self.config = {} + cls.config = {} - c = self.config + c = cls.config # override with environmental variables for k, v in ENV_MAP.items(): @@ -173,13 +175,14 @@ class UI_driver(object): if 'type' not in c: c['type'] = DEFAULT_TYPE - def get_driver(self): + @classmethod + def get_driver(cls): """ Get WebDriver according to configuration """ - browser = self.config["browser"] - port = self.config["port"] - driver_type = self.config["type"] + browser = cls.config["browser"] + port = cls.config["port"] + driver_type = cls.config["type"] options = None @@ -188,9 +191,9 @@ class UI_driver(object): options.binary_location = paths.CHROMIUM_BROWSER if driver_type == 'remote': - if 'host' not in self.config: + if 'host' not in cls.config: raise nose.SkipTest('Selenium server host not configured') - host = self.config["host"] + host = cls.config["host"] if browser == 'chrome': capabilities = DesiredCapabilities.CHROME @@ -216,9 +219,10 @@ class UI_driver(object): driver = webdriver.Ie() else: fp = None - if "ff_profile" in self.config: - fp = webdriver.FirefoxProfile(self.config["ff_profile"]) - driver = webdriver.Firefox(fp) + if "ff_profile" in cls.config: + fp = webdriver.FirefoxProfile(cls.config["ff_profile"]) + ff_log_path = cls.config.get("geckodriver_log_path") + driver = webdriver.Firefox(fp, log_path=ff_log_path) except URLError as e: raise nose.SkipTest('Error connecting to selenium server: %s' % e) except RuntimeError as e: @@ -344,22 +348,6 @@ class UI_driver(object): """ Navigate to Web UI first page and wait for loading of all dependencies. """ - # If the application is already loaded, there is no need to re-enter - # the URL on the address bar and reloading everything. - # This help us to create scenarios like login -> logout -> login - - # if a page is already loaded we click in the IPA logo to go to the - # initial page - ipa_logo = self.find('.navbar-brand', By.CSS_SELECTOR) - if ipa_logo and ipa_logo.is_displayed(): - self.move_to_element_in_page(ipa_logo) - ipa_logo.click() - return - - # already on the first page - if self.login_screen_visible(): - return - # if is not any of above cases, we need to load the application for # its first time entering the URL in the address bar self.driver.get(self.get_base_url())