Hi All, I keep getting errors whenever trying to get started with playwright. First i can't do a python mytool.py, always has to be pytest mytool.py. Second whenever I am in my text editor, playwright.async_api as well as sync_api are always underlined as module not found (also the error I get when running python mytool.py).
pytest mytool.py does work regardless of this in sync mode. However, if I go to import asyncio and use playwright.async_api I get the error: "ImportError: cannot import name 'async_playwright' from playwright.async_api"
I literally am just copying the async code from https://playwright.dev/python/docs/api/class-playwright
This thread is trying to answer question "Why can't the user get async to work in playwright and why are they having issues running their script with python instead of pytest?"
Hello, Playwright for Python maintainer here! If you want to write tests we recommend pytest, thats why we have it everywhere in our docs. If you want to just write a normal script, see here https://playwright.dev/python/docs/library
Your VSCode issue is related to the Python environment which is selected, most likely the wrong one, that’s e.g. virtualenv related.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].