diff --git a/capybara/dsl.py b/capybara/dsl.py index b6c11fb..a23448c 100644 --- a/capybara/dsl.py +++ b/capybara/dsl.py @@ -37,11 +37,15 @@ def _define_package_method(name): def _define_session_method(name): @wraps(getattr(Session, name)) - def func(*args, **kwargs): + def class_func(self, *args, **kwargs): return getattr(page, name)(*args, **kwargs) - setattr(DSLMixin, name, func) - setattr(_module, name, func) + @wraps(getattr(Session, name)) + def module_func(*args, **kwargs): + return getattr(page, name)(*args, **kwargs) + + setattr(DSLMixin, name, class_func) + setattr(_module, name, module_func) for _method in PACKAGE_METHODS: diff --git a/tests/test_dsl.py b/tests/test_dsl.py index 9ba42eb..e169112 100644 --- a/tests/test_dsl.py +++ b/tests/test_dsl.py @@ -139,3 +139,15 @@ def test_is_nestable(self): class TestSessionName(DSLTestCase): def test_defaults_to_default(self): assert capybara.session_name == "default" + + +class TestUsingDSLMixin(DSLTestCase): + @pytest.fixture + def myclass(self): + from capybara.dsl import DSLMixin + class MyClass(DSLMixin): + pass + return MyClass() + + def test_uses_current_session(self, myclass): + assert myclass.has_no_current_path("/")