TestCafe:无法完成对URL的请求

dap*_*985 4 testing automated-tests e2e-testing testcafe

摘要

在我们的Web应用程序上部署后不久,我们便进行了烟雾测试。有时,首次登录需要花费一段时间才能登录页面。

错误

- 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.
Run Code Online (Sandbox Code Playgroud)

可能的解决方案

我希望setPageTimeout在“角色” 中添加可以解决此问题,但是,直到星期二我才能确认。

任何人都可以确认是否setPageTimeout要走吗?如果没有,是否有可用的解决方案?

示例解决方案

- 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.
Run Code Online (Sandbox Code Playgroud)

Vla*_* A. 5

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;
});
Run Code Online (Sandbox Code Playgroud)

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.