TestCafe:无法完成对url的请求

问题描述 投票:2回答:1

摘要

我们在部署到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 });
testing automated-tests e2e-testing testcafe
1个回答
2
投票

此问题的原因是请求超时。因此,在您的测试用例中使用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;
});

我们将考虑实施公共选项,以便在以下问题的背景下设置超时:https://github.com/DevExpress/testcafe/issues/2940

© www.soinside.com 2019 - 2024. All rights reserved.