Fix test_user::test_login_without_username (Web UI test)

Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
Serhii Tsymbaliuk 2018-08-30 08:58:35 +02:00
parent 1f04c481e3
commit 685cef554b
9 changed files with 56 additions and 48 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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]

View File

@ -419,7 +419,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"]',

View File

@ -122,20 +122,22 @@ class UI_driver(object):
if NO_SELENIUM:
raise unittest.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
@ -148,7 +150,7 @@ 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 unittest.SkipTest("Invalid Web UI config.\n%s" % e)
except IOError as e:
@ -156,9 +158,9 @@ class UI_driver(object):
"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():
@ -174,13 +176,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
@ -189,9 +192,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 unittest.SkipTest('Selenium server host not configured')
host = self.config["host"]
host = cls.config["host"]
if browser == 'chrome':
capabilities = DesiredCapabilities.CHROME
@ -221,9 +224,9 @@ class UI_driver(object):
driver = webdriver.Ie()
else:
fp = None
if "ff_profile" in self.config:
fp = webdriver.FirefoxProfile(self.config["ff_profile"])
ff_log_path = self.config.get("geckodriver_log_path")
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 unittest.SkipTest(
@ -354,22 +357,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())