Skip to content

Commit

Permalink
Remove automatic base_url override, this ever has worked only accid…
Browse files Browse the repository at this point in the history
…entally

The order in which pytest plugins are loaded is currently
nondeterministic, see pytest-dev/pytest#935. So we have no chance to
override a fixture from another plugin in our plugin, this must
instead be done in the project's conftest.py (which is guaranteed to
have precedence over plugins).
  • Loading branch information
wosc committed Dec 13, 2024
1 parent 0a38681 commit 8c98d66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,16 @@ Controlling a browser with playwright
=====================================

As an alternative to Selenium (above) nightwatch also supports playwright;
mostly by pulling in the ``pytest-playwright`` plugin, so you can use their fixtures, with some convenience features:
mostly by pulling in the ``pytest-playwright`` plugin.

- Configure a base url, and then only use paths:
``page.goto('/foo')``
Unfortunately, the playwright API is too unfriendly to allow nightwatch to set the base url automatically,
so you'll need to do that yourself, for example by overriding the ``base_url`` fixture::

Example usage::

@pytest.fixture(scope='session')
def nightwatch_config():
return dict(selenium=dict(
baseurl='https://example.com',
))
@pytest.fixture(scope="session")
def base_url():
return 'https://example.com'

def test_playwright_works(page):
page.goto('/something')
Expand Down
5 changes: 0 additions & 5 deletions src/zeit/nightwatch/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ def selenium(selenium_session):
selenium_session.delete_all_cookies()


@pytest.fixture(scope="session", autouse=True)
def base_url(nightwatch_config): # Overrides pytest-base-url
return nightwatch_config.get("selenium", {}).get("baseurl")


@pytest.fixture(scope="session")
def zeitde(nightwatch_environment):
if nightwatch_environment == "production":
Expand Down
5 changes: 5 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def nightwatch_config():
)


@pytest.fixture(scope="session")
def base_url(nightwatch_config):
return nightwatch_config.get("selenium", {}).get("baseurl")


def test_get(http):
r = http.get("/get")
assert r.status_code == 200
Expand Down

0 comments on commit 8c98d66

Please # to comment.