铬远程接口ECONNREFUSED 127.0.0.1:9222



我使用的是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

请回答类似的问题:如何使用节流连接运行TestCafe测试?

此外,在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);
});

最新更新