[Bug]: Playwright error connection refused in docker

See original GitHub issue

I’m trying to run end-2-end tests in docker in headless mode and getting playwright._impl._api_types.Error: net::ERR_CONNECTION_REFUSED at http://app/. It happends only in chromium and firefox. Webkit works but there are also problems with finding selectors. E2E tests passed when i run them from localhost. Requests succeed when I make them from localhost. Also requests succeed when I make curl from e2e-tests container.

docker-compose.yml :

  app:
    image: ${APP}
    ports:
      - 8090:80
    environment:
      SERVICE_HOST: ${REAL_IP}:8080
      KEYCLOAK_URL: 'http://keycloak:8080'
      DOLLAR: $$
    restart: unless-stopped
    command: sh -c "envsubst < /etc/nginx/conf.d/proxy.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
    depends_on:
      backend:
        condition: service_healthy


  e2e-tests:
    build: ../../auto_tests/end2end
    environment:
      SERVICE_HOST: 'http://app:80'
      HEADLESS_MODE: 1
      SERVICE_LOG_LEVEL: DEBUG
    depends_on:
      - app

chromium:

============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /usr/bin/python3

=================================== FAILURES ===================================
__________________________ TestAuth.test_correct_auth __________________________
  
tests/test_auth.py:6: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
fixture/session.py:10: in login
    self.app.navigation.open_home_page()
fixture/navigation.py:15: in open_home_page
    page.goto(SERVICE_HOST)
/usr/local/lib/python3.8/dist-packages/playwright/sync_api/_generated.py:7133: in goto
    self._sync(
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_sync_base.py:111: in _sync
    return task.result()
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_page.py:467: in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_frame.py:119: in goto
    await self._channel.send("goto", locals_to_params(locals()))
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py:39: in send
    return await self.inner_send(method, params, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright._impl._connection.Channel object at 0x7fa7a814bca0>
method = 'goto', params = {'url': 'http://app:80'}, return_as_dict = False

    async def inner_send(
        self, method: str, params: Optional[Dict], return_as_dict: bool
    ) -> Any:
        if params is None:
            params = {}
        callback = self._connection._send_message_to_server(self._guid, method, params)
    
        done, pending = await asyncio.wait(
            {self._connection._transport.on_error_future, callback.future},
            return_when=asyncio.FIRST_COMPLETED,
        )
        if not callback.future.done():
            callback.future.cancel()
>       result = next(iter(done)).result()
E       playwright._impl._api_types.Error: net::ERR_CONNECTION_REFUSED at http://app/
E       =========================== logs ===========================
E       navigating to "http://app/", waiting until "load"
E       ============================================================

/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py:57: Error

firefox:

    =================================== FAILURES ===================================
    
    tests/test_auth.py:6: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    fixture/session.py:10: in login
        self.app.navigation.open_home_page()
    fixture/navigation.py:15: in open_home_page
        page.goto(SERVICE_HOST)
    /usr/local/lib/python3.8/dist-packages/playwright/sync_api/_generated.py:7133: in goto
        self._sync(
    /usr/local/lib/python3.8/dist-packages/playwright/_impl/_sync_base.py:111: in _sync
        return task.result()
    /usr/local/lib/python3.8/dist-packages/playwright/_impl/_page.py:467: in goto
        return await self._main_frame.goto(**locals_to_params(locals()))
    /usr/local/lib/python3.8/dist-packages/playwright/_impl/_frame.py:119: in goto
        await self._channel.send("goto", locals_to_params(locals()))
    /usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py:39: in send
        return await self.inner_send(method, params, False)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <playwright._impl._connection.Channel object at 0x7f89aa274ca0>
    method = 'goto', params = {'url': 'http://app:80'}, return_as_dict = False
    
        async def inner_send(
            self, method: str, params: Optional[Dict], return_as_dict: bool
        ) -> Any:
            if params is None:
                params = {}
            callback = self._connection._send_message_to_server(self._guid, method, params)
        
            done, pending = await asyncio.wait(
                {self._connection._transport.on_error_future, callback.future},
                return_when=asyncio.FIRST_COMPLETED,
            )
            if not callback.future.done():
                callback.future.cancel()
    >       result = next(iter(done)).result()
    E       playwright._impl._api_types.Error: NS_ERROR_CONNECTION_REFUSED
    E       =========================== logs ===========================
    E       navigating to "http://app/", waiting until "load"
    E       ============================================================

webkit:

=================================== FAILURES ===================================

tests/test_auth.py:6: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
fixture/session.py:27: in login
    page.click('#username')
/usr/local/lib/python3.8/dist-packages/playwright/sync_api/_generated.py:7813: in click
    self._sync(
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_sync_base.py:111: in _sync
    return task.result()
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_page.py:624: in click
    return await self._main_frame.click(**locals_to_params(locals()))
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_frame.py:448: in click
    await self._channel.send("click", locals_to_params(locals()))
/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py:39: in send
    return await self.inner_send(method, params, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright._impl._connection.Channel object at 0x7f5669d6aca0>
method = 'click', params = {'selector': '#username'}, return_as_dict = False

    async def inner_send(
        self, method: str, params: Optional[Dict], return_as_dict: bool
    ) -> Any:
        if params is None:
            params = {}
        callback = self._connection._send_message_to_server(self._guid, method, params)
    
        done, pending = await asyncio.wait(
            {self._connection._transport.on_error_future, callback.future},
            return_when=asyncio.FIRST_COMPLETED,
        )
        if not callback.future.done():
            callback.future.cancel()
>       result = next(iter(done)).result()
E       playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
E       =========================== logs ===========================
E       waiting for selector "#username"
E       ============================================================

/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py:57: TimeoutError

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
mxschmittcommented, Oct 25, 2021

Closing for now since this is unlikely a Playwright related issue and more a docker-compose configuration issue.

3reactions
HurricaneHazecommented, Oct 25, 2021

Closing for now since this is unlikely a Playwright related issue and more a docker-compose configuration issue.

It is not docker-compose configuration issue becuase i curl from playwright container and requests succeed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playwright error connection refused in docker - Stack Overflow
I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application.
Read more >
playwright._impl._api_types.error - You.com | The AI Search ...
I'm trying to run end-2-end tests in docker in headless mode and getting playwright._impl._api_types.Error: net::ERR_CONNECTION_REFUSED at http://app/ . It ...
Read more >
Running End-to-End Tests with Playwright on ... - Lari Haataja
I started to build a docker image based on this post on the AWS blog. Let's use mcr.microsoft.com/playwright:focal as the base image and...
Read more >
Moon - A cross browser Selenium, Cypress, Playwright and ...
When trying to open an HTTPS web-page using such TLS certificate, your browser by default will refuse to do this saying that "Your...
Read more >
Troubleshooting AWS CodeBuild
Error : "Cannot connect to the Docker daemon" when running a build · In the navigation pane, choose Build projects, and then choose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found