【问题标题】:TestCafe: Failed to complete a request to urlTestCafe:未能完成对 url 的请求
【发布时间】:2019-09-09 00:41:39
【问题描述】:

总结

我们的烟雾测试在部署到我们的 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 automation automated-tests e2e-testing testcafe


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢!现在试试这个。我会看看周末情况如何。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多