chrome 远程接口 ECONNREFUSED 127.0.0.1:9222

问题描述

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

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


//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

解决方法

请看一个类似的问题: 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);
});

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...