pythonpytestplaywrightplaywright-python

Unable to run Playwright test scripts in debug Mode


I'm trying to learn Playwright, so I was checking Playwright Inspector concept and written below piece of code. In Pycharm terminal I run the below i.e. set PWDEBUG=1 and use pytest

PWDEBUG=1 pytest -s test_saucedemo.py

I get error message

PWDEBUG=1 : The term 'PWDEBUG=1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.

Note: Path of the file is proper because when I run as pytest -s test_saucedemo.py test is passed.

import pytest
from playwright.sync_api import Page,expect

def test_page_title(page:Page):
    page.goto("https://www.saucedemo.com/v1/index.html")  #pytest --base-url https://www.saucedemo.com
    expect(page).to_have_title("Swag Labs")
    page.get_by_placeholder("Username").fill("standard_user")
    page.get_by_placeholder("Password").fill("secret_sauce")


    page.locator("input.btn_action").click()

Solution

  • The command you are executing to start your tests is using POSIX shell syntax for setting the environment variable PWDEBUG, but you seem to be executing it in a PowerShell.

    The PowerShell syntax is a bit different. Try executing the following command instead:

    $Env:PWDEBUG = 1; pytest -s test_saucedemo.py
    

    See the question PowerShell: Setting an environment variable for a single command only.