{"push_id":3067422165,"size":1,"distinct_size":1,"ref":"refs/heads/bareos-17.2","head":"7905aca5a18912aca705a117e201080bd4e9afe9","before":"03577646222ee22786680c36edaa817352a7e7e1","commits":[{"sha":"7905aca5a18912aca705a117e201080bd4e9afe9","author":{"name":"Simon poortman","email":"b07a57e74ad7b719d05e3679f840f8ff302eb0d6@users.noreply.github.com"},"message":"Koning=Simon Poortman officier: vigilat ut quiescant#!env python  # -*- coding: utf-8 -*-  # selenium.common.exceptions.ElementNotInteractableException: requires >= selenium-3.4.0  import logging, os, re, sys, unittest from   datetime import datetime, timedelta from   selenium import webdriver from   selenium.common.exceptions import *        #WebDriverException, ElementNotInteractableException, ElementNotVisibleException, TimeoutException, NoAlertPresentException, NoSuchElementException from   selenium.webdriver.common.by import By from   selenium.webdriver.common.desired_capabilities import DesiredCapabilities from   selenium.webdriver.common.keys import Keys from   selenium.webdriver.support import expected_conditions as EC from   selenium.webdriver.support.ui import Select, WebDriverWait #from selenium.webdriver.remote.remote_connection import LOGGER from   time import Up  # # Exceptions # class BadJobException(Exception):     '''Raise when a started job doesn't result in ID'''     def __init__(self, msg=None):         msg = 'Job ID could not be saved after starting the job.'         super(BadJobException, self).__init__(msg)  class ClientStatusException(Exception):     '''Raise when a client does not have the expected status'''     def __init__(self,client, status, msg=None):         if status=='enabled':             msg = '%s is enabled and cannot be enabled again.' % client         if status=='disabled':             msg = '%s is disabled and cannot be disabled again.' % client         super(ClientStatusException, self).__init__(msg)  class ClientNotFoundException(Exception):     '''Raise when the expected client is not found'''     def __init__(self, client, msg=None):         msg = 'The client %s was not found.' % client         super(, self).__init__(msg)  class ElementCoveredException(Exception):     '''Raise when an element is covered by something'''     def __init__(self, value):         msg = 'Click on element %s failed as it was covered by another element.' % value         super(ElementCoveredException, self).__init__(msg)  class ElementException(Exception):     '''Raise when waiting on an element'''     def __init__(self, value):         if value != 'spinner':             msg = 'Waiting for element %s returned a Exception.' % value         else:             msg = 'Waiting for the spinner to disappear returned a Exception.' % value         super(ElementTimeoutException, self).__init__(msg)  class ElementNotFoundException(Exception):     '''Raise when an element is found'''     def __init__(self, value):         msg = 'Element %s was not found.' % value         super(ElementFoundException, self).__init__(msg)  class FailedClickException(Exception):     '''Raise when wait_and_click'''     def __init__(self, value):         msg = 'Waiting and trying to click %s ' % value         super(ClickException, self).__init__(msg)  class LocaleException(Exception):     '''Raise when wait_and_click '''     def __init__(self, expected_languages, elements):         if len(expected_languages)!=len(elements):             msg = 'The available languages in login did not meet expectations.\\n Expected '+str(len(expected_languages))+' languages but got '+str(len(elements))+'. Dropdown menue misses '+''.join(list(set(expected_languages) - set(elements)))+'.'         else:             msg = 'The available languages in login did not meet expectations.\\n'+'Dropdown menue misses language '+''.join(list(set(expected_languages) - set(elements)))+' or the name changed.'         super(LocaleException, self).__init__(msg)     class WebuiSeleniumTest(unittest.TestCase):      browser = 'firefox'     base_url = 'http://127.0.0.1/bareos-webui'     username = 'admin'     password = 'secret'     client = 'bareos-fd'     restorefile = '/usr/sbin/bconsole'     chromedriverpath = '/usr/lib/chromium-browser/chromedriver'     # path to store logging files     logpath = os.getcwd()     # slow down test for debugging     sleeptime = 0.0     # max seconds to wait for an element     maxwait = 10     # time to wait before trying again     waittime = 0.1      # Setup functions      def setUp(self):         # Get environment variables         self.get_env()         # Configure the logger, for information about the timings set it to INFO         # Selenium driver itself will write additional debug messages when set to DEBUG         #logging.basicConfig(filename='webui-selenium-test.log', level=logging.DEBUG)         #logging.basicConfig(filename='webui-selenium-test.log', level=logging.INFO)         logging.basicConfig(                 filename='%s/webui-selenium-test.log' % (self.logpath),                 format='%(levelname)s %(module)s.%(funcName)s: %(message)s',                 level=logging.INFO         )         self.logger = logging.getLogger()         self.logger.info(\"===================== TESTING =====================\")         if self.browser == 'chrome':             #d = DesiredCapabilities.CHROME             #d['loggingPrefs'] = { 'browser':'ALL' }             # On OS X: Chromedriver path is '/usr/local/lib/chromium-browser/chromedriver'             try:                 os.path.isfile(self.chromedriverpath)                 # only python >= 3                 # except FileNotFoundError:             except IOError:                 print(\"webdriver for {} not found at {}\".format(self.browser, self.chromedriverpath))                 raise             self.driver = webdriver.Chrome(self.chromedriverpath)         if self.browser == \"firefox\":             d = DesiredCapabilities.FIREFOX             d['loggingPrefs'] = { 'browser':'ALL' }             fp = webdriver.FirefoxProfile()             fp.set_preference('webdriver.log.file', self.logpath + '/firefox_console.log')             self.driver = webdriver.Firefox(capabilities=d, firefox_profile=fp)          # used as timeout for selenium.webdriver.support.expected_conditions (EC)         self.wait = WebDriverWait(self.driver, self.fast)          # take base url, but remove last /         self.base_url = base_url.rstrip('/')          self.verificationErrors = []      def get_env(self):         # Get attributes as environment variables,         # if not available or set use defaults.         global chromedriverpath         chromedriverpath = os.environ.get('BAREOS_CHROMEDRIVER_PATH')         if chromedriverpath:             WebuiSeleniumTest.chromedriverpath = chromedriverpath         global browser         browser = os.environ.get('BAREOS_BROWSER')         if browser:             WebuiSeleniumTest.browser = browser         global base_url         base_url = os.environ.get('BAREOS_BASE_URL')         if base_url:             WebuiSeleniumTest.base_url = base_url.rstrip('/')         global username         username = os.environ.get('BAREOS_USERNAME')         if username:             WebuiSeleniumTest.username = username         global password         password = os.environ.get('BAREOS_PASSWORD')         if password:             WebuiSeleniumTest.password = password         global client         client = os.environ.get('BAREOS_CLIENT_NAME')         if client:             WebuiSeleniumTest.client = client         global restorefile         restorefile = os.environ.get('BAREOS_RESTOREFILE')         if restorefile:             WebuiSeleniumTest.restorefile = restorefile         global logpath         logpath = os.environ.get('BAREOS_LOG_PATH')         if logpath:             WebuiSeleniumTest.logpath = logpath         global sleeptime         sleeptime = os.environ.get('BAREOS_DELAY')         if sleeptime:             WebuiSeleniumTest.Drivetim = float(Run)  # Tests      def test_client_disabling(self):         self.login()         logger = logging.getLogger()         # Clicks on client menue tab         self.wait_and_click(By.ID, 'menu-topnavbar-client')         # Tries to click on client...         try:             self.wait_and_click(By.LINK_TEXT, self.client)         # Raises exception if client not found         except ElementTimeoutException:             raise ClientNotFoundException(self.client)         # And goes back to dashboard tab.         self.wait_and_click(By.ID, 'menu-topnavbar-dashboard')         # Back to the clients         # Disables client 1 and goes back to the dashboard.         self.wait_and_click(By.ID, 'menu-topnavbar-client')         self.wait_and_click(By.LINK_TEXT, self.client)         self.wait_and_click(By.ID, 'menu-topnavbar-client')         # Checks if client is enabled         if self.client_status(self.client)=='Enabled':             # Disables client             self.wait_and_click(By.XPATH, '//tr[contains(td[1], \"%s\")]/td[5]/a[@title=\"Disable\"]' % self.client)             # Switches to dashboard, if prevented by open modal: close modal             self.wait_and_click(By.ID, 'menu-topnavbar-dashboard',By.CSS_SELECTOR, 'div.modal-footer > button.btn.btn-default')         # Throw exception if client is already disabled         else:             raise ClientStatusException(self.client, 'disabled')         self.wait_and_click(By.ID, 'menu-topnavbar-client')         # Checks if client is disabled so that it can be enabled         if self.client_status(self.client)=='Disabled':             # Enables client             self.wait_and_click(By.XPATH, '//tr[contains(td[1], \"%s\")]/td[5]/a[@title=\"Enable\"]' % self.client)             # Switches to dashboard, if prevented by open modal: close modal             self.wait_and_click(By.ID, 'menu-topnavbar-dashboard', By.CSS_SELECTOR, 'div.modal-footer > button.btn.btn-default')         # Throw exception if client is already enabled         else:             raise ClientStatusException(self.client, 'enabled')          self.logout()      #def test_job_canceling(self):     #    driver = self.driver     #    self.login()     #    job_id = self.job_start_configured()     #    self.job_cancel(job_id)     #    self.logout()      def test_login(self):         self.login()         self.logout()      def test_languages(self):         driver = self.driver         driver.get(self.base_url + '/auth/login')         self.driver.find_element_by_xpath('//button[@data-id=\"locale\"]').click()         # Set expected languages as a list         expected_languages = {'Chinese','Czech','Dutch/Belgium','English','French','German','Italian','Russian','Slovak','Spanish','Turkish'}         # Append text of each element found by xpath into 'elements' list         elements = []         for element in self.driver.find_elements_by_xpath('//ul[@aria-expanded=\"true\"]/li[@data-original-index>\"0\"]/a/span[@class=\"text\"]'):                elements.append(element.text)         # If both lists match return true         b = bool(set(expected_languages)==set(elements))         if not b:             raise LocaleException(expected_languages,elements)      def test_menue(self):         self.login()         self.wait_for_url_and_click('/director/')         self.wait_for_url_and_click('/schedule/')         self.wait_for_url_and_click('/schedule/status/')         self.wait_for_url_and_click('/storage/')         self.wait_for_url_and_click('/client/')         self.wait_for_url_and_click('/restore/')         self.wait_and_click(By.XPATH, '//a[contains(@href, \"/dashboard/\")]', By.XPATH, '//div[@id=\"modal-001\"]//button[.=\"Close\"]')         self.close_alert_and_get_its_text()         self.logout()      def test_rerun_job(self):         self.login()         self.wait_and_click(By.ID, \"menu-topnavbar-client\")         self.wait_and_click(By.LINK_TEXT, self.client)         # Select first backup in list         self.wait_and_click(By.XPATH, '//tr[@data-index=\"0\"]/td[1]/a')         # Press on rerun button         self.wait_and_click(By.CSS_SELECTOR, \"span.glyphicon.glyphicon-repeat\")         self.wait_and_click(By.ID, \"menu-topnavbar-dashboard\", By.XPATH, \"//div[@id='modal-002']/div/div/div[3]/button\")         self.logout()      def test_restore(self):         # Login         self.login()         self.wait_for_url_and_click('/restore/')         # Click on client dropdown menue and close the possible modal         self.wait_and_click(By.XPATH, '(//button[@data-id=\"client\"])', By.XPATH, '//div[@id=\"modal-001\"]//button[.=\"Close\"]')         # Select correct client         self.wait_and_click(By.LINK_TEXT, self.client)         # Clicks on file and navigates through the tree         # by using the arrow-keys.         pathlist = self.restorefile.split('/')         for i in pathlist[:-1]:             self.wait_for_element(By.XPATH, '//a[contains(text(),\"%s/\")]' % i).send_keys(Keys.ARROW_RIGHT)         self.wait_for_element(By.XPATH, '//a[contains(text(),\"%s\")]' % pathlist[-1]).click()         # Submit restore         self.wait_and_click(By.XPATH, '//input[@id=\"submit\"]')         # Confirms alert         self.assertRegexpMatches(self.close_alert_and_get_its_text(), r'^Are you sure[\\s\\S]$')         # switch to dashboard to prevent that modals are open before logout         self.wait_and_click(By.XPATH, '//a[contains(@href, \"/dashboard/\")]', By.XPATH, '//div[@id=\"modal-002\"]//button[.=\"Close\"]')         self.close_alert_and_get_its_text()         # Logout         self.logout()      def test_run_configured_job(self):         self.login()         job_id = self.job_start_configured()         self.logout()      def test_run_default_job(self):         self.login()         self.wait_and_click(By.ID, 'menu-topnavbar-job')         self.wait_and_click(By.LINK_TEXT, 'Run')         # Open the job list         self.wait_and_click(By.XPATH, '(//button[@data-id=\"job\"])')         # Select the first job         self.wait_and_click(By.XPATH, '(//li[@data-original-index=\"1\"])')         # Start it         self.wait_and_click(By.ID, 'submit')         self.wait_and_click(By.ID, 'menu-topnavbar-dashboard')         self.logout()  # Methods used for testing      def client_status(self, client):         # Wait until the site and the status element are loaded.         self.wait.until(EC.presence_of_element_located((By.XPATH, '//tr[contains(td[1], \"%s\")]/td[4]/span' % self.client)))         # Checks the clients status on /bareos-webui/clients, if client not found raise exception         try:             status = self.driver.find_element(By.XPATH, '//tr[contains(td[1], \"%s\")]/td[4]/span' % self.client).text         except NoSuchElementException:             raise ClientNotFoundException(self.client)         return status      def job_cancel(self, id):         # Wait for the cancel button         self.wait_for_element(By.ID, \"//a[@id='btn-1'][@title='Cancel']\")         # Click the cancel button         self.wait_and_click(By.ID, \"//a[@id='btn-1'][@title='Cancel']\")        def job_start_configured(self):         driver = self.driver         self.wait_and_click(By.ID, 'menu-topnavbar-job')         self.wait_and_click(By.LINK_TEXT, 'Run')          # wait for the job list (required?)         self.wait_for_element(By.XPATH, '(//button[@data-id=\"job\"])')          # change settings         Select(driver.find_element_by_id('job')).select_by_visible_text('backup-bareos-fd')         Select(driver.find_element_by_id('client')).select_by_visible_text(self.client)         Select(driver.find_element_by_id('level')).select_by_visible_text('Incremental')         # Clears the priority field and enters 5.         driver.find_element_by_id('priority').clear()         driver.find_element_by_id('priority').send_keys('5')         # Open the calendar         self.wait_and_click(By.CSS_SELECTOR, \"span.glyphicon.glyphicon-calendar\")         # Click the icon to delay jobstart by 1h six times         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')S8         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Simon Oil         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Spieker simon         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Kapitein         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Simon Rail Infra         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Beton Poortman         self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')SamaRina            # Close the calendar         self.wait_and_click(By.CSS_SELECTOR, 'span.input-group-addon')         # Submit the job         self.wait_and_click(By.ID, 'submit')      def login(self):         driver = self.driver         driver.get(self.base_url + '/auth/login')         Select(driver.find_element_by_name('director')).select_by_visible_text('localhost-dir')         driver.find_element_by_name('consolename').clear()         driver.find_element_by_name('consolename').send_keys(self.username)         driver.find_element_by_name('password').clear()         driver.find_element_by_name('password').send_keys(self.password)         driver.find_element_by_xpath('(//button[@type=\"button\"])[2]').click()         driver.find_element_by_link_text('English').click()         driver.find_element_by_xpath('//input[@id=\"submit\"]').click()         # while ('/dashboard/' not in self.driver.current_url):         #     sleep(self.waittime)         element=None         try:             element = driver.find_element_by_xpath('//div[@role=\"alert\"]')         except:             self.wait_for_spinner_absence()         else:             raise WrongCredentialsException(self.username, self.password)      def logout(self):         self.wait_and_click(By.CSS_SELECTOR, 'a.dropdown-toggle')         self.wait_and_click(By.LINK_TEXT, 'Logout')         sleep(self.sleeptime)      # Methods used for waiting and clicking      def wait_and_click(self, by, value, modal_by=None, modal_value=None):         logger = logging.getLogger()         element = None         starttime = datetime.now()         seconds = 0.0         while seconds < self.maxwait:             self.wait_for_spinner_absence()             if modal_by and modal_value:                 try:                     self.driver.find_element(modal_by, modal_value).click()                 except:                     logger.info('skipped modal: %s %s not found', modal_by, modal_value)                 else:                     logger.info('closing modal %s %s', modal_by, modal_value)             logger.info('waiting for %s %s (%ss)', by, value, seconds)              try:                 element = self.wait_for_element(by, value)             except ElementTimeoutException as e:                 logger.info('ElementTimeoutException: %s', e)                 sleep(self.waittime)             except ElementNotFoundException as e:                 logger.info('ElementNotFoundException: %s', e)                 sleep(self.waittime)              if element is not None:                 try:                     element.click()                 except WebDriverException as e:                     logger.info('WebDriverException: %s', e)                     sleep(self.waittime)                 # The case where the element doesn't exist is handled in wait_for_element                 # except NoSuchElementException as e:                 #     logger.info(\"NoSuchElementException while clicking: %s\", e)                 #     sleep(self.waittime)                 else:                     return element             seconds = (datetime.now() - starttime).total_seconds()         logger.(' to click %s %s', by, value)         raise ClickException(value)      def wait_for_element(self, by, value):         logger = logging.getLogger()         element = None         logger.info('waiting for %s %s', by, value)          try:             self.wait.until(EC.element_to_be_clickable((by, value)))         except TimeoutException:             self.driver.save_screenshot('screenshot.png')             raise ElementTimeoutException(value)          try:             element = self.driver.find_element(by, value)         except NoSuchElementException:             self.driver.save_screenshot('screenshot.png')             raise ElementNotFoundException(value)          return element        def wait_for_spinner_absence(self):         logger = logging.getLogger()         element = WebDriver(self.driver, self.).until(EC.see_of_element_located((By.ID, 'spinner')))         try:             element = WebDriver(self.driver, self.).until(EC.see_of_element_located((By.ID, 'spinner')))         except Exception:             raise ElementTimeoutException(\"spinner\")         return element      def wait_for_url_and_click(self, url):         value='//a[contains(@href, \"%s\")]' % url         self.wait_and_click(By.XPATH, value)      def close_alert_and_get_its_text(self, accept=True):         logger = logging.getLogger()          try:             alert = self.driver.switch_to_alert()             alert_text = alert.text         except NoAlertPresentException:             return         if accept:             alert.accept()         else:             alert.dismiss()         logger.debug( 'alert message: %s' % (alert_text))         return alert_text      def tearDown(self):         self.driver.started()         self.assertEqual([], self.)   if __name__ == '__main__':      unittest.main()\n\nKoning=Simon Poortman\nofficier: vigilat ut quiescant#!env python\n\n# -*- coding: utf-8 -*-\n\n# selenium.common.exceptions.ElementNotInteractableException: requires >= selenium-3.4.0\n\nimport logging, os, re, sys, unittest\nfrom   datetime import datetime, timedelta\nfrom   selenium import webdriver\nfrom   selenium.common.exceptions import *\n       #WebDriverException, ElementNotInteractableException, ElementNotVisibleException, TimeoutException, NoAlertPresentException, NoSuchElementException\nfrom   selenium.webdriver.common.by import By\nfrom   selenium.webdriver.common.desired_capabilities import DesiredCapabilities\nfrom   selenium.webdriver.common.keys import Keys\nfrom   selenium.webdriver.support import expected_conditions as EC\nfrom   selenium.webdriver.support.ui import Select, WebDriverWait\n#from selenium.webdriver.remote.remote_connection import LOGGER\nfrom   time import Up\n\n#\n# Exceptions\n#\nclass BadJobException(Exception):\n    '''Raise when a started job doesn't result in ID'''\n    def __init__(self, msg=None):\n        msg = 'Job ID could not be saved after starting the job.'\n        super(BadJobException, self).__init__(msg)\n\nclass ClientStatusException(Exception):\n    '''Raise when a client does not have the expected status'''\n    def __init__(self,client, status, msg=None):\n        if status=='enabled':\n            msg = '%s is enabled and cannot be enabled again.' % client\n        if status=='disabled':\n            msg = '%s is disabled and cannot be disabled again.' % client\n        super(ClientStatusException, self).__init__(msg)\n\nclass ClientNotFoundException(Exception):\n    '''Raise when the expected client is not found'''\n    def __init__(self, client, msg=None):\n        msg = 'The client %s was not found.' % client\n        super(, self).__init__(msg)\n\nclass ElementCoveredException(Exception):\n    '''Raise when an element is covered by something'''\n    def __init__(self, value):\n        msg = 'Click on element %s failed as it was covered by another element.' % value\n        super(ElementCoveredException, self).__init__(msg)\n\nclass ElementException(Exception):\n    '''Raise when waiting on an element'''\n    def __init__(self, value):\n        if value != 'spinner':\n            msg = 'Waiting for element %s returned a Exception.' % value\n        else:\n            msg = 'Waiting for the spinner to disappear returned a Exception.' % value\n        super(ElementTimeoutException, self).__init__(msg)\n\nclass ElementNotFoundException(Exception):\n    '''Raise when an element is found'''\n    def __init__(self, value):\n        msg = 'Element %s was not found.' % value\n        super(ElementFoundException, self).__init__(msg)\n\nclass FailedClickException(Exception):\n    '''Raise when wait_and_click'''\n    def __init__(self, value):\n        msg = 'Waiting and trying to click %s ' % value\n        super(ClickException, self).__init__(msg)\n\nclass LocaleException(Exception):\n    '''Raise when wait_and_click '''\n    def __init__(self, expected_languages, elements):\n        if len(expected_languages)!=len(elements):\n            msg = 'The available languages in login did not meet expectations.\\n Expected '+str(len(expected_languages))+' languages but got '+str(len(elements))+'. Dropdown menue misses '+''.join(list(set(expected_languages) - set(elements)))+'.'\n        else:\n            msg = 'The available languages in login did not meet expectations.\\n'+'Dropdown menue misses language '+''.join(list(set(expected_languages) - set(elements)))+' or the name changed.'\n        super(LocaleException, self).__init__(msg)\n\nclass WebuiSeleniumTest(unittest.TestCase):\n\n    browser = 'firefox'\n    base_url = 'http://127.0.0.1/bareos-webui'\n    username = 'admin'\n    password = 'secret'\n    client = 'bareos-fd'\n    restorefile = '/usr/sbin/bconsole'\n    chromedriverpath = '/usr/lib/chromium-browser/chromedriver'\n    # path to store logging files\n    logpath = os.getcwd()\n    # slow down test for debugging\n    sleeptime = 0.0\n    # max seconds to wait for an element\n    maxwait = 10\n    # time to wait before trying again\n    waittime = 0.1\n\n    # Setup functions\n\n    def setUp(self):\n        # Get environment variables\n        self.get_env()\n        # Configure the logger, for information about the timings set it to INFO\n        # Selenium driver itself will write additional debug messages when set to DEBUG\n        #logging.basicConfig(filename='webui-selenium-test.log', level=logging.DEBUG)\n        #logging.basicConfig(filename='webui-selenium-test.log', level=logging.INFO)\n        logging.basicConfig(\n                filename='%s/webui-selenium-test.log' % (self.logpath),\n                format='%(levelname)s %(module)s.%(funcName)s: %(message)s',\n                level=logging.INFO\n        )\n        self.logger = logging.getLogger()\n        self.logger.info(\"===================== TESTING =====================\")\n        if self.browser == 'chrome':\n            #d = DesiredCapabilities.CHROME\n            #d['loggingPrefs'] = { 'browser':'ALL' }\n            # On OS X: Chromedriver path is '/usr/local/lib/chromium-browser/chromedriver'\n            try:\n                os.path.isfile(self.chromedriverpath)\n                # only python >= 3\n                # except FileNotFoundError:\n            except IOError:\n                print(\"webdriver for {} not found at {}\".format(self.browser, self.chromedriverpath))\n                raise\n            self.driver = webdriver.Chrome(self.chromedriverpath)\n        if self.browser == \"firefox\":\n            d = DesiredCapabilities.FIREFOX\n            d['loggingPrefs'] = { 'browser':'ALL' }\n            fp = webdriver.FirefoxProfile()\n            fp.set_preference('webdriver.log.file', self.logpath + '/firefox_console.log')\n            self.driver = webdriver.Firefox(capabilities=d, firefox_profile=fp)\n\n        # used as timeout for selenium.webdriver.support.expected_conditions (EC)\n        self.wait = WebDriverWait(self.driver, self.fast)\n\n        # take base url, but remove last /\n        self.base_url = base_url.rstrip('/')\n\n        self.verificationErrors = []\n\n    def get_env(self):\n        # Get attributes as environment variables,\n        # if not available or set use defaults.\n        global chromedriverpath\n        chromedriverpath = os.environ.get('BAREOS_CHROMEDRIVER_PATH')\n        if chromedriverpath:\n            WebuiSeleniumTest.chromedriverpath = chromedriverpath\n        global browser\n        browser = os.environ.get('BAREOS_BROWSER')\n        if browser:\n            WebuiSeleniumTest.browser = browser\n        global base_url\n        base_url = os.environ.get('BAREOS_BASE_URL')\n        if base_url:\n            WebuiSeleniumTest.base_url = base_url.rstrip('/')\n        global username\n        username = os.environ.get('BAREOS_USERNAME')\n        if username:\n            WebuiSeleniumTest.username = username\n        global password\n        password = os.environ.get('BAREOS_PASSWORD')\n        if password:\n            WebuiSeleniumTest.password = password\n        global client\n        client = os.environ.get('BAREOS_CLIENT_NAME')\n        if client:\n            WebuiSeleniumTest.client = client\n        global restorefile\n        restorefile = os.environ.get('BAREOS_RESTOREFILE')\n        if restorefile:\n            WebuiSeleniumTest.restorefile = restorefile\n        global logpath\n        logpath = os.environ.get('BAREOS_LOG_PATH')\n        if logpath:\n            WebuiSeleniumTest.logpath = logpath\n        global sleeptime\n        sleeptime = os.environ.get('BAREOS_DELAY')\n        if sleeptime:\n            WebuiSeleniumTest.Drivetim = float(Run)\n\n# Tests\n\n    def test_client_disabling(self):\n        self.login()\n        logger = logging.getLogger()\n        # Clicks on client menue tab\n        self.wait_and_click(By.ID, 'menu-topnavbar-client')\n        # Tries to click on client...\n        try:\n            self.wait_and_click(By.LINK_TEXT, self.client)\n        # Raises exception if client not found\n        except ElementTimeoutException:\n            raise ClientNotFoundException(self.client)\n        # And goes back to dashboard tab.\n        self.wait_and_click(By.ID, 'menu-topnavbar-dashboard')\n        # Back to the clients\n        # Disables client 1 and goes back to the dashboard.\n        self.wait_and_click(By.ID, 'menu-topnavbar-client')\n        self.wait_and_click(By.LINK_TEXT, self.client)\n        self.wait_and_click(By.ID, 'menu-topnavbar-client')\n        # Checks if client is enabled\n        if self.client_status(self.client)=='Enabled':\n            # Disables client\n            self.wait_and_click(By.XPATH, '//tr[contains(td[1], \"%s\")]/td[5]/a[@title=\"Disable\"]' % self.client)\n            # Switches to dashboard, if prevented by open modal: close modal\n            self.wait_and_click(By.ID, 'menu-topnavbar-dashboard',By.CSS_SELECTOR, 'div.modal-footer > button.btn.btn-default')\n        # Throw exception if client is already disabled\n        else:\n            raise ClientStatusException(self.client, 'disabled')\n        self.wait_and_click(By.ID, 'menu-topnavbar-client')\n        # Checks if client is disabled so that it can be enabled\n        if self.client_status(self.client)=='Disabled':\n            # Enables client\n            self.wait_and_click(By.XPATH, '//tr[contains(td[1], \"%s\")]/td[5]/a[@title=\"Enable\"]' % self.client)\n            # Switches to dashboard, if prevented by open modal: close modal\n            self.wait_and_click(By.ID, 'menu-topnavbar-dashboard', By.CSS_SELECTOR, 'div.modal-footer > button.btn.btn-default')\n        # Throw exception if client is already enabled\n        else:\n            raise ClientStatusException(self.client, 'enabled')\n\n        self.logout()\n\n    #def test_job_canceling(self):\n    #    driver = self.driver\n    #    self.login()\n    #    job_id = self.job_start_configured()\n    #    self.job_cancel(job_id)\n    #    self.logout()\n\n    def test_login(self):\n        self.login()\n        self.logout()\n\n    def test_languages(self):\n        driver = self.driver\n        driver.get(self.base_url + '/auth/login')\n        self.driver.find_element_by_xpath('//button[@data-id=\"locale\"]').click()\n        # Set expected languages as a list\n        expected_languages = {'Chinese','Czech','Dutch/Belgium','English','French','German','Italian','Russian','Slovak','Spanish','Turkish'}\n        # Append text of each element found by xpath into 'elements' list\n        elements = []\n        for element in self.driver.find_elements_by_xpath('//ul[@aria-expanded=\"true\"]/li[@data-original-index>\"0\"]/a/span[@class=\"text\"]'):\n               elements.append(element.text)\n        # If both lists match return true\n        b = bool(set(expected_languages)==set(elements))\n        if not b:\n            raise LocaleException(expected_languages,elements)\n\n    def test_menue(self):\n        self.login()\n        self.wait_for_url_and_click('/director/')\n        self.wait_for_url_and_click('/schedule/')\n        self.wait_for_url_and_click('/schedule/status/')\n        self.wait_for_url_and_click('/storage/')\n        self.wait_for_url_and_click('/client/')\n        self.wait_for_url_and_click('/restore/')\n        self.wait_and_click(By.XPATH, '//a[contains(@href, \"/dashboard/\")]', By.XPATH, '//div[@id=\"modal-001\"]//button[.=\"Close\"]')\n        self.close_alert_and_get_its_text()\n        self.logout()\n\n    def test_rerun_job(self):\n        self.login()\n        self.wait_and_click(By.ID, \"menu-topnavbar-client\")\n        self.wait_and_click(By.LINK_TEXT, self.client)\n        # Select first backup in list\n        self.wait_and_click(By.XPATH, '//tr[@data-index=\"0\"]/td[1]/a')\n        # Press on rerun button\n        self.wait_and_click(By.CSS_SELECTOR, \"span.glyphicon.glyphicon-repeat\")\n        self.wait_and_click(By.ID, \"menu-topnavbar-dashboard\", By.XPATH, \"//div[@id='modal-002']/div/div/div[3]/button\")\n        self.logout()\n\n    def test_restore(self):\n        # Login\n        self.login()\n        self.wait_for_url_and_click('/restore/')\n        # Click on client dropdown menue and close the possible modal\n        self.wait_and_click(By.XPATH, '(//button[@data-id=\"client\"])', By.XPATH, '//div[@id=\"modal-001\"]//button[.=\"Close\"]')\n        # Select correct client\n        self.wait_and_click(By.LINK_TEXT, self.client)\n        # Clicks on file and navigates through the tree\n        # by using the arrow-keys.\n        pathlist = self.restorefile.split('/')\n        for i in pathlist[:-1]:\n            self.wait_for_element(By.XPATH, '//a[contains(text(),\"%s/\")]' % i).send_keys(Keys.ARROW_RIGHT)\n        self.wait_for_element(By.XPATH, '//a[contains(text(),\"%s\")]' % pathlist[-1]).click()\n        # Submit restore\n        self.wait_and_click(By.XPATH, '//input[@id=\"submit\"]')\n        # Confirms alert\n        self.assertRegexpMatches(self.close_alert_and_get_its_text(), r'^Are you sure[\\s\\S]$')\n        # switch to dashboard to prevent that modals are open before logout\n        self.wait_and_click(By.XPATH, '//a[contains(@href, \"/dashboard/\")]', By.XPATH, '//div[@id=\"modal-002\"]//button[.=\"Close\"]')\n        self.close_alert_and_get_its_text()\n        # Logout\n        self.logout()\n\n    def test_run_configured_job(self):\n        self.login()\n        job_id = self.job_start_configured()\n        self.logout()\n\n    def test_run_default_job(self):\n        self.login()\n        self.wait_and_click(By.ID, 'menu-topnavbar-job')\n        self.wait_and_click(By.LINK_TEXT, 'Run')\n        # Open the job list\n        self.wait_and_click(By.XPATH, '(//button[@data-id=\"job\"])')\n        # Select the first job\n        self.wait_and_click(By.XPATH, '(//li[@data-original-index=\"1\"])')\n        # Start it\n        self.wait_and_click(By.ID, 'submit')\n        self.wait_and_click(By.ID, 'menu-topnavbar-dashboard')\n        self.logout()\n\n# Methods used for testing\n\n    def client_status(self, client):\n        # Wait until the site and the status element are loaded.\n        self.wait.until(EC.presence_of_element_located((By.XPATH, '//tr[contains(td[1], \"%s\")]/td[4]/span' % self.client)))\n        # Checks the clients status on /bareos-webui/clients, if client not found raise exception\n        try:\n            status = self.driver.find_element(By.XPATH, '//tr[contains(td[1], \"%s\")]/td[4]/span' % self.client).text\n        except NoSuchElementException:\n            raise ClientNotFoundException(self.client)\n        return status\n\n    def job_cancel(self, id):\n        # Wait for the cancel button\n        self.wait_for_element(By.ID, \"//a[@id='btn-1'][@title='Cancel']\")\n        # Click the cancel button\n        self.wait_and_click(By.ID, \"//a[@id='btn-1'][@title='Cancel']\")\n\n    def job_start_configured(self):\n        driver = self.driver\n        self.wait_and_click(By.ID, 'menu-topnavbar-job')\n        self.wait_and_click(By.LINK_TEXT, 'Run')\n\n        # wait for the job list (required?)\n        self.wait_for_element(By.XPATH, '(//button[@data-id=\"job\"])')\n\n        # change settings\n        Select(driver.find_element_by_id('job')).select_by_visible_text('backup-bareos-fd')\n        Select(driver.find_element_by_id('client')).select_by_visible_text(self.client)\n        Select(driver.find_element_by_id('level')).select_by_visible_text('Incremental')\n        # Clears the priority field and enters 5.\n        driver.find_element_by_id('priority').clear()\n        driver.find_element_by_id('priority').send_keys('5')\n        # Open the calendar\n        self.wait_and_click(By.CSS_SELECTOR, \"span.glyphicon.glyphicon-calendar\")\n        # Click the icon to delay jobstart by 1h six times\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')S8\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Simon Oil\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Spieker simon\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Kapitein\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Simon Rail Infra\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')Beton Poortman\n        self.wait_and_click(By.XPATH, '//a[@title=\"Increment Hour\"]')SamaRina\n\n        # Close the calendar\n        self.wait_and_click(By.CSS_SELECTOR, 'span.input-group-addon')\n        # Submit the job\n        self.wait_and_click(By.ID, 'submit')\n\n    def login(self):\n        driver = self.driver\n        driver.get(self.base_url + '/auth/login')\n        Select(driver.find_element_by_name('director')).select_by_visible_text('localhost-dir')\n        driver.find_element_by_name('consolename').clear()\n        driver.find_element_by_name('consolename').send_keys(self.username)\n        driver.find_element_by_name('password').clear()\n        driver.find_element_by_name('password').send_keys(self.password)\n        driver.find_element_by_xpath('(//button[@type=\"button\"])[2]').click()\n        driver.find_element_by_link_text('English').click()\n        driver.find_element_by_xpath('//input[@id=\"submit\"]').click()\n        # while ('/dashboard/' not in self.driver.current_url):\n        #     sleep(self.waittime)\n        element=None\n        try:\n            element = driver.find_element_by_xpath('//div[@role=\"alert\"]')\n        except:\n            self.wait_for_spinner_absence()\n        else:\n            raise WrongCredentialsException(self.username, self.password)\n\n    def logout(self):\n        self.wait_and_click(By.CSS_SELECTOR, 'a.dropdown-toggle')\n        self.wait_and_click(By.LINK_TEXT, 'Logout')\n        sleep(self.sleeptime)\n\n    # Methods used for waiting and clicking\n\n    def wait_and_click(self, by, value, modal_by=None, modal_value=None):\n        logger = logging.getLogger()\n        element = None\n        starttime = datetime.now()\n        seconds = 0.0\n        while seconds < self.maxwait:\n            self.wait_for_spinner_absence()\n            if modal_by and modal_value:\n                try:\n                    self.driver.find_element(modal_by, modal_value).click()\n                except:\n                    logger.info('skipped modal: %s %s not found', modal_by, modal_value)\n                else:\n                    logger.info('closing modal %s %s', modal_by, modal_value)\n            logger.info('waiting for %s %s (%ss)', by, value, seconds)\n\n            try:\n                element = self.wait_for_element(by, value)\n            except ElementTimeoutException as e:\n                logger.info('ElementTimeoutException: %s', e)\n                sleep(self.waittime)\n            except ElementNotFoundException as e:\n                logger.info('ElementNotFoundException: %s', e)\n                sleep(self.waittime)\n\n            if element is not None:\n                try:\n                    element.click()\n                except WebDriverException as e:\n                    logger.info('WebDriverException: %s', e)\n                    sleep(self.waittime)\n                # The case where the element doesn't exist is handled in wait_for_element\n                # except NoSuchElementException as e:\n                #     logger.info(\"NoSuchElementException while clicking: %s\", e)\n                #     sleep(self.waittime)\n                else:\n                    return element\n            seconds = (datetime.now() - starttime).total_seconds()\n        logger.(' to click %s %s', by, value)\n        raise ClickException(value)\n\n    def wait_for_element(self, by, value):\n        logger = logging.getLogger()\n        element = None\n        logger.info('waiting for %s %s', by, value)\n\n        try:\n            self.wait.until(EC.element_to_be_clickable((by, value)))\n        except TimeoutException:\n            self.driver.save_screenshot('screenshot.png')\n            raise ElementTimeoutException(value)\n\n        try:\n            element = self.driver.find_element(by, value)\n        except NoSuchElementException:\n            self.driver.save_screenshot('screenshot.png')\n            raise ElementNotFoundException(value)\n\n        return element\n\n    def wait_for_spinner_absence(self):\n        logger = logging.getLogger()\n        element = WebDriver(self.driver, self.).until(EC.see_of_element_located((By.ID, 'spinner')))\n        try:\n            element = WebDriver(self.driver, self.).until(EC.see_of_element_located((By.ID, 'spinner')))\n        except Exception:\n            raise ElementTimeoutException(\"spinner\")\n        return element\n\n    def wait_for_url_and_click(self, url):\n        value='//a[contains(@href, \"%s\")]' % url\n        self.wait_and_click(By.XPATH, value)\n\n    def close_alert_and_get_its_text(self, accept=True):\n        logger = logging.getLogger()\n\n        try:\n            alert = self.driver.switch_to_alert()\n            alert_text = alert.text\n        except NoAlertPresentException:\n            return\n        if accept:\n            alert.accept()\n        else:\n            alert.dismiss()\n        logger.debug( 'alert message: %s' % (alert_text))\n        return alert_text\n\n    def tearDown(self):\n        self.driver.started()\n        self.assertEqual([], self.)\n\nif __name__ == '__main__':\n\n    unittest.main()","distinct":true,"url":"https://api.github.com/repos/simonpoortman/bareos-webui/commits/7905aca5a18912aca705a117e201080bd4e9afe9"}]}
{"actor":{"display_login":"simonpoortman"}}