def test_choose_browser_by_precedence(self): selected = utils.choose_browser_by_precedence(cli_browsers=['a', 'b'], suite_browsers=['c', 'd'], settings_default_browser='default') assert selected == ['a', 'b'] selected = utils.choose_browser_by_precedence(cli_browsers=[], suite_browsers=['c', 'd'], settings_default_browser='default') assert selected == ['c', 'd'] selected = utils.choose_browser_by_precedence(cli_browsers=[], suite_browsers=[], settings_default_browser='default') assert selected == ['default'] selected = utils.choose_browser_by_precedence(cli_browsers=[], suite_browsers=[], settings_default_browser=None) assert selected == ['chrome']
def interactive(settings, cli_browsers): """Starts the Golem interactive shell.""" browsers = utils.choose_browser_by_precedence( cli_browsers=cli_browsers, suite_browsers=[], settings_default_browser=settings['default_browser']) execution.browser_name = browsers[0] remote_browsers = settings_manager.get_remote_browsers(session.settings) default_browsers = gui_utils.get_supported_browsers_suggestions() browser_defs = define_browsers(browsers, remote_browsers, default_browsers) execution.browser_definition = browser_defs[0] execution.settings = settings execution.settings['interactive'] = True execution.logger = execution_logger.get_logger( console_log_level=execution.settings['console_log_level'], log_all_events=execution.settings['log_all_events']) actions.interactive_mode()
def _prepare(self): # Generate timestamp if needed. # A timestamp is passed when the test is executed from the GUI. # The gui uses this timestamp to fetch the test execution status later on. # Otherwise, a new timestamp should be generated at this point. if not self.timestamp: self.timestamp = utils.get_timestamp() # create the execution report directory # if this is a suite, the directory takes this structure: # reports/<suite_name>/<timestamp>/ # # if this is a single test, the directory takes this structure: # reports/single_tests/<test_name>/<timestamp>/ self.execution.reportdir = self._create_execution_directory() # Filter tests by tags self.execution.tags = self.cli_args.tags or self.suite.tags or [] if self.execution.tags: self.tests = self._filter_tests_by_tags() if not self.tests: self._finalize() else: # get amount of processes (parallel executions), default is 1 if self.cli_args.processes > 1: # the processes arg passed through cli has higher priority self.execution.processes = self.cli_args.processes elif self.suite.processes: self.execution.processes = self.suite.processes # select the browsers to use in this execution # the order of precedence is: # 1. browsers defined by CLI # 2. browsers defined inside a suite # 3. 'default_browser' setting key # 4. default default is 'chrome' self.selected_browsers = utils.choose_browser_by_precedence( cli_browsers=self.cli_args.browsers, suite_browsers=self.suite.browsers, settings_default_browser=session.settings['default_browser']) # Define the attributes for each browser. # A browser name can be predefined ('chrome, 'chrome-headless', 'firefox', etc) # or it can be defined by the user with the 'remote_browsers' setting. # Remote browsers have extra details such as capabilities # # Each defined browser must have the following attributes: # 'name': real name, # 'full_name': the remote_browser name defined by the user, # 'remote': is this a remote_browser or not # 'capabilities': full capabilities defined in the remote_browsers setting remote_browsers = settings_manager.get_remote_browsers(session.settings) default_browsers = gui_utils.get_supported_browsers_suggestions() self.execution.browsers = define_browsers(self.selected_browsers, remote_browsers, default_browsers) # Select which environments to use # The user can define environments in the environments.json file. # The suite/test can be executed in one or more of these environments. # Which environments will be used is defined by this order of preference: # 1. envs passed by CLI # 2. envs defined inside the suite # 3. The first env defined for the project # 4. no envs at all # # Note, in the case of 4, the test might fail if it tries # to use env variables project_envs = environment_manager.get_envs(self.project) self.execution.envs = self._select_environments(project_envs) invalid_envs = [e for e in self.execution.envs if e not in project_envs] if invalid_envs: print('ERROR: the following environments do not exist for project {}: {}' .format(self.project, ', '.join(invalid_envs))) self.execution.has_failed_tests.value = True self._finalize() return # Generate the execution list # Each test must be executed for each: # * data set # * environment # * browser # The result is a list that contains all the requested combinations self.execution.tests = self._define_execution_list() self._print_number_of_tests_found() # for each test, create the test report directory # for example, in a suite 'suite1' with a 'test1': # reports/suite1/2017.07.02.19.22.20.001/test1/set_00001/ for test in self.execution.tests: test.reportdir = report.create_report_directory(self.execution.reportdir, test.name, self.is_suite) try: self._execute() except KeyboardInterrupt: self.execution.has_failed_tests.value = True self._finalize()