Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Error: page.goto: net::ERR_CONNECTION_REFUSED at http://127.0.0.1:3000/users/sign_in (local host) #24582

Closed
RomarioNijimAlmond opened this issue Aug 3, 2023 · 3 comments

Comments

@RomarioNijimAlmond
Copy link

RomarioNijimAlmond commented Aug 3, 2023

Hi,
Iv'e been trying for quite a while now to run my playwright test on my application which I run on localhost port 3000,
I navigate to the local host website via page.goto function

    public async loadApplication(url: ApplicationUrl) {
        await this.page.goto(url.valueOf(), {
            waitUntil: 'domcontentloaded',
        });
    }

which I get it from an enum => LOCAL = 'http://127.0.0.1:3000/users/sign_in',
which I call it like this loadApplication(ApplicationUrl.LOCAL);

I tried to navigate to localhost or 127.0.0.1:3000 but both do not work and I get this connection refused error in github actions

I am exposing port 3000 in the docker-compose.yml file and when running it locally everything works fine and Im able to load up the app via docker compose but it fails when it tries to go to the url and I always get this error.

I also tried to curl http request to the same url on both localhost or 127.0.0.1 which did not solve the issue.
connecting to a url with server that has a DNS name does work in CI, but I wanna run it on local host in the job.

the server is up and running when I run docker-compsoe up and the step passes
otherwise it would have failed if the server was not up

also tried to start the server with it's command rails s -p 3000 -d but still I receive the same error that the connection is refused

please tell me what I need to do to fix this issue since I already tried pretty much everything.
I will provide the workflow + docker-compose file below:

this is the error that I recieve:

1) [Google Chrome] › tests/almondLoginTest/LoginTest.spec.ts:23:9 › Login test to almond QMS › Login to Almond QMS system @LOGIN_SANITY (Qase ID: 90) 

    Error: page.goto: net::ERR_CONNECTION_REFUSED at http://127.0.0.1:3000/users/sign_in
    =========================== logs ===========================
    navigating to "http://127.0.0.1:3000/users/sign_in", waiting until "domcontentloaded"
    ============================================================

       at common/BasePage.ts:11

       9 |
      10 |     public async loadApplication(url: ApplicationUrl) {
    > 11 |         await this.page.goto(url.valueOf(), {
         |                         ^
      12 |             waitUntil: 'domcontentloaded',
      13 |         });
      14 |     }

        at BasePage.loadApplication (/__w/almond/almond/uiAutomation/Playwright/common/BasePage.ts:11:[25](https://github.com/almond-qms/almond/actions/runs/5750240504/job/15586604981#step:8:26))
        at /__w/almond/almond/uiAutomation/Playwright/tests/almondLoginTest/LoginTest.spec.ts:[26](https://github.com/almond-qms/almond/actions/runs/5750240504/job/15586604981#step:8:27):[28](https://github.com/almond-qms/almond/actions/runs/5750240504/job/15586604981#step:8:29)
        at /__w/almond/almond/uiAutomation/Playwright/tests/almondLoginTest/LoginTest.spec.ts:25:20

    attachment #2: video (video/webm) ──────────────────────────────────────────────────────────────
    test-results/tests-almondLoginTest-LoginTest-Login-test-to--84f2b-n-to-Almond-QMS-system-LOGIN-SANITY-Qase-ID-90--Google-Chrome/video.webm
    ────────────────────────────────────────────────────────────────────────────────────────────────

    attachment #3: trace (application/zip) ─────────────────────────────────────────────────────────
    test-results/tests-almondLoginTest-LoginTest-Login-test-to--84f2b-n-to-Almond-QMS-system-LOGIN-SANITY-Qase-ID-90--Google-Chrome/trace.zip
    Usage:

        npx playwright show-trace test-results/tests-almondLoginTest-LoginTest-Login-test-to--84f2b-n-to-Almond-QMS-system-LOGIN-SANITY-Qase-ID-90--Google-Chrome/trace.zip

this is my CI workflow:

name: Playwright Tests
on:
  push:
    branches:
      - "*"
  pull_request:
    types:
      - closed
    branches: [dev, master]
env:
  IMAGE_TAG: ${{ github.sha }}
  PLAYWRIGHT_DIRECTORY: uiAutomation/Playwright
  DOCKER_HUB_USER_NAME: ${{ secrets.DOCKER_HUB_USER_NAME }}
  DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
jobs:
  test_build:
    if: github.event_name == 'push'
    timeout-minutes: 60
    runs-on: ubuntu-20.04
    container:
      image: private image
      credentials:
        username: ${{ env.DOCKER_HUB_USER_NAME }}
        password: ${{ env.DOCKER_HUB_PASSWORD }}
    strategy:
      matrix:
        modules: ["@LOGIN_SANITY"]
    steps:
      - uses: actions/checkout@v3
      - name: login to dockerhub
        uses: docker/login-action@v2
        with:
          username: ${{ env.DOCKER_HUB_USER_NAME }}
          password: ${{ env.DOCKER_HUB_PASSWORD }}
      - name: run the container via docker compose
        run: |
          docker compose -f docker-compose.yml up -d
          echo "Server is Up and running"
      - name: Install playwright dependencies and run tests
        run: npm ci
        working-directory: ${{ env.PLAYWRIGHT_DIRECTORY }}
      - name: install playwright chromium browser
        run: npx playwright install --with-deps chromium
        working-directory: ${{ env.PLAYWRIGHT_DIRECTORY }}
      - name: run playwright tests
        run: npx playwright test --grep ${{ matrix.modules }}
        working-directory: ${{ env.PLAYWRIGHT_DIRECTORY }}
      - uses: actions/upload-artifact@v3
        if: always()
        with:
          path: uiAutomation/Playwright/playwright-report/
          retention-days: 30
      - name: login to dockerhub
        uses: docker/login-action@v2
        with:
          username: ${{ env.DOCKER_HUB_USER_NAME }}
          password: ${{ env.DOCKER_HUB_PASSWORD }}
      - name: build docker image
        run: |
          echo "building the image"
          docker build -f Dockerfile -t image${{ env.IMAGE_TAG }} .
          echo "pushing to dockerhub"
          docker push image:${{ env.IMAGE_TAG }}
        if: github.event.pull_request.merged

docker-compose

version: '3.3'
services:
  web:
    image: private
  
    ports:
      - 3000:3000
@yury-s
Copy link
Member

yury-s commented Aug 4, 2023

I also tried to curl http request to the same url on both localhost or 127.0.0.1 which did not solve the issue. connecting to a url with server that has a DNS name does work in CI, but I wanna run it on local host in the job.

Since you cannot access the url with curl, it seems like a problem with running the server with docker compose on your CI rather than a playwright bug.

If you still think it's a bug in Playwright we'll need a self-contained repro that could be run locally in order to help you.

@yury-s yury-s added the triaging label Aug 4, 2023
@RomarioNijimAlmond
Copy link
Author

RomarioNijimAlmond commented Aug 6, 2023

@yury-s I solved the issue by adding the service under the container key in the CI, similar to docker compose file when you define the services, although idk why I need to specify the service if it is already defined in the docker compose file but this solves the issue for navigating to local host in playwright with github actions.

jobs:
  test_build:
    if: github.event_name == 'push'
    timeout-minutes: 60
    runs-on: ubuntu-20.04
    container:
    services:
      web:
        image: private
        credentials:
          username: ${{ env.DOCKER_HUB_USER_NAME }}
          password: ${{ env.DOCKER_HUB_PASSWORD }}

@yury-s
Copy link
Member

yury-s commented Aug 6, 2023

Closing per the response above as the problems is solved.

@yury-s yury-s closed this as completed Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants