I am running Playwright tests on a local server (http://localhost:3000). The tests pass without issues on my local machine, but in the CI pipeline, the tests fail with the following error:
Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:3000/
Local Machine:
- OS: macOS
- Node.js Version: 16
- Playwright Version: 1.39.0
CI Environment:
- Platform: GitHub Actions
- Node.js Version: 16
- Playwright Version: 1.39.0
Here is my playwright.config.js
:
const { devices } = require('@playwright/test');
const baseURL = 'http://localhost:3000/en/';
const config = {
testDir: './tests',
timeout: 30 * 1000,
expect: {
timeout: 5000
},
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
actionTimeout: 0,
// baseURL: 'http://localhost:3000/en/',
baseURL: baseURL,
trace: 'on',
locale: 'en-US'
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome']
}
},
{
name: 'Chrome Half Size',
use: {
...devices['Desktop Chrome'],
viewport: { width: 800, height: 600 }, // Half size viewport
},
},
{
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] },
},
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] },
},
],
outputDir: 'test-results/',
webServer: {
command: 'yarn dev',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
url: baseURL
// port: 3000,
}
};
module.exports = config;
Here is my workflow file:
name: Playwright Tests
on:
push:
branches: [main, master, actions]
pull_request:
branches: [main, master, actions]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: cityflagv2
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
env:
DB_MONGO_URL: ${{ secrets.DB_MONGO_URL }}
SECRET_COOKIE_PASSWORD: ${{ secrets.SECRET_COOKIE_PASSWORD }}
SENTRY_URL: ${{ secrets.SENTRY_URL }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
BASE_URL: ${{ secrets.BASE_URL }}
MYSQL_HOST: ${{ secrets.MYSQL_HOST }}
MYSQL_DB: ${{ secrets.MYSQL_DB }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PASS: ${{ secrets.MYSQL_PASS }}
MYSQL_CONNECTION_LIMIT: 10
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Verify DB exists
run: mysql --host 127.0.0.1 --port 3306 -uroot -proot -e "SHOW DATABASES LIKE 'cityflagv2'"
- name: Install dependencies
run: npm config set "@fortawesome:registry" https://npm.fontawesome.com/ && npm config set "//npm.fontawesome.com/:_authToken" "${{ secrets.FONTAWESOME_NPM_AUTH_TOKEN }}" && yarn install
- name: Lint
run: yarn lint
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test tests/index.spec.js
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
deploy:
needs: test
name: Deploy
runs-on: self-hosted
steps:
- run: cd /home/ubuntu/irysteams && git pull
- run: cd /home/ubuntu/irysteams && yarn install
- run: cd /home/ubuntu/irysteams && yarn prestart
- run: pm2 reload name
Troubleshooting steps taken:
- Verified that the server starts correctly.
- Added a wait time to ensure the server is ready before running tests.
- Checked for port conflicts and ensured no other processes are using port 3000.
- Compared the environment configuration between local and CI.
Observations:
- The URL bar is empty in the network trace for the failing tests.
- The baseURL is set correctly in the configuration.
What could be causing the net::ERR_CONNECTION_REFUSED
error in the CI pipeline but not locally? The tests passes for the chromium browsers but fails on the other 2 on page.goto("/")
.
Choudhry18 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.