testcafe: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

What is your Test Scenario?

When I run simple test

import { Selector } from 'testcafe';

fixture `Page tests`
	.page `https://localhost:44300`	
    .httpAuth({
        username: process.env['USERNAME'],
		password: process.env['USERPWD'],
		domain: process.env['USERDOMAIN'],
		workstation: process.env['USERDOMAIN']
    });

test('Element exists', async t => {
	await t
		.resizeWindow(1920, 1080)
		.expect(Selector('#elementId').exists).ok();
});

on chrome, chrome:headless it passes every time. When I try run it on IE 11/Windows 10 or Edge 18.18363 / Windows 10 it fails.

What is the Current behavior?

Currently what I get is this exception:

...\node_modules\testcafe-hammerhead\lib\request-pipeline\connection-reset-guard.js:21
  throw err;
  ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:526:11)
    at RequestPipelineContext.redirect (...\node_modules\testcafe-hammerhead\lib\request-pipeline\context.js:278:9)
    at TestRun.handlePageError (...\node_modules\testcafe\src\test-run\index.js:287:13)
    at SessionController.handlePageError (...\node_modules\testcafe\src\test-run\session-controller.js:43:36)
    at error (...\node_modules\testcafe-hammerhead\lib\request-pipeline\utils.js:81:48)
    at DestinationRequest.<anonymous> (...\node_modules\testcafe-hammerhead\lib\request-pipeline\utils.js:62:9)
    at DestinationRequest.emit (events.js:310:20)
s:171:17)
    at ClientRequest.<anonymous> (...\node_modules\testcafe-hammerhead\lib\request-pipeline\destination-request\index.js:93:40) {
  code: 'ERR_HTTP_HEADERS_SENT',
  domainThrown: true
}

What is the Expected behavior?

No exception on IE or Edge.

What is your web application and your TestCafe test code?

The test are run on sample ASP.NET Core application with Windows auth enabled.

Your complete configuration file (if any):
{
	"browsers": [
		"ie",
		"edge",
		"chrome:headless"
	],
	"pageLoadTimeout": 10000,
	"screenshots": {
		"takeOnFails": true,
		"fullPage": true
	}
}

Your Environment details:

  • testcafe version: 1.8.4
  • node.js version: 12.16.2
  • command-line arguments: testcafe ie tests.js
  • browser name and version: IE 11, Edge 18
  • platform and version: Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 30 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Hey guys.

I am still getting this error with testcafe 1.9.4, just wondering if there is anyone else, please leave a reaction or comment.

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at RequestPipelineContext.redirect (.../node_modules/testcafe-hammerhead/lib/request-pipeline/context.js:285:9)
    at TestRun.handlePageError (.../node_modules/testcafe/src/test-run/index.js:301:13)
    at SessionController.handlePageError (.../node_modules/testcafe/src/test-run/session-controller.js:44:36)
    at error (.../node_modules/testcafe-hammerhead/lib/request-pipeline/utils.js:114:48)
    at DestinationRequest.req.on.err (.../node_modules/testcafe-hammerhead/lib/request-pipeline/utils.js:84:9)
    at DestinationRequest.emit (events.js:182:13)
    at DestinationRequest.EventEmitter.emit (domain.js:441:20)
    at DestinationRequest._onError (.../node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request/index.js:201:17)
    at ClientRequest.req.on.err (.../node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request/index.js:105:40)
child_process.js:660
    throw err;
    ^

Throws randomly on Github Actions using https://github.com/DevExpress/testcafe-action.

@krzysiek-b We made a little mistake. The 1.8.5-alpha.3 version doesn’t have the fix. We’ll update this thread when we release a version with the fix.

@Farfurix sure, I understand, just wanted you to be aware that there is more people who is having the issue. And, since it’s completely random, I won’t be able to reproduce it in a sample. It fails at random tests at random points, rerunning the tests without changing anything helps in 99,9% of the case, rerunning twice 100%.