microsoft / playwright-python

Python version of the Playwright testing and automation library.
https://playwright.dev/python/
Apache License 2.0
11.56k stars 880 forks source link

[Bug]: Error running Playwright test in Windows runner in GitHub actions[Bug]: #2506

Closed pamelafox closed 1 month ago

pamelafox commented 1 month ago

Version

1.45.1

Steps to reproduce

See the CI here: https://github.com/Azure-Samples/rag-postgres-openai-python/actions/runs/10189786904/job/28188453780?pr=66

Here's the workflow file: https://github.com/Azure-Samples/rag-postgres-openai-python/actions/runs/10189786904/workflow?pr=66

The playwright tests run fine in Mac, but they fail in the Windows runner.

We'll go ahead and disable them in main, but you can replicate by using our code at that point in time in a fork: commit 0cf5e354b0e8e9723920887b769d8649730baa25 in https://github.com/john0isaac/rag-postgres-openai-python/tree/add-playwright-tests

Expected behavior

We expect tests to pass.

Actual behavior

We see this error:

____________________ ERROR at setup of test_home[chromium] ____________________

launch_browser = <function launch_browser.<locals>.launch at 0x0000016AF7510670>

    @pytest.fixture(scope="session")
    def browser(launch_browser: Callable[[], Browser]) -> Generator[Browser, None, None]:
>       browser = launch_browser()

C:\hostedtoolcache\windows\Python\3.10.11\x[64](https://github.com/Azure-Samples/rag-postgres-openai-python/actions/runs/10189786904/job/28188453780?pr=66#step:16:65)\lib\site-packages\pytest_playwright\pytest_playwright.py:2[66](https://github.com/Azure-Samples/rag-postgres-openai-python/actions/runs/10189786904/job/28188453780?pr=66#step:16:67): 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\pytest_playwright\pytest_playwright.py:258: in launch
    browser = browser_type.launch(**launch_options)
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\playwright\sync_api\_generated.py:14155: in launch
    self._sync(
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\playwright\_impl\_browser_type.py:94: in launch
    Browser, from_channel(await self._channel.send("launch", params))
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\playwright\_impl\_connection.py:59: in send
    return await self._connection.wrap_api_call(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <playwright._impl._connection.Connection object at 0x0000016AF[72](https://github.com/Azure-Samples/rag-postgres-openai-python/actions/runs/10189786904/job/28188453780?pr=66#step:16:73)B8610>
cb = <function Channel.send.<locals>.<lambda> at 0x0000016AF[73](https://github.com/Azure-Samples/rag-postgres-openai-python/actions/runs/10189786904/job/28188453780?pr=66#step:16:74)8E8C0>
is_internal = False

    async def wrap_api_call(
        self, cb: Callable[[], Any], is_internal: bool = False
    ) -> Any:
        if self._api_zone.get():
            return await cb()
        task = asyncio.current_task(self._loop)
        st: List[inspect.FrameInfo] = getattr(task, "__pw_stack__", inspect.stack())
        parsed_st = _extract_stack_trace_information_from_stack(st, is_internal)
        self._api_zone.set(parsed_st)
        try:
            return await cb()
        except Exception as error:
>           raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
E           playwright._impl._errors.Error: BrowserType.launch: ENOENT: no such file or directory, mkdtemp 'undefined\temp\playwright-artifacts-XXXXXXXXXXXX'

C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\playwright\_impl\_connection.py:514: Error

Additional context

No response

Environment

- Operating System: Windows
- CPU: Whatever is used by GitHub windows runner
- Browser: Chromium
- Python Version: 3.10 - 3.12
- Other info:
mxschmitt commented 1 month ago

This looks suspicious: https://github.com/Azure-Samples/rag-postgres-openai-python/blob/0cf5e354b0e8e9723920887b769d8649730baa25/tests/conftest.py#L46

Try to remove clear or just write to os.environ. Playwright needs good environment variables, and you fully clear them probably.

pamelafox commented 1 month ago

Ah, interesting- I often use clear=True so that we don't have to overspecify every single environment variable, and can rely on unset env variables taking on their default values in configuration. I don't think it's an issue in this repo, but it was an issue in another repo. Anyways, I just did a test CI removing clear=True for this repo, and all passed! I can make sure to only clear the app's env variables in future to avoid trampling on playwright vars. Thank you!