Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefacas18 opened this issue Jul 9, 2019 · 10 comments

Comments

@stefacas18
Copy link

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

@CamiloManrique
Copy link

I'm having the exact same issue

@NicholasBoll
Copy link
Owner

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.

@intelcoder
Copy link

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()
     })
   })

@NicholasBoll
Copy link
Owner

@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
Copy link
Owner

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?

@intelcoder
Copy link

Thank you for checking.

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

this is cypress click ?

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

@NicholasBoll
Copy link
Owner

Yes

@mmacaula
Copy link

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?

@ycwdaaaa
Copy link

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

@karonov
Copy link

karonov commented May 9, 2022

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'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants