Skip to content

TestCafe hungs if the overriden method of the RequestHook raises an error #3786

@marcinlesek

Description

@marcinlesek

What is your Test Scenario?

edit: When I added URL Filter to Hook, it's works - so case is only without it.

I'm trying to add custom HTTP header without any URL filter to few fixtures or tests.

What is the Current behavior?

The whole fixture couldn't load and hang on TestCafe splash screen with CONNECTED information. When I removed .requestHooks(hook); from fixture or test chain, it's work as expected.

When we'll check network info during loading, TestCafe is still sending requests to browser heartbeat (Request URL: http://192.168.1.183:52055/browser/heartbeat/7bPNpzU) and get 200 OK with response but without url property value:

{  
   "code":"ok",
   "url":""
}

What is the Expected behavior?

Fixture or test with .requestHooks(hook); method should load and execute properly.

What is your web application and your TestCafe test code?

I'm using your example test and example HTTP request hook to easily allow to reproduce it.

Your website URL (or attach your complete example): http://devexpress.github.io/testcafe/example

Your complete test code (or attach your test files):
import { Selector, RequestHook } from 'testcafe';

class MyHeaderHook extends RequestHook {
  constructor() { // btw. TestCafe crew, you could remove constructor from your docs here, it's useless when you're not passing requestFilterRules or responseEventConfigureOpts
    // No URL filtering applied to this hook
    // so it will be used for all requests.
    super();
  }

  onRequest(requestEvent) {
    requestEvent.requestOptions.headers['MyHeader'] = 'MyHeader value';
  }
}

const myHeaderHook = new MyHeaderHook();

fixture`Getting Started`
  .page`http://devexpress.github.io/testcafe/example`
  .requestHooks(myHeaderHook);

test('My first test', async (t) => {
  await t
    .typeText('#developer-name', 'John Smith')
    .click('#submit-button')

    // Use the assertion to check if the actual header text is equal to the expected one
    .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
});
Your complete test report:
$ ./node_modules/.bin/testcafe scenarios/hook-test.js
The "src" option from the configuration file will be ignored.
 Running tests in:
 - Chrome 74.0.3729 / Mac OS X 10.14.4

 Getting Started
^CStopping TestCafe...

I forced exit due to few minutes without any result.

Screenshots: Screenshot 2019-05-13 at 11 26 24 AM
Config file:
{
  "browsers": [ "chrome" ],
  "src": "scenarios",
  "reporter": [
    {
      "name": "spec"
    }
  ],
  "screenshotPath": "screenshots",
  "takeScreenshotsOnFails": true,
  "screenshotPathPattern": "${DATE}_${TIME}/${TEST}/${USERAGENT}/${FILE_INDEX}.png"
}

Steps to Reproduce:

  1. Copy whole fixture with hook class
  2. Copy config file to .testcaferc.json
  3. Run TestCafe via $ ./node_modules/.bin/testcafe
  4. Check that TestCafe couldn't fixture/test page

Your Environment details:

  • testcafe version: 1.1.4
  • node.js version: v10.14.2
  • command-line arguments: -
  • browser name and version: Chrome 74.0.3729
  • platform and version: Mac OS X 10.14.4
  • other: -

Metadata

Metadata

Assignees

Labels

STATE: Auto-lockedAn issue has been automatically locked by the Lock bot.TYPE: bugThe described behavior is considered as wrong (bug).

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions