def step_then_following_active_tags_combinations_are_enabled(context): assert context.table, "REQUIRE: table" assert context.active_value_provider, "REQUIRE: active_value_provider" context.table.require_columns(["tags", "enabled?"]) ignore_unknown_categories = getattr( context, "active_tags_ignore_unknown_categories", ActiveTagMatcher.ignore_unknown_categories) table = context.table annotate_column_id = 0 active_tag_matcher = ActiveTagMatcher(context.active_value_provider) active_tag_matcher.ignore_unknown_categories = ignore_unknown_categories mismatched_rows = [] for row_index, row in enumerate(table.rows): tags = normalize_tags(row["tags"].split()) expected_enabled = parse_bool(row["enabled?"]) actual_enabled = active_tag_matcher.should_run_with(tags) if actual_enabled != expected_enabled: # -- ANNOTATE MISMATCH IN EXTRA COLUMN: if annotate_column_id == 0: annotate_column_id = table.ensure_column_exists("MISMATCH!") row.cells[annotate_column_id] = "= %s" % actual_enabled mismatched_rows.append(row_index) # -- FINALLY: Ensure that there are no mismatched rows. assert_that(mismatched_rows, equal_to([]), "No mismatched rows:")
def step_then_following_active_tags_combinations_are_enabled(context): assert context.table, "REQUIRE: table" assert context.active_value_provider, "REQUIRE: active_value_provider" context.table.require_columns(["tags", "enabled?"]) ignore_unknown_categories = getattr(context, "active_tags_ignore_unknown_categories", ActiveTagMatcher.ignore_unknown_categories) table = context.table annotate_column_id = 0 active_tag_matcher = ActiveTagMatcher(context.active_value_provider) active_tag_matcher.ignore_unknown_categories = ignore_unknown_categories mismatched_rows = [] for row_index, row in enumerate(table.rows): tags = normalize_tags(row["tags"].split()) expected_enabled = parse_bool(row["enabled?"]) actual_enabled = active_tag_matcher.should_run_with(tags) if actual_enabled != expected_enabled: # -- ANNOTATE MISMATCH IN EXTRA COLUMN: if annotate_column_id == 0: annotate_column_id = table.ensure_column_exists("MISMATCH!") row.cells[annotate_column_id] = "= %s" % actual_enabled mismatched_rows.append(row_index) # -- FINALLY: Ensure that there are no mismatched rows. assert_that(mismatched_rows, equal_to([]), "No mismatched rows:")
class TestActivateTags(object): VALUE_PROVIDER = { "foo": "Frank", "bar": "Bob", # "OTHER": "VALUE", } def check_should_run_with_active_tags(self, case, expected, tags): # -- tag_matcher.should_run_with(tags).result := expected case += " (tags: {tags})" tag_matcher = ActiveTagMatcher(self.VALUE_PROVIDER) actual_result1 = tag_matcher.should_run_with(tags) actual_result2 = tag_matcher.should_exclude_with(tags) assert expected == actual_result1, case.format(tags=tags) assert (not expected) == actual_result2
"""Hooks file.""" from behave.tag_matcher import ActiveTagMatcher from ipdb import post_mortem from json import load from os import makedirs from os.path import isdir from logging import getLogger, config from {{cookiecutter.project_name}}.helpers import constants active_tag_value_provider = { "config_0": False } active_tag_matcher = ActiveTagMatcher(active_tag_value_provider) def before_all(context): userdata = context.config.userdata context.config_0 = userdata.get('config_0', 'False') context.logger = setup_logger() def before_feature(context, feature): pass def before_scenario(context, scenario): if active_tag_matcher.should_exclude_with(scenario.effective_tags): scenario.skip(reason="DISABLED ACTIVE-TAG")
def before_all(context): atexit.register(cleanup, context, True) # We set these to None explicity so that the cleanup code can run # through without error. It assumes that these fields exist. context.builder = None context.driver = None context.wm = None context.display = None context.server = None context.tunnel = None context.sc_tunnel_tempdir = None setup_screenshots(context) context.selenium_quit = os.environ.get("SELENIUM_QUIT") userdata = context.config.userdata context.builder = builder = Builder(conf_path, userdata) desired_capabilities = {} ssh_tunnel = None dump_config(builder) if userdata.get("check_selenium_config", False): exit(0) browser_to_tag_value = { "INTERNETEXPLORER": "ie", "CHROME": "ch", "FIREFOX": "ff" } values = { 'browser': browser_to_tag_value[builder.config.browser], } platform = builder.config.platform if platform.startswith("OS X "): values['platform'] = 'osx' elif platform.startswith("WINDOWS "): values['platform'] = 'win' elif platform == "LINUX" or platform.startswith("LINUX "): values['platform'] = 'linux' # We have some cases that need to match a combination of platform # and browser values['platform_browser'] = values['platform'] + "," + values['browser'] context.active_tag_matcher = ActiveTagMatcher(values) server_thread = start_server(context) if not builder.remote: visible = context.selenium_quit in ("never", "on-success") context.display = Display(visible=visible, size=(1024, 768)) context.display.start() builder.update_ff_binary_env('DISPLAY') context.wm = subprocess.Popen(["openbox", "--sm-disable"]) else: context.display = None context.wm = None ssh_tunnel = builder.WED_SSH_TUNNEL if not ssh_tunnel: sc_tunnel_id = os.environ.get("SC_TUNNEL_ID") if not sc_tunnel_id: user, key = builder.SAUCELABS_CREDENTIALS.split(":") context.tunnel, sc_tunnel_id, \ context.sc_tunnel_tempdir = \ outil.start_sc(builder.SC_TUNNEL_PATH, user, key) desired_capabilities["tunnel-identifier"] = sc_tunnel_id else: context.tunnel = \ subprocess.Popen( ["ssh", ssh_tunnel["ssh_to"], "-R", str(ssh_tunnel["ssh_port"]) + ":localhost:" + context.server_port, "-N"]) driver = builder.get_driver(desired_capabilities) context.driver = driver context.util = selenic.util.Util( driver, # Give more time if we are remote. 4 if builder.remote else 2) # Without this, window sizes vary depending on the actual browser # used. context.initial_window_size = {"width": 1020, "height": 700} context.initial_window_handle = driver.current_window_handle assert_true( driver.desired_capabilities["nativeEvents"], "Wed's test suite require that native events be available; " "you may have to use a different version of your browser, " "one for which Selenium supports native events.") behave_wait = os.environ.get("BEHAVE_WAIT_BETWEEN_STEPS") context.behave_wait = behave_wait and float(behave_wait) context.behave_captions = os.environ.get("BEHAVE_CAPTIONS") context.selenium_logs = os.environ.get("SELENIUM_LOGS", False) server_thread.join() # IE 10 has a problem with self-signed certificates. Selenium # cannot tell IE 10 to ignore these problems. Here we work around # the issue. This problem occurs only if we are using an SSH # tunnel rather than sauce connect. if ssh_tunnel and context.util.ie \ and context.builder.config.version == "10": driver.get(builder.WED_SERVER + "/blank") # Tried using, execute_script. Did not seem to work. driver.get("javascript:((link = document.getElementById(" "'overridelink')) && link.click())") context.start_time = time.time()
def before_all(context): atexit.register(cleanup, context, True) # We set these to None explicity so that the cleanup code can run # through without error. It assumes that these fields exist. context.builder = None context.driver = None context.wm = None context.display = None context.server = None context.tunnel = None context.tunnel_id = None context.selenium_quit = os.environ.get("SELENIUM_QUIT") userdata = context.config.userdata context.builder = builder = Builder(conf_path, userdata) ssh_tunnel = None dump_config(builder) setup_screenshots(context) browser_to_tag_value = { "INTERNETEXPLORER": "ie", "CHROME": "ch", "FIREFOX": "ff", "EDGE": "edge" } values = { 'browser': browser_to_tag_value[builder.config.browser], } platform = builder.config.platform if platform.startswith("OS X "): values['platform'] = 'osx' elif platform.startswith("WINDOWS "): values['platform'] = 'win' elif platform == "LINUX" or platform.startswith("LINUX "): values['platform'] = 'linux' # We have some cases that need to match a combination of platform # and browser values['platform_browser'] = values['platform'] + "," + values['browser'] context.active_tag_matcher = ActiveTagMatcher(values) server_thread = start_server(context) if not builder.remote: visible = context.selenium_quit in ("never", "on-success", "on-enter") context.display = Display(visible=visible, size=(1024, 768)) context.display.start() builder.update_ff_binary_env('DISPLAY') context.wm = subprocess.Popen(["openbox", "--sm-disable"]) else: context.display = None context.wm = None ssh_tunnel = builder.WED_SSH_TUNNEL if not ssh_tunnel: tunnel_id = os.environ.get("TUNNEL_ID") if not tunnel_id: context.tunnel_id = builder.start_tunnel() else: builder.set_tunnel_id(tunnel_id) else: context.tunnel = \ subprocess.Popen( ["ssh", ssh_tunnel["ssh_to"], "-R", str(ssh_tunnel["ssh_port"]) + ":localhost:" + context.server_port, "-N"]) behave_wait = os.environ.get("BEHAVE_WAIT_BETWEEN_STEPS") context.behave_wait = behave_wait and float(behave_wait) context.behave_captions = os.environ.get("BEHAVE_CAPTIONS") context.selenium_logs = os.environ.get("SELENIUM_LOGS", False) server_thread.join() context.start_time = time.time() context.top = Top()
def before_all(context): atexit.register(cleanup, context, True) if not hasattr(context, "step_registry"): raise Exception("you must use a test runner that exposes " "step_registry on the context object") # We need to set these to None so that cleanup does not fail. It # expects to be able to check these fields without having to check # first for their existence. context.driver = None context.wm = None context.display = None context.server = None context.server_tempdir = None context.download_dir = None context.tunnel_id = None context.tunnel = None context.builder = None context.created_documents = {} context.selenium_quit = os.environ.get("SELENIUM_QUIT") context.behave_keep_tempdirs = os.environ.get("BEHAVE_KEEP_TEMPDIRS") context.visible = os.environ.get("SELENIUM_VISIBLE") userdata = context.config.userdata context.builder = builder = Builder(conf_path, userdata) dump_config(builder) if userdata.get("check_selenium_config", False): exit(0) setup_screenshots(context) browser_to_tag_value = { "INTERNETEXPLORER": "ie", "CHROME": "ch", "FIREFOX": "ff", "EDGE": "edge" } values = { 'browser': browser_to_tag_value[builder.config.browser], } platform = builder.config.platform if platform.startswith("OS X "): values['platform'] = 'osx' elif platform.startswith("WINDOWS "): values['platform'] = 'win' elif platform == "LINUX" or platform.startswith("LINUX "): values['platform'] = 'linux' # We have some cases that need to match a combination of platform # and browser values['platform_browser'] = values['platform'] + "," + values['browser'] context.active_tag_matcher = ActiveTagMatcher(values) # Without this, window sizes vary depending on the actual browser # used. initial_window_size = context.initial_window_size = \ {"width": 1366, "height": 768} if not builder.remote: visible = context.visible or \ context.selenium_quit in ("never", "on-success", "on-enter") context.display = Display(visible=visible, size=(initial_window_size["width"], initial_window_size["height"])) context.display.start() print("Display started") builder.update_ff_binary_env('DISPLAY') context.wm = subprocess.Popen(["openbox", "--sm-disable"]) print("Window manager started") chrome_options = builder.local_conf.get("CHROME_OPTIONS", None) if chrome_options: # We set a temporary directory for Chrome downloads. Even if # we do not test downloads, this will prevent Chrome from # polluting our *real* download directory. context.download_dir = tempfile.mkdtemp() prefs = {"download.default_directory": context.download_dir} chrome_options.add_experimental_option("prefs", prefs) else: context.display = None context.wm = None tunnel_id = os.environ.get("TUNNEL_ID") if not tunnel_id: context.tunnel_id = builder.start_tunnel() else: builder.set_tunnel_id(tunnel_id) driver = builder.get_driver() context.driver = driver print("Obtained driver") context.util = selenic.util.Util(driver, 5) behave_wait = os.environ.get("BEHAVE_WAIT_BETWEEN_STEPS") context.behave_wait = behave_wait and float(behave_wait) context.server_tempdir = tempfile.mkdtemp() server_write_fifo = os.path.join(context.server_tempdir, "fifo_to_server") os.mkfifo(server_write_fifo) server_read_fifo = os.path.join(context.server_tempdir, "fifo_from_server") os.mkfifo(server_read_fifo) nginx_port = str(builder.get_unused_port()) server = subprocess.Popen([ "utils/start_server", server_write_fifo, server_read_fifo, nginx_port ], close_fds=True) context.server = ServerControl(server, server_read_fifo, server_write_fifo) signal.signal(signal.SIGCHLD, lambda *_: sigchld(context)) # We must add the port to the server context.builder.SERVER += ":" + nginx_port context.selenium_logs = os.environ.get("SELENIUM_LOGS", False) remove_server_limit() lognames = subprocess.check_output( ["./manage.py", "btwworker", "lognames"]) context.log_checkers = [LogChecker(name) for name in lognames.splitlines()]