cypress-promise icon indicating copy to clipboard operation
cypress-promise copied to clipboard

cypress-promise is not working when you run the suite using cypress run command - with Electron and/or Chrome

Open stefacas18 opened this issue 5 years ago • 10 comments

I'm using this library to implement async/await with cypress, if I use command cypress open, everything is working as expected, but if I use the command cypress run / .cypress run --headed or cypress run --browser chrome, the suite is freeze in the first promisify that I use in the test scenario.

Cypress Version 3.3.2 Electron Version Electron 61

Screenshot 2019-07-09 at 17 04 11

stefacas18 avatar Jul 09 '19 15:07 stefacas18

I'm having the exact same issue

CamiloManrique avatar Aug 05 '19 03:08 CamiloManrique

Interesting. Cypress really doesn't want to work in this way. I wonder why it is getting stuck. It could be due to some internal changes in Cypress code. The library really isn't much code (about 20 lines): https://github.com/NicholasBoll/cypress-promise/blob/master/index.js

It seems the fail event isn't being fired in this scenario.

NicholasBoll avatar Aug 05 '19 04:08 NicholasBoll

I am having similar issue. When I run cypress test on ui. It works but when I run test with cypress run command it throw error like Error: can't serialize object of unregistered class

"cypress": "^3.4.1", "cypress-promise": "^1.0.2",

Below code works with Chrome but throws unregistered class error with headless

const length = await promisify(
      getByTestId('dropdownChildren')
        .children()
        .its('length'),
    )
    const elem = await promisify(
      getByTestId('dropdownChildren')
        .children()
        .eq(randomNumber(0, length - 1)),
    )
    elem.click()

this code passes test without error

getByTestId('dropdownChildren').children().its('length').then(length => {
     getByTestId('dropdownChildren').children().eq(randomNumber(0, length - 1)).then(elem => {
       elem.click()
     })
   })

intelcoder avatar Sep 25 '19 18:09 intelcoder

@intelcoder That code looks like it relies on promises too much. Why are you awaiting on elem and then using jQuery.click instead of Cypress clicks? Does the following work for you?

const length = await promisify(
    getByTestId('dropdownChildren')
        .children()
        .its('length'),
    )
getByTestId('dropdownChildren')
    .children()
    .eq(randomNumber(0, length - 1))
    .click()

NicholasBoll avatar Sep 25 '19 20:09 NicholasBoll

I upgraded to the latest version of Cypress (3.4.1) and added a test case very similar to @intelcoder and there wasn't any issue. Perhaps something more complex is going on?

NicholasBoll avatar Sep 25 '19 20:09 NicholasBoll

Thank you for checking.

You mean this one is jquery click
 elem.click() 

this is cypress click ?

.eq(randomNumber(0, length - 1))
    .click()

intelcoder avatar Sep 25 '19 21:09 intelcoder

Yes

NicholasBoll avatar Sep 25 '19 23:09 NicholasBoll

I too am having this issue. (Electron freezing). Here's my info in case it can help resolve the issue:

We're using cypress to do integration testing via the browser but also want to use it to do some API testing as well. Arguably this is not the right tool for the job anyway but we tried it out. Anyway, we setup some endpoint helpers in a js file, like so:

export const doSomething = data => cy.request('POST', '/api/endpoint', { data })
 .then(getData).promisify();
export const doSomethingElse = data => cy.request('POST', '/api/endpoint2', { data })
 .then(getData).promisify();

Then wrote a cypress test using async await:

beforeEach( () => cy.login());
describe('integration tests', () => {
     it('list should support pagination', async() => {  // THIS WORKS
       const list = await doSomething({ limit: 10 });
       expect(list.length).to.equal(10);      
    });
   it('two awaits fails', () => {
     const list = await doSomething({ limit: 10 });
     await doSomethingElse({data}) // hangs before any request to external server
  });
});

This by itself was enough to have cypress fail in electron for us. I was hopeful that since we didn't try to do anything beyond a cy.request for async await that we'd avoid any issues but maybe helps narrow it down?

mmacaula avatar Sep 26 '19 20:09 mmacaula

also meet this issue in cypress 4.9.0, is there any update?

ycwdaaaa avatar Jul 10 '20 17:07 ycwdaaaa

Running into the same issue. Works like a charm with "cypress open", gets stuck on first promisify using "cypress run".

const crossSpecsParameters = await promisify(cy.readFile('crossSpecsParameters.txt', 'utf8'));

karonov avatar May 09 '22 11:05 karonov