node.jstestcafechrome-devtools-protocoleconnrefusedchrome-remote-debugging

chrome remote interface ECONNREFUSED 127.0.0.1:9222


I am using Testcafe and it does not have direct support to access Chrome Dev Tools. My Aim is to cut the network so that I can see the error dialog in the website. This is the code that I have written. TestCafe opens at a different url Here is the URL: http://192.168.0.123:52678/someRandomStringHere/https://abcdefgh.com/abcdefgh/

I am unable to configure the parameters for this url. FYI, the port number changes, it is not fixed. Can someone please help me with this.


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

Solution

  • Please take a loot at a similar question: How to run TestCafe tests with throttling connection?

    Moreover, in the TestCafe repository, we have a test that emulates Network throttling: 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);
    });