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

cypress-promise with async/await not working in Electron

Open llatinov opened this issue 6 years ago • 7 comments

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.

llatinov avatar Jul 25 '18 09:07 llatinov

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

james-hu avatar Jun 27 '19 09:06 james-hu

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 avatar Aug 05 '19 04:08 NicholasBoll

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

NicholasBoll avatar Feb 10 '20 19:02 NicholasBoll

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

juspeeh avatar Jun 03 '20 07:06 juspeeh

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" },

varemel avatar Nov 07 '21 18:11 varemel

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 avatar May 09 '22 19:05 miracllife

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

miracllife avatar May 09 '22 19:05 miracllife