1

In node.js we have https://playwright.dev/docs/test-timeouts, but page does not exist for python, I can use the timeout parameter, but then I have to set it all over:

page.goto(url, timeout=6000.0)
page.get_by_label(re.compile(r"(Language select|Språkvalg)")).click(timeout=6000.0)

How can I set this globally, in pytest.ini or a pytest.fixture?

1 Answer 1

2

To change navigational timeouts, one way you could accomplish this is to overwrite the default page fixture used in your Playwright tests. For example, you could add the following code to the top of your Playwright test file:

@pytest.fixture
def page(context: BrowserContext) -> Generator[Page, None, None]:
    page = context.new_page()
    page.set_default_navigation_timeout(6000) # the timeout is in milliseconds
    yield page

For expect based timeouts, you can modify the default timeout in your conftest.py file (see documentation here). To set the timeout to 6 seconds, include the following code:

from playwright.sync_api import expect

expect.set_options(timeout=6000) # the timeout is in milliseconds
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.