TestCafe:无法完成对 url 的请求

TestCafe: Failed to complete a request to url

总结

我们在 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.

可能的解决方案

我希望在我的角色中添加一个 setPageTimeout 可以解决这个问题,但是,我要到星期二才能确认。

谁能确认 setPageTimeout 是否可行?如果不行,有解决办法吗?

示例解决方案

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 });

UPD:使用以下 API 配置超时:

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

旧答案: 此问题的原因是请求超时。因此,在您的测试用例中,使用 setPageLoadTimeout 不是解决方案。

作为解决方法,我建议您更改请求超时:

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;
});

我们将考虑实施 public 选项以在以下问题的上下文中设置超时:https://github.com/DevExpress/testcafe/issues/2940.

作为对先前答案的补充,我认为 TestCafe 已经更改了 DestinationRequest 导出模式。所以我使用 import * as DestinationRequest ....