def get_saucelabs_connect(config=None, config_path=None, update=False): ''' Downloads saucelabs connect binary into **config.saucelabs.connect.path** :param pymlconf.ConfigManager config: configuration object :param str config_path: path to config :param bool update: - (optional) if True overwrites exisiting binary ''' if not config: if config_path: config = get_config(config_path) else: logger.error('No config provided!') return sauce_config = config.saucelabs if not update and os.path.isdir(sauce_config.connect.path): logger.debug('%s already exists' % sauce_config.connect.path) else: logger.info('Downloading %s' % sauce_config.connect.url) download_and_extract( url=sauce_config.connect.url, path=sauce_config.connect.path ) logger.info('Downloaded') return os.path.abspath(sauce_config.connect.path)
def run_tests(config_path): ''' Runs test suite based on configuration passed :param str config_path: path to yaml config file ''' config = get_config(config_path) if config.type == 'saucelabs': logger.info('testing on saucelabs') credentials_yaml = config.saucelabs.get('yaml', config_path) return test_saucelabs(config, credentials_yaml) if config.type == 'selenium': logger.info('testing on selenium') return test_selenium(config) return test_unit(config)
def run_saucelabs(config_path): ''' Runs saucelabs (by setting up tunnel via saucelabs connect) ''' config = get_config(config_path) sauce_connect_path = get_saucelabs_connect(config) + '/bin/sc' command = [sauce_connect_path, '--verbose', '-u', config.get('username'), '-k', config.get('api-key')] pytest_proc = Popen(' '.join(command), shell=True) try: pytest_proc.communicate() except KeyboardInterrupt: pytest_proc.kill() if pytest_proc.returncode != 0: return pytest_proc.returncode return 0
def get_chromedriver(config=None, config_path=None, update=False): ''' Downloads chromedriver binary into **config.selenium.chromedriver.file** path :param pymlconf.ConfigManager config: configuration object :param update: - (optional) if True overwrites existing binary ''' if not config: if config_path: config = get_config(config_path) else: logger.error('No config provided!') return chromedriver_config = config.selenium.chromedriver if not update and os.path.isfile(chromedriver_config.file): logger.debug('%s already exists' % chromedriver_config.file) else: url = None if platform.system() in ('Windows', ): url = chromedriver_config.url + chromedriver_config.zips['win'] elif platform.system() in ('Mac', 'Darwin'): url = chromedriver_config.url + chromedriver_config.zips['mac'] elif platform.system() in ('Linux'): if platform.architecture()[0] == '32bit': url = chromedriver_config.url +\ chromedriver_config.zips['linux32'] if platform.architecture()[0] == '64bit': url = chromedriver_config.url +\ chromedriver_config.zips['linux64'] if not url: raise Exception('Architecture is not detected') logger.info('Downloading %s' % url) download_and_unzip(url, 'chromedriver', chromedriver_config.file) logger.info('Downloaded') return os.path.abspath(chromedriver_config.file)