5

I have been trying to verify the GET status using the following code. Unfortunately, I am getting an error "apiRequestContext.get: connect ECONNREFUSED ::1:8080". Any insight would be much appreciated.

Code:

import { expect, test } from '@playwright/test';

test('Get health status', async ({ request }) => {
    const response = await request.get('http://localhost:8080/myapp/actuator/health')
    expect(response.status()).toBe(200)
  })

Error: apiRequestContext.get: connect ECONNREFUSED ::1:8080

3
  • Are you able to hit this endpoint successfully using any other testing tool like postman and get the response as 200? Commented Nov 26, 2022 at 2:53
  • Can you try await request.get('http://localhost:8080/myapp/actuator/health', verify=False) Commented Nov 27, 2022 at 11:02
  • Did you find solution? Commented Dec 10, 2022 at 12:02

1 Answer 1

0

Since NodeJS 17, node will prefer IPv6 over IPv4.

Verification

It might be that the service only listens on IPv4, but the client uses IPv6. Check for the words IPv4 or IPv6 in:

  • netstat -tulpen (on linux) or
  • sudo lsof -iTCP -sTCP:LISTEN -n -P 8080 | grep -i --color 8080 (on macOS).

Solutions

There are two options:

  1. Enable IPv6 binding for the service. This depends on your service framework - search how to enable ipv6 for service XYZ in Google.

  2. Configure NodeJS to prefer IPv4 over IPV6. Add to playwright.config.js:

import dns from "dns";
dns.setDefaultResultOrder("ipv4first");
  1. If the service can handle, force the use of IPv4: connect to http://127.0.0.1:8080 instead of http://localhost:8080

  2. Disable the IPv6 address for localhost for the whole machine. Edit the hosts file (sudo vi /etc/hosts) and remove ::1 localhost.

Resources

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.