def before_all(context): """ Before all hook. Set config variables for whole run, setup logging, init allure. context.config.userdata is a dict with values from behave commandline. Example: -D foo=bar will store value in config.userdata['foo']. Will be executed once at the beginning of the test run. Context injected automatically by Behave. :type context: behave.runner.Context """ if context.config.userdata: Config.BROWSER = context.config.userdata.get('browser', Config.BROWSER).lower() Config.APP_URL = context.config.userdata.get('url', Config.APP_URL).lower() Config.REUSE = context.config.userdata.get('reuse', Config.REUSE).lower() Config.HIGHLIGHT = context.config.userdata.get( 'highlight', Config.HIGHLIGHT).lower() Logger.configure_logging() logger = logging.getLogger(__name__) allure_report_path = '{}/allure_report'.format(Config.LOG_DIR) try: context.allure = AllureImpl(allure_report_path) except Exception: logger.error('Failed to init allure at: {}'.format(allure_report_path)) raise
def before_all(context): """ Before all hook. Set config variables for whole run, setup logging, init allure. context.config.userdata is a dict with values from behave commandline. Example: -D foo=bar will store value in config.userdata['foo']. Will be executed once at the beginning of the test run. Context injected automatically by Behave. :type context: behave.runner.Context """ if context.config.userdata: Config.BROWSER = context.config.userdata.get('browser', Config.BROWSER).lower() Config.APP_URL = context.config.userdata.get('url', Config.APP_URL).lower() Config.REUSE = context.config.userdata.get('reuse', Config.REUSE).lower() Config.HIGHLIGHT = context.config.userdata.get('highlight', Config.HIGHLIGHT).lower() Logger.configure_logging() logger = logging.getLogger(__name__) allure_report_path = '{}/allure_report'.format(Config.LOG_DIR) try: context.allure = AllureImpl(allure_report_path) except Exception: logger.error('Failed to init allure at: {}'.format(allure_report_path)) raise
def before_all(context): if context.config.userdata: Config.BROWSER = context.config.userdata.get('browser', Config.BROWSER).lower() Config.APP_URL = context.config.userdata.get('url', Config.APP_URL).lower() Config.REUSE = context.config.userdata.get('reuse', Config.REUSE).lower() Config.HIGHLIGHT = context.config.userdata.get( 'highlight', Config.HIGHLIGHT).lower() Logger.configure_logging() logger = logging.getLogger(__name__)
def before_all(context): """ Before all hook. Set config variables for whole run, setup logging. context.config.userdata is a dict with values from behave commandline. Example: -D foo=bar will store value in config.userdata['foo']. Will be executed once at the beginning of the test run. Context injected automatically by Behave. :type context: behave.runner.Context """ Logger.configure_logging() logger = logging.getLogger(__name__) if context.config.userdata: Config.ENV = context.config.userdata.get('env', Config.ENV) Config.REUSE = context.config.userdata.get('reuse', Config.REUSE) Config.HIGHLIGHT = context.config.userdata.get('highlight', Config.HIGHLIGHT) Config.BROWSERTYPE = context.config.userdata.get( 'browsertype', Config.BROWSERTYPE) Config.PLATFORM = context.config.userdata.get('osplatform', Config.PLATFORM) Config.BROWSERNAME = context.config.userdata.get( 'browsername', Config.BROWSERNAME) Config.VERSION = context.config.userdata.get('browserver', Config.VERSION) context.lt_username = context.config.userdata.get( 'lt_username', "ERROR_LT_USERNAME") context.lt_access_key = context.config.userdata.get( 'lt_access_key', "ERROR_LT_ACCESS_KEY") context.lt_tunnel = context.config.userdata.get( 'lt_tunnel', "ERROR_LT_TUNNEL") context.build = context.config.userdata.get('build_id', "ERROR_BUILD_ID") context.run_mode = context.config.userdata.get('behave_run_mode', "ERROR_RUN_MODE") # pid from parallel_runner if platform.system() == 'Windows': # On Win: pool_process -> cmd (call function) -> behave -> python -> before_all (hook) parent_runner_pid = Process( Process(Process(Process( os.getpid()).ppid()).ppid()).ppid()).ppid() elif platform.system() == 'Linux': # On Lin: pool_process -> behave -> before_all (hook) parent_runner_pid = Process(Process(os.getpid()).ppid()).ppid() elif platform.system() == 'Darwin': # On Darwin: pool_process -> behave -> before_all (hook) parent_runner_pid = Process(Process(os.getpid()).ppid()).ppid() logger.info("parent pid: " + str(parent_runner_pid)) if context.run_mode == 'Multithreaded' and os.path.exists( "pid_" + str(parent_runner_pid) + ".db"): with open("pid_" + str(parent_runner_pid) + ".db", "r") as context_file: content = context_file.read() variables = re.findall(r"<var_beg>(.+?)<var_end>", content) for var in variables: if "project_db" in var: context.project_db = json.loads( var.replace("project_db=", '').replace("'", '"')) else: context.project_db = json.loads(Config.PROJECT_DB.replace("'", '"'))