def composite3(context, checkpoints, *args, **kwargs): bad_fixture = bad_with_setup_error the_composite = use_composite_fixture_with(context, [ fixture_call_params(fixture_foo, checkpoints, name="_1"), fixture_call_params(bad_fixture, checkpoints, name="OOPS"), fixture_call_params(fixture_foo, checkpoints, name="_3:NOT_REACHED"), ]) return the_composite
def password_reset(context): return use_composite_fixture_with(context, [ fixture_call_params(unknown), fixture_call_params(successful_set_password), fixture_call_params(password_not_compliant), fixture_call_params(expired_link), fixture_call_params(successful_password_reset) ])
def signup(context): return use_composite_fixture_with(context, [ fixture_call_params(unknown), fixture_call_params(successful_signup), fixture_call_params(expired_link), fixture_call_params(successful_account_confirmation), fixture_call_params(password_not_compliant) ])
def composite3(context, checkpoints, *args, **kwargs): bad_fixture = bad_with_setup_error the_composite = use_composite_fixture_with(context, [ fixture_call_params(fixture_foo, checkpoints, name="_1"), fixture_call_params(bad_fixture, checkpoints, name="OOPS"), fixture_call_params( fixture_foo, checkpoints, name="_3:NOT_REACHED"), ]) return the_composite
def test_data_schema2(self): @fixture def foo(context, *args, **kwargs): # -- NOTE checkpoints: Injected from outer scope. params = "%r, %r" % (args, kwargs) checkpoints.append("foo.setup: %s" % params) yield "fixture.foo" checkpoints.append("foo.cleanup: %s" % params) fixture_registry = { "fixture.foo": fixture_call_params(foo, 1, 2, 3, name="foo_1") } # -- PERFORM-TEST: context = make_runtime_context() checkpoints = [] with scoped_context_layer(context): use_fixture_by_tag("fixture.foo", context, fixture_registry) checkpoints.append("scoped-block") # -- VERIFY: assert checkpoints == [ "foo.setup: (1, 2, 3), {'name': 'foo_1'}", "scoped-block", "foo.cleanup: (1, 2, 3), {'name': 'foo_1'}", ]
def user_accounts(context): # the following fixtures add data to the database # therefore they need to be added before each scenario # because the database is cleaned up after each scenario return use_composite_fixture_with(context, [ fixture_call_params(permissions), fixture_call_params(consumer), fixture_call_params(producer), fixture_call_params(manager), fixture_call_params(rex), fixture_call_params(softozor), fixture_call_params(inactive_customer) ])
from behave.fixture import fixture_call_params, fixture from sell_tests.configurations.account_configuration import EMAIL, PASSWORD from sell_tests.helpers.web_elements.wait import wait_until from sell_tests.page_objects.dashboard_page import DashboardPage from sell_tests.page_objects.login_page import LoginPage @fixture def login(context): """ Fixture opens login page and login user """ login_page = LoginPage() login_page.open() login_page.set_email(EMAIL) login_page.set_password(PASSWORD) login_page.click_sign_in_button() __wait_until_dashboard_is_loaded() def __wait_until_dashboard_is_loaded(): dashboard_page = DashboardPage() wait_until(dashboard_page.is_dashboard_title_displayed, timeout_message="Dashboard title isn't displayed.") FIXTURES = {"fixture.login": fixture_call_params(login)}
from behave.fixture import use_fixture_by_tag, fixture_call_params from features.support.fixtures import backup_file # -- REGISTRY DATA SCHEMA: (fixture_func, fixture_args, fixture_kwargs) # Note: See https://behave.readthedocs.io/en/latest/fixtures.html for more info # on fixtures and how they work fixture_registry = { "fixture.backup.TBcanonical_s.json": fixture_call_params( backup_file, filename="models/TBcanonical_s.json"), "fixture.backup.TBcanonical_p.json": fixture_call_params( backup_file, filename="models/TBcanonical_p.json"), "fixture.backup.TBcanonical_d.json": fixture_call_params( backup_file, filename="models/TBcanonical_d.json"), } def before_tag(context, tag): if tag.startswith("fixture."): return use_fixture_by_tag(tag, context, fixture_registry) def before_scenario(context, scenario): context.patchers = [] def after_scenario(context, scenario): for patcher in context.patchers: patcher.stop()
def composite2(context, checkpoints, *args, **kwargs): the_composite = use_composite_fixture_with(context, [ fixture_call_params(fixture_foo, checkpoints, name="_1"), fixture_call_params(fixture_foo, checkpoints, name="_2"), ]) return the_composite
def login(context): return use_composite_fixture_with(context, [ fixture_call_params(unknown), fixture_call_params(wrong_credentials_response), fixture_call_params(user_not_admin_response) ])
# return use_fixture(cmake_build_use_inherit_config_file, ctx) # # @fixture # def fixture_cmake_build_use_inherit_config_file_enabled(ctx, **kwargs): # return use_fixture(cmake_build_use_inherit_config_file, ctx, value=True) # # @fixture # def fixture_cmake_build_use_inherit_config_file_disabled(ctx, **kwargs): # return use_fixture(cmake_build_use_inherit_config_file, ctx, value=False) # # ----------------------------------------------------------------------------- # FIXTURE REGISTRY: Maps fixture-tag to fixture-func # ----------------------------------------------------------------------------- fixture_registry = { "fixture.cmake_build.cleanup_environment": fixture_cleanup_environment, "fixture.cmake_build.ensure_clean_environment": fixture_ensure_clean_environment, "fixture.cmake_build.inherits_config_file": fixture_call_params(cmake_build_use_inherit_config_file, value=None), "fixture.cmake_build.inherit_config_file.enabled": fixture_call_params(cmake_build_use_inherit_config_file, value=True), "fixture.cmake_build.inherit_config_file.disabled": fixture_call_params(cmake_build_use_inherit_config_file, value=False), # -- ALIASES with SYNTACTIC SUGAR: "fixture.cmake_build.inherit_config_file=yes": fixture_call_params(cmake_build_use_inherit_config_file, value=True), "fixture.cmake_build.inherit_config_file=no": fixture_call_params(cmake_build_use_inherit_config_file, value=False), }
def shops_fixtures(context): return use_composite_fixture_with(context, [ fixture_call_params(shops), fixture_call_params(expected_shop_list), fixture_call_params(expected_shop_catalogues) ])
import base64 from behave.fixture import fixture_call_params from fixtures import use_fixture_by_tag, browser import glob import logging.config import os import sys logging.config.fileConfig(fname='package/config/logger.ini', disable_existing_loggers=False) logger = logging.getLogger('Features') fixture_registry = {'fixture.browser': fixture_call_params(browser)} os.environ['DEBUG'] = str('@wip' in sys.argv or '@debug' in sys.argv) def before_tag(context, tag): if tag.startswith('fixture.'): return use_fixture_by_tag(tag, context, fixture_registry) def after_step(context, step): if step.status != 'failed' and os.getenv('DEBUG') != 'True': return logger.error(step.exception) logger.info(step.exception, exc_info=(None, step.exception, step.exc_traceback)) if 'fixture.browser' not in context.tags:
Generator function. Yields: A flask testing client attribute to Behave's context. """ app = create_app(TestConfig) # context.client = app.test_client() # context.client = create_app( TestConfig ) with app.test_client() as testClient: # with app.app_context(): context.client = testClient yield context.client tag_registry = { "fixture.browser.chrome": fixture_call_params(splinter_browser), "fixture.browser.flask": fixture_call_params(splinter_browser, type='flask'), "fixture.flask": fixture_call_params(flask_client) } def before_all(context): """Runs before each test Args: context: Behave testing context """ # use_fixture( flask_client, context )
from behave.fixture import use_fixture_by_tag, fixture_call_params from features.support.fixtures import backup_file # -- REGISTRY DATA SCHEMA: (fixture_func, fixture_args, fixture_kwargs) # Note: See https://behave.readthedocs.io/en/latest/fixtures.html for more info # on fixtures and how they work fixture_registry = { "fixture.backup.TBcanonical_s.json": fixture_call_params(backup_file, filename="models/TBcanonical_s.json"), "fixture.backup.TBcanonical_p.json": fixture_call_params(backup_file, filename="models/TBcanonical_p.json"), "fixture.backup.TBcanonical_d.json": fixture_call_params(backup_file, filename="models/TBcanonical_d.json"), } def before_tag(context, tag): if tag.startswith("fixture."): return use_fixture_by_tag(tag, context, fixture_registry) def before_scenario(context, scenario): context.patchers = [] def after_scenario(context, scenario): for patcher in context.patchers: patcher.stop()