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 test_selenium(config): ''' runs selenium test based on config ''' if not config['browsers']: logger.info('No browsers defined!') return for browser in config['browsers']: logger.info('testing %s browser' % browser['browsername']) call_arguments = ['py.test'] +\ map_presets_to_cmd(browser) if browser['browsername'] == 'chrome': call_arguments += map_presets_to_cmd({ 'chromepath': get_chromedriver(config) }) if config.selenium.xvfb: xfvb_args = map_presets_to_cmd(config.selenium.xvfb.options) xfvb_args.insert(0, 'xvfb-run') call_arguments = xfvb_args + call_arguments code = run(call_arguments, config) if code != 0: break return code
def test_unit(config): ''' runs unit or integration tests based on config ''' logger.info('Running pytest tests without selenium') call_arguments = ['py.test', '-p no:pytest_mozwebqa'] return run(call_arguments, config)
def run(command, config): '''joins list of run arguments and runs them''' arguments = read_run_arguments(config) arguments.append(os.path.abspath(config.testpath)) command_to_run = ' '.join(command + arguments) logger.info(command_to_run) pytest_proc = Popen(command_to_run, cwd=(os.path.abspath(config.testpath)), shell=True) try: pytest_proc.communicate() except KeyboardInterrupt: pytest_proc.kill() return pytest_proc.returncode
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 test_saucelabs(config, credentials_yaml): ''' runs selenium test based on config ''' if not config['browsers']: logger.warning('No browsers defined!') return for browser in config['browsers']: logger.info('testing %s browser' % browser['browsername']) call_arguments = ['py.test', '--saucelabs=%s' % (os.path.abspath(credentials_yaml)) ] + map_presets_to_cmd(browser) code = run(call_arguments, config) if code != 0: break return code
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)