[Python] Playwright pytest--screenshot does not create test_result folder or take screenshot

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am using playwright with pytest and whenever I tried to take a screenshot of a test that failed nothing happen. Here a snippet of my code:

    def test_resetpassword(authentification_page) -> None:
    page = authentification_page
    randomPassword = generate_password()
    page.get_by_role("link", name="Don't remember your password?").click()
    page.get_by_role("button", name="Use phone number").click()
    page.get_by_test_id("phoneNumber").fill("0634778965")
    page.get_by_test_id("submit").click()
    page.get_by_test_id("verification_code").fill("0000")
    page.get_by_test_id("password").fill(randomPassword)
    page.get_by_test_id("password_confirmation").fill(randomPassword)
    with page.expect_request(DOMAIN_URL + "/reset-password") as first:
    # when clicking on Send we expect the above API call on the network
    page.get_by_test_id("submit").click()
    first_request = first.value
    request_payload=first_request.post_data_json #request payload
    response_payload=first_request.response().json()
    assert response_payload["error_description"] == "Invalid verification code"
    assert request_payload["phone_number"] == "+33634778966"


    and here the fixture part for this code:

    @pytest.fixture(scope="session")
    def authentification_page(browser):
    # browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    context.set_default_navigation_timeout(120000)
    # # Open a new page
    page = context.new_page()
    page.goto(HP_URL)
    yield page


    Here the command line that I use:

    pytest -k test_resetpassword.py --screenshot only-on-failure

    Continue reading...

Compartilhe esta Página