#!/usr/bin/python import selenium import selenium.webdriver import time import sys class SeleniumUMC: def __init__(self, url, username=None, password=None): self.url = url self.username = username if username else 'Administrator' self.password = password if password else 'univention' def wait_for_func(self, timeout, func, *args): success = False timeout = time.time() + timeout while not success: try: return func(*args) success = True except (selenium.common.exceptions.ElementNotVisibleException, selenium.common.exceptions.NoSuchFrameException): if time.time() > timeout: raise else: time.sleep(0.1) def setup(self): self.browser = selenium.webdriver.Firefox() def shutdown(self): self.browser.close() def run_all_tests(self): for func in [ x for x in dir(self) if x.startswith('test_') ]: self.setup() getattr(self, func)() time.sleep(10) self.shutdown() def perform_umc_login(self): self.browser.get(self.url) self.wait_for_func(10, self.browser.switch_to_frame, "umc_LoginDialog_Iframe") elem = self.browser.find_element_by_name("username") self.wait_for_func(10, elem.send_keys, self.username) elem = self.browser.find_element_by_name("password") elem.send_keys(self.password) self.browser.find_element_by_id("umc_SubmitButton_label").click() time.sleep(3) self.browser.switch_to_default_content() class SeleniumAppCenterOX(SeleniumUMC): def test_open_ox_in_appcenter(self): self.perform_umc_login() time.sleep(3) elem = self.wait_for_func(10, self.browser.find_element_by_class_name, 'umcAppCenter-icon50-apps-oxseforucs') elem.click() x = SeleniumAppCenterOX('http://10.200.18.35/univention-management-console/?module=appcenter') x.run_all_tests() sys.exit(0)