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_scenario(context, scenario): """ Before scenario hook. Create folder for screenshot, open browser, set Full HD resolution and place browser in test context. Also start allure test case. Will be executed in the beginning of every scenario in .feature file. Context and scenario injected automatically by Behave :type context: behave.runner.Context :type scenario: behave.model.Scenario """ Logger.create_test_folder(scenario.name) logger = logging.getLogger(__name__) try: context.allure.start_case(scenario.name, labels=LabelsList([ TestLabel(name=Label.FEATURE, value=scenario.feature.name) ])) except Exception: logger.error('Failed to init allure test with name: {}'.format( scenario.name)) raise context.test_name = scenario.name if context.browser is None: try: # use in constructor service_args=['--webdriver-logfile=path_to_log'] to debug deeper... context.browser = Config.browser_types[Config.BROWSER]() context.browser.set_window_size(1920, 1080) except Exception: logger.error('Failed to start browser: {}'.format(Config.BROWSER)) raise logger.info('Start of test: {}'.format(scenario.name))
def before_scenario(context, scenario): """ Before scenario hook. Create folder for screenshot, open browser, set Full HD resolution and place browser in test context. Also start allure test case. Will be executed in the beginning of every scenario in .feature file. Context and scenario injected automatically by Behave :type context: behave.runner.Context :type scenario: behave.model.Scenario """ Logger.create_test_folder(scenario.name) logger = logging.getLogger(__name__) try: context.allure.start_case(scenario.name, labels=LabelsList([TestLabel(name=Label.FEATURE, value=scenario.feature.name)])) except Exception: logger.error('Failed to init allure test with name: {}'.format(scenario.name)) raise context.test_name = scenario.name if context.browser is None: try: # use in constructor service_args=['--webdriver-logfile=path_to_log'] to debug deeper... context.browser = DriverManger.getDriver() # context.browser.set_window_size(1920, 1080) except Exception: logger.error('Failed to start browser: {}'.format(Config.BROWSER)) raise logger.info('Start of test: {}'.format(scenario.name))
def before_scenario(context, scenario): """ Before scenario hook. Create folder for screenshot, open browser, set Full HD resolution and place browser in test context. Will be executed in the beginning of every scenario in .feature file. Context and scenario injected automatically by Behave :type context: behave.runner.Context :type scenario: behave.model.Scenario """ Logger.create_test_folder(scenario.name) logger = logging.getLogger(__name__) if context.browser is None: try: if Config.BROWSERTYPE == 'Local': if Config.BROWSERNAME == 'Chrome': context.browser = Config.browser_types[Config.BROWSERNAME]( chrome_options=Config.CHROME_OPTIONS) context.browser.set_window_size(1920, 1080) if Config.BROWSERNAME == 'Firefox': context.browser = Config.browser_types[ Config.BROWSERNAME]() context.browser.set_window_size(1920, 1080) if Config.BROWSERNAME == 'Edge': context.browser = Config.browser_types[ Config.BROWSERNAME]() context.browser.set_window_size(1920, 1080) elif Config.BROWSERTYPE == 'Remote': url = "https://" + context.lt_username + ":" + context.lt_access_key + "@hub.lambdatest.com/wd/hub" desired_cap = { "platform": Config.PLATFORM, "browserName": Config.BROWSERNAME, "version": Config.VERSION, "resolution": "1920x1080", "name": scenario.name, "build": context.build, "tunnel": True, "tunnelName": context.lt_tunnel, "console": True, "network": False, "visual": True } context.browser = Config.browser_types[Config.BROWSERTYPE]( desired_capabilities=desired_cap, command_executor=url) else: print('Wrong type of browser') except Exception: logger.error('Failed to start browser: {}'.format( Config.BROWSERNAME)) raise logger.info('Start of test: {}'.format(scenario.name))
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_scenario(context, scenario): Logger.create_test_folder(scenario.name) logger = logging.getLogger(__name__) context.test_name = scenario.name if context.browser is None: try: # use in constructor service_args=['--webdriver-logfile=path_to_log'] to debug deeper... context.browser = Config.browser_types[Config.BROWSER]() context.browser.set_window_size(1920, 1080) except Exception: logger.error('Failed to start browser: {}'.format(Config.BROWSER)) raise logger.info('Start of test: {}'.format(scenario.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("'", '"'))