Rayrun
← Back to Discord Forum

I can't get async to work, I'm just starting with playwright

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?"

4 replies

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.

Have you installed playwright with pip? This explains the module not found error.

ok yeah i see switching to 3.10 env does resolve the errors... interesting thought I only had 3.12 🙂 thanks and will look at the docs you sent

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.