TestCafe: Failed to complete a request to url
Asked Answered
C

2

5

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 });
Conflict answered 18/4, 2019 at 16:15 Comment(0)
F
6

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.

Foin answered 19/4, 2019 at 13:42 Comment(1)
Thanks! Trying this out now. I'll see how things run over the weekend.Conflict
C
1

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

Cirri answered 7/8, 2019 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.