0

我正在使用 Testcafe,它不直接支持访问 Chrome 开发工具。我的目标是切断网络,以便我可以在网站上看到错误对话框。这是我写的代码。TestCafe 在不同的 url 打开 这是 URL: http: //192.168.0.123 :52678/someRandomStringHere/https://abcdefgh.com/abcdefgh/

我无法为此 url 配置参数。仅供参考,端口号更改,它不是固定的。有人可以帮我解决这个问题。


//Performing some actions using Testcafe here


let config = {
        offline: true,
        latency: 100,
        downloadThroughput: 750 * 1024 / 8,
        uploadThroughput: 250 * 1024 / 8
    };


    const CDP = require('chrome-remote-interface');
    const client = await CDP();
    const {Network} = client;

    await Promise.all([
        Network.enable()
    ]);
    Network.emulateNetworkConditions(config);


//Checking if the error is present or not in website after cutting the network
4

1 回答 1

2

请在一个类似的问题上寻找: How to run TestCafe tests with throttling connection?

此外,在 TestCafe 存储库中,我们有一个模拟网络节流的测试:https://github.com/DevExpress/testcafe/blob/61f3703d50ef8cc64331d09659837c52a9aae862/test/functional/fixtures/regression/gh-3929/testcafe-fixtures/index。 js

import { ClientFunction } from 'testcafe';

fixture `Should reconnect with bad network conditions (GH-3929)`
    .page `http://localhost:3000/fixtures/regression/gh-3929/pages/index.html`;

const getClickCount = ClientFunction(() => {
    return window.clickCount;
});

test(`Click action with bad network conditions`, async t => {
    const browserConnection = t.testRun.browserConnection;
    const browser           = browserConnection.provider.plugin.openedBrowsers[browserConnection.id];
    const client            = await browser.browserClient.getActiveClient();

    const networkConditions = {
        offline:            true,
        latency:            10,
        downloadThroughput: 100000,
        uploadThroughput:   100000
    };

    await client.Network.emulateNetworkConditions(networkConditions);

    setTimeout(() => {
        networkConditions.offline = false;

        client.Network.emulateNetworkConditions(networkConditions);
    }, 5000);

    const expectedClickCount = 10;

    for (let i = 0; i < expectedClickCount; i++)
        await t.click('button');

    const actualClickCount = await getClickCount();

    await t.expect(actualClickCount).eql(expectedClickCount);
});
于 2021-05-13T08:11:31.080 回答