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 with async/await not working in Electron #2

Open
llatinov opened this issue Jul 25, 2018 · 7 comments
Open

cypress-promise with async/await not working in Electron #2

llatinov opened this issue Jul 25, 2018 · 7 comments

Comments

@llatinov
Copy link

A very good package, it is very needed and makes code easier to read. I have issues with it though.

it('should run tests with async/await', async () => {
  const foo = await cy.wrap('foo').promisify();
  const bar = await cy.wrap('bar').promisify();

  expect(foo).to.equal('foo');
  expect(bar).to.equal('bar');
});

is not working if you run it in Electron browser. I use 3.0.2 version of Cypress which comes with Electron 59.

After several experiments, I found a way to patch the promises to work in Electron. If you wrap your expect(foo).to.equal('foo'); into a Cypress command then Cypress automatically resolves the promise and you do not need async/await:

Cypress.Commands.add('toEqual', (actual, expected) => {
  expect(actual).to.equal(expected);
});

then this works in the test:

it('should run tests WITHOUT async/await', () => {
  const foo = cy.wrap('foo').promisify();
  const bar = cy.wrap('bar').promisify();

  cy.toEqual(foo, 'foo');
  cy.toEqual(bar, 'bar');
});

I know this is not the way it should be but for me this workaround is good enough until cypress-promise starts to work in Electron. I'm open for suggestions that can skip wrapping into command but directly resolve the promise in the tests without async/await.

@james-hu
Copy link

james-hu commented Jun 27, 2019

the workaround probably would still work if you remove ".promisify()" - just put the assignment into the then clause: cy....then(ele => foo = ele)

@NicholasBoll
Copy link
Owner

It's very possible something changed in Cypress 3 that is causing issues with the fail event firing or the Cypress timeout happening.

There isn't much code here (about 20 lines): https://github.com/NicholasBoll/cypress-promise/blob/master/index.js

@NicholasBoll
Copy link
Owner

This doesn't seem to work with Electron or Firefox. The second promise does not resolve.

@juspeeh
Copy link

juspeeh commented Jun 3, 2020

Not working on Chrome either if you run "yarn cypress run".

Only way got these to work is with "yarn cypress open" then run the tests with Chrome. All other browsers fail here.

Any workaround to this issue?

The second promise not resolving at all and always failing with timeout 4000 error.

I'm using Cypress 4.7.0

@varemel
Copy link

varemel commented Nov 7, 2021

I love this module, but its not working in Electron. So, I cant run cypress headless.

Browser: Electron 91 (headless)
CypressError: Cypress command timeout of 10000ms exceeded.

"devDependencies": { "@jc21/cypress-swagger-validation": "^0.1.0", "@openapitools/openapi-generator-cli": "^2.4.13", "cypress": "^8.5.0", "cypress-promise": "^1.1.0", "http": "0.0.1-security", "prettier": "^2.4.1", "request": "^2.88.2", "typescript": "^4.4.3" },

@miracllife
Copy link

I love this module, but its not working in Electron. So, I cant run cypress headless.

Browser: Electron 91 (headless) CypressError: Cypress command timeout of 10000ms exceeded.

"devDependencies": { "@jc21/cypress-swagger-validation": "^0.1.0", "@openapitools/openapi-generator-cli": "^2.4.13", "cypress": "^8.5.0", "cypress-promise": "^1.1.0", "http": "0.0.1-security", "prettier": "^2.4.1", "request": "^2.88.2", "typescript": "^4.4.3" },

have you got the resolution?

@miracllife
Copy link

beside, the cypress-promise seems got command timeout in firefox

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

6 participants