Comments (10)
To answer your questions:
but is it possible to change this timer value
Yes, all DOM based commands support options and you can just pass {timeout: num}
as the options.
I just tried this and actually there is a bug with the timeout implementation so I will release a patch for this. What I've written below won't work until this patch is released.
Is it also possible to limit the rate at which it polls the given function?
Yes, pass {interval: num}
which changes the interval at which it will retry. By default this is 50ms
.
Neither of those options are documented and so I'll make myself a note to document them.
However, you shouldn't ever have to explicitly wait as you are doing. The reason cy.wait(num)
exists is mostly for debugging purposes.
Instead of explicitly waiting, simply describe the state of your application that it has to be in, in order to proceed.
For instance, after the animation runs, when it completes, what are you trying to assert? Will something appear? Disappear? Will a class be added or removed?
The correct way to write this is by using command options and/or selectors which will simply put Cypress in a holding pattern until the state resolves.
Here's an example. Let's assume after we click the button that some message will animate in and take 5 seconds before its finished. When its finished a class animation-is-done
is added to the element.
cy
.get("button").click() // this causes the animation to happen
.get("#animation.animation-is-done", {timeout: 10000})
// now perform additional commands below
// since our animation is guaranteed to be done
That's all we have to do. Cypress will retry the 2nd cy.get
until it finds an element with that id and that class. You don't ever have to explicitly cy.wait
.
By default Cypress will timeout a command after 4000ms
so that's why we need to pass the timeout and raise this up since the animation could take as long as 10 seconds to finish.
An alternative way to write this is by using Cypress's eventually
flag in should
.
cy
.get("button").click() // this causes the animation to happen
.get("#animation").should("eventually.not.have.class", "animating", {timeout: 10000})
// now perform additional commands below
// since our animation is guaranteed to be done
BTW: a 5-10 second animation is extremely long, and all your tests around this will take forever to complete. Perhaps you can either turn off the animations, or simply call into the functions which may run at the end of the animation and just test the state there. Often you don't necessarily have to reproduce every single step leading up like a real user would do, it's fairly easy to just reproduce the state you're trying to test using real methods and functions instead of the interface.
from cypress.
Hi, thanks for the answers :).
Yeah, I assumed wait(num)
was more for debugging.
What I'm waiting for is four roulettes to finish their spinning. The roulette is almost like this one here (expect that there are four wheels and more images): http://demo.st-marron.info/roulette/sample/demo.html
They get a status of "spinning" while they're spinning. Absence of "spinning" means the roulette is not spinning.
I initially wanted to do something like
cy
.get('button').click() // start roulette
.get('.roulette').wait(function ($target) { // wait for roulette to finish
expect($target).not.to.have.class('spinning')
}).then(function () {
//New text with information is visible
});;
Your last example with the eventually
flag would probably also work.
As you mentioned, it might be too long to wait and I might consider skipping the animation and just test the state.
Will you update this thread when the updates to enable {timeout: num}
is available?
from cypress.
Yes I will update the thread. I'm trying to finish up a large group of features for 0.7.0
, and then I'll fix those bugs. I'll try to finish all of it at this weekend or Monday.
from cypress.
I released 0.7.0
today. So tonight I'll start on these bug fixes.
from cypress.
I released 0.7.1
tonight which includes the bug fix for setting {timeout: 10000}
options in DOM based commands like cy.get
, etc.
I haven't yet added in support using the eventually
flag with cy.should
, so I'll leave this issue open until I make a few more upgrades. Part of these fixes is for a larger upgrade affecting other commands.
Your primary issue should be fixed now though. Make sure you update Cypress and let me know if everything passes.
from cypress.
Works fine now! Thanks!
There's one small issue/request I have with the feedback, though. Is it possible to ignore or hide the failed assertions (as long as the assertion passes before the timeout) ? Or possible just limit the assertions by having one list item specifying error with range 4-x (assuming it's the same test with the same error), and (x+1) would be the assertion that passes.
from cypress.
Haha. Yah. Those errors should all be grouped under one single failure. I'll make a note and fix that at some point soon.
On Jun 22, 2015, at 3:21 AM, William Almnes [email protected] wrote:
Works fine now! Thanks!
There's one small issue/request I have with the feedback, though. Is it possible to ignore or hide the failed assertions (as long as the assertion passes before the timeout) ? Or possible just limit the assertions by having one list item specifying error with range 4-x (assuming it's the same test with the same error), and (x+1) would be the assertion that passes.
—
Reply to this email directly or view it on GitHub.
from cypress.
Actually can you open a new issue with the error grouping? These are two different things, and once I upgrade .should("eventually"...) to accept options I can close out this issue.
from cypress.
Ok, created a new issue :)
from cypress.
Fixed in 0.11.0
.
You don't need to provide the timeout
options to the assertion, instead just apply the timeout
option to the command that precedes the assertion and the assertions will automatically retry until that timeout
has been reached.
from cypress.
Related Issues (20)
- Support Dark mode for all Launchpad UI HOT 3
- Cypress Test Runner - Autoscroll isn't working for the pinned elements if they're at the bottom of the page HOT 1
- Outdated text on https://example.cypress.io/ HOT 6
- Error when using Cypress.require in a cy.origin HOT 1
- `@packages/example build` prepares incomplete deployment example website HOT 1
- Cypress UI doesn't display on laptop screen upon disconnecting external screen HOT 1
- Error : certificate has expired HOT 5
- Custom assertion messages create confusing output in Cypress open HOT 2
- Cypress crashing HOT 3
- Cypress open hangs for a minute or two before loading HOT 7
- Only first test runs with Firefox 124.0 HOT 8
- Cypress Runner and Cypress Cloud running Different Commits From Main
- Can't omit --ci-build-id when running Cypress in Webapp.io HOT 1
- Open in IDE does not work HOT 1
- Cypress hangs often or crashes. In test runner it takes forever to load. HOT 3
- Cypress Component Testing with Local Storage HOT 3
- Internal test hanging: 'stores viewport globally and does not hang on re-runs' HOT 2
- fix: unskip rerun.cy.js for chromium browsrs HOT 1
- Cypress configuration error empty stack trace
- Firefox 124 + Cypress 13.7.1 The browser never connected. Something is wrong. The tests cannot run. Aborting... after first test with multiple tests on CI HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress.