testcafe: Allow configurable timeouts for page and XHR requests

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

Any XHR that takes longer than 20 seconds will make tests depending on parsing the response fail

What is the expected behavior?

Either the page load ltimeout or another timeout should be available to make testcafe not fail when XHR take longer than 20 seconds

How would you reproduce the current behavior (if this is a bug)?

Run the below test which loads twp page that retrieve a simple JSON from a remote service using XHR. The first page XHR response returns in less than 1 sec. The second page XHR response returns in 25 seconds. The first succeeds but the second fails because testcafe gives up on XHR that take over 20 seconds.

import { Selector } from 'testcafe';

fixture `Testcafe XHR support POC`

test('the label jsonDisplay should show up the fast XHR response', async t => {
  // The below succeeds 
  await t.navigateTo('http://www.nestorurquiza.com/xhr.html');
  const jsonDisplay = Selector('#jsonDisplay').addCustomDOMProperties({
    innerHTML: el => el.innerHTML
  });
  await t.expect(jsonDisplay.visible).ok();
  await t.expect(jsonDisplay.innerHTML).contains('hello');
});

test('the label jsonDisplay should show up the slow XHR response', async t => {
  // The below fails
  await t.navigateTo('http://www.nestorurquiza.com/slowXHR.html');
  const jsonDisplay = Selector('#jsonDisplay').addCustomDOMProperties({
    innerHTML: el => el.innerHTML
  });
  await t.expect(jsonDisplay.visible).ok();
  await t.expect(jsonDisplay.innerHTML).contains('hello');
});

Using the following command the test ends with the below error:

$ ./node_modules/.bin/testcafe --selector-timeout 60000 --assertion-timeout 60000 --page-load-timeout 60000 chrome  tests/slow-xhr.test.js
 Running tests in:
 - Chrome 69.0.3497 / Linux 0.0.0

  XHR
 ✓ the label jsonDisplay should show up the fast XHR response
 ✖ the label jsonDisplay should show up the slow XHR response

   1) AssertionError: expected 'Result of request should appear here ...' to include 'hello'

      Browser: Chrome 69.0.3497 / Linux 0.0.0

         17 |  await t.navigateTo('http://www.nestorurquiza.com/slowXHR.html');
         18 |  const jsonDisplay = Selector('#jsonDisplay').addCustomDOMProperties({
         19 |    innerHTML: el => el.innerHTML
         20 |  });
         21 |  await t.expect(jsonDisplay.visible).ok();
       > 22 |  await t.expect(jsonDisplay.innerHTML).contains('hello');
         23 |});
         24 |

         at contains (/home/nurquiza/workspace/lms-e2e/tests/slow-xhr.test.js:22:41)



 1/2 failed (1m 05s)

Note that the command sets to 1 minute all the available timeouts. Optionally and for the record, see below the html of this page in case you want to host it yourself. Change the mocky-delay param to have a page to render in 1ms and another in 25s (If you host it you will need to either have the XHR service in the same sub-domain or provide CORS support for the remote service):

<html>
<head>
<title>XHR example</title>
</head>
<body>
<label id="jsonDisplay">Result of request should appear here ...</label>
<script>
const url = 'https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=1ms';
const jsonDisplay = document.querySelector('#jsonDisplay');
fetch(url).then(function(response) {
  response.text().then(function(text) {
    jsonDisplay.innerHTML = text;
  });
});
</script>
</body>

Provide the test code and the tested page URL (if applicable)

See above. Note that this is an issue that will result in tests suddenly not passing after a release just because the responses from the database are slower for instance. The test failure in that case becomes a distraction, a false positive.It would be ideal to have a configurable timeout for XHR responses or use the same page load timeout to fix the currently hardcoded 20 seconds landmark.

Specify your

  • operating system:
  • testcafe version:
  • node.js version:
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
$ ./node_modules/.bin/testcafe --version
0.20.3
$ node --version
v8.9.3

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Any update on this at all? Very keen to see this implemented.

Hello @znar ,

We’ve added an API that allows you to configure request timeouts: https://github.com/DevExpress/testcafe/blob/master/docs/articles/documentation/reference/command-line-interface.md#--ajax-request-timeout-ms. It should be available in the next TestCafe release.