Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestCafe: Failed to complete a request to url

Summary

We have smoke tests that run shortly after deployment on our web application. Sometimes it takes the login page takes a while for its first load.

Error

- Error in Role initializer -
Failed to complete a request to "https://myurl.com/account/login/" within the
timeout period. The problem may be related to local machine's network or firewall settings, server outage, or network problems that make the server inaccessible.

Possible Solutions

I'm hoping that adding a setPageTimeout in my Roles will solve this issue, however, I can't confirm until Tuesday.

Can anyone confirm if setPageTimeout is the way to go? If not, is there a solution available?

Example Solution

import { Role } from 'testcafe';
import { config, pageWait } './config/config';
import { loginPage } from '../pages'

const defaultPageTimeout = 5000;

export const orgAdminRole: Role = Role(config.baseUrl, async t => {
    await t
        .setPageLoadTimeout(pageWait.extraLongPoll)
        .typeText(loginPage.userNameInput, config.orgAdminUser)
        .typeText(loginPage.passwordInput, config.orgAdminPass)
        .click(loginPage.loginButton)
        .setPageLoadTimeout(defaultPageTimeout);
}, { preserveUrl: true });

export const userRole: Role = Role(config.baseUrl, async t => {
    await t
        .setPageLoadTimeout(pageWait.extraLongPoll)
        .typeText(loginPage.userNameInput, config.user)
        .typeText(loginPage.passwordInput, config.userPass)
        .click(loginPage.loginButton)
        .setPageLoadTimeout(defaultPageTimeout);
}, { preserveUrl: true });
like image 651
dapperdan1985 Avatar asked Apr 18 '19 16:04

dapperdan1985


2 Answers

UPD: Use the following API to configure your timeouts:

  1. --page-load-timeout-ms
  2. --ajax-request-timeout-ms
  3. --page-request-timeout-ms
  4. Test.timeouts Method

Old answer: The reason of this issue is the request timeouts. So, using setPageLoadTimeout is not a solution in your test case.

As a workaround, I suggest you change the request timeouts:

import { Selector } from 'testcafe';

// Import DestinationRequest from the testcafe-hammerhead module. Please, specify your own environment path.
import { DestinationRequest } from '../../../../../../node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request';

fixture `Fixture`
  .page `https://example.com`;

test('test', async t => {
  // Set timeouts
  DestinationRequest.XHR_TIMEOUT = 10 * 60 * 1000; // XHR requests timeout
  DestinationRequest.TIMEOUT     = 10 * 60 * 1000; // other requests timeout

  // Actions and assertions

  // Restore default timeouts
  DestinationRequest.XHR_TIMEOUT = 2 * 60 * 1000;
  DestinationRequest.TIMEOUT     = 25 * 1000;
});

We will consider the implementation of public options to set the timeouts in the context of the following issue: https://github.com/DevExpress/testcafe/issues/2940.

like image 100
Vladimir A. Avatar answered Oct 19 '22 22:10

Vladimir A.


As an addition to the previous answer I think TestCafe have changed DestinationRequest exporting mode. So I'm using as import * as DestinationRequest ....

like image 42
Vlad Moyseenko Avatar answered Oct 19 '22 21:10

Vlad Moyseenko