question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress.automation('remote:debugger:protocol') command started failing in Cypress 7.3.0

See original GitHub issue

Current behavior

Starting in 7.3.0, the test code below (mostly copied from https://www.cypress.io/blog/2020/11/12/testing-application-in-offline-network-mode/) throws this error:

CypressError: `cy.then()` timed out after waiting `4000ms`.

Your callback function returned a promise that never resolved.

The callback function was:

() => Cypress.automation('remote:debugger:protocol', {
      command: 'Network.emulateNetworkConditions',
      params: {
        offline: true,
        latency: -1,
        downloadThroughput: -1,
        uploadThroughput: -1
      }
    })
    at https://www.cypress.io/__cypress/runner/cypress_runner.js:136167:24
From previous event:
    at Context.thenFn (https://www.cypress.io/__cypress/runner/cypress_runner.js:136166:13)
    at Context.then (https://www.cypress.io/__cypress/runner/cypress_runner.js:136597:21)
    at Context.<anonymous> (https://www.cypress.io/__cypress/runner/cypress_runner.js:151455:21)
From Your Spec Code:
    at Context.eval (https://www.cypress.io/__cypress/tests?p=cypress/integration/spec.js:133:9)

Desired behavior

The test should run without error.

Test code to reproduce

Set the baseUrl configuration key (e.g. "https://www.cypress.io") and run the following spec. I can reproduce without setting the baseUrl but it’s a little more complicated and I think this is better as a MWE.

describe('page', () => {
  it('tries to go offline', () => {
    cy.log('**go offline**')
    .then(() =>
      Cypress.automation('remote:debugger:protocol', { command: 'Network.enable' })
    )
      .then(() => 
        Cypress.automation('remote:debugger:protocol', {
          command: 'Network.emulateNetworkConditions',
          params: {
            offline: true,
            latency: -1,
            downloadThroughput: -1,
            uploadThroughput: -1
          }
        })
      );
    cy.visit('/');
  });
});

Cypress Version

7.3.0

Other

I encountered this when attempting to update to the latest version of Cypress, but traced it back to 7.3.0. Version 7.2.0 runs without error.

It looks like at least a couple other people have encountered this based on the comments on that blog post. I found that modifying the callback in the second then to not return anything did allow my tests to get further, only to hang indefinitely at random places in my test file so, as I suspected, that isn’t a real solution.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:28
  • Comments:20

github_iconTop GitHub Comments

9reactions
weilucommented, Oct 27, 2022

Can we please get this working? None of the workarounds above works anymore. I hate to be stuck with version 6.9 because of this

5reactions
szhong-beclscommented, Aug 26, 2021

According to my investigation, this issue may be injected by this commit in socketio/engine.io-client repo. It supports a listen to the "offline" event feature in version 5.0.0 (2021-03-10).

The problemic code is as follows:

+ if (this.hostname !== "localhost") {
+   this.offlineEventListener = () => {
+     this.onClose("transport close");
+   };
+   addEventListener("offline", this.offlineEventListener, false);
+ }

The socket is closed after sending CDP command: { "command": "Network.emulateNetworkConditions", "parameters": { "offline": true } }. Then the command response is never received and Cypress.automation('remote:debugger:protocol', { ... }) is timeout.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress Automation - Gleb Bahmutov
In this blog post I will show how to use Cypress.automation command to set the browser permission and to take native screenshot images....
Read more >
Changelog - Cypress Documentation
Visually warn in the Command Log when the cy.session() command fails to ... 7.3.0. Released 05/10/2021. Features: Component tests can now be launched...
Read more >
Cypress failed to start on Windows - Stack Overflow
Try this npx cypress install --force then use npx cypress open ... and run cypress thro' editor command prompt using below command prompt...
Read more >
cypress - npm
What is this? Cypress comes packaged as an npm module, which is all you need to get started testing. After installing you'll be...
Read more >
Learn Cypress in 3 Hours | LambdaTest - YouTube
Deep dive into the basics of Cypress and various Cypress commands with the Cypress testing tutorial at Lambda Test. Start FREE Testing: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found