I am running into an issue where in Playwright I am getting this error every 15 or so requests
Error: apiRequestContext.post: getaddrinfo ENOTFOUND
for the URL I am using an https:// development server endpoint. The same exact request can pass and then fail, and when I debug the tests they are always passing. Here is a helper function where it is running the post that is throwing the error:
public static async postJSONX_Access(request: APIRequestContext, endpoint: string,body: object, xAccessToken: string | undefined ) : Promise<any>
{
const response = await request.post(endpoint, {
data:body,
headers: {
'X-Access-Token' : xAccessToken!
},
});
expect(response.ok());
return await response.json();
}
Full error log here:
Error: apiRequestContext.post: getaddrinfo ENOTFOUND d-api.company.com
Call log:
- → POST d-api.company.com/post/data
- user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.17 Safari/537.36
- accept: /
- accept-encoding: gzip,deflate,br
- X-Access-Token: tokenGoesHere
- content-type: application/json
- content-length: 2
I am testing two APIs and only running into this issue on one of them. Any help would be appreciated, I tried the solution from this question API GET Request test using Playwright on adding
import dns from "dns"; dns.setDefaultResultOrder("ipv4first");
To my playwright.config.js folder and it didn’t work to resolve the issue.
I am expecting what happens most of the time where the POST request goes through and the response is returned. I have tried removing https:// from the baseURL, I have tried adding
import dns from "dns"; dns.setDefaultResultOrder("ipv4first");
To the config file, I have tried running ipconfig /flushdns. When I restart my computer it is working to pass all the tests but over time these failures start popping up.