Kudryavtsev Yuri
Kudryavtsev Yuri

Reputation: 51

Playwright error connection refused in docker

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

Upvotes: 2

Views: 9507

Answers (1)

Kudryavtsev Yuri
Kudryavtsev Yuri

Reputation: 51

I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application. My application is running locally on http. Chromium and geko drivers force httpS connection for some domain names one of which is "app". So i have to change name for my docker container wich contains frontend application.

Upvotes: 3

Related Questions