Excellent. Okay, so Melad has our next question and also news for you. They started using Cypress three months ago. They have a problem though when I use it which is I can't handle lazy loading. The only option I know is the wait command but the lazy doesn't load components in the exact amount of time. Do you have any recommendations for handling lazy loading?
Yeah, so this is something that we're seeing increasingly right with kind of modern front-end frameworks that use like leverage lazy loading or for example, sometimes you need to scroll into view in order to trigger it to load. So actually I believe maybe Gleb recently did a blog post or I could talk like a video about this in order to essentially with results that were being dynamically loaded onto the page. And so like with search results, so you would scroll down, wait for it to load, scroll down, wait for it to render. And there's also a couple other things that you can do too. If you're using a front-end store like Vuex or if you're using like Redux, you can kind of tap into your front-end store and essentially force things to trigger to load something. So if you know like what action that gets dispatched in order to render that component, you can go ahead and dispatch that manually the Cypress in order to force that to happen. And then there's also always gonna be essentially asserting that the DOM is ready. And so laser loading can be difficult but if you understand what will trigger the load to that component, then you can really work with that in order to ensure that it's gonna appear on the screen, whether that be a scroll, whether that be a click. Sometimes I've seen people where they'll like, they'll type in the button, but then what they click on doesn't act, isn't actually the element that loads, that fires the event. So they're not just like, they're just kind of not grabbing the right element. So a lot of that is just really understanding your application and what is causing those components to load.
I couldn't agree more. Like understanding the state, once you know the state and also sometimes are you trying to test the lazy loading? Like, can you turn it off? Because sometimes these things are just there to be nice to have, you know, bit of flare, bit of style, but if you're not trying to test the flare in style, turn it off, make your life easy, make it easier to test these applications. That's a really great point, Richard, for sure. It's like, what are you trying to test, right? And if it doesn't need to be tested, then maybe just don't enable that in your test environment. So that's, that's a good point. Exactly. Question from Amanda Law. Hopefully a relatively simple one, I reckon, but can you stub HTTPS requests and responses? Yeah, absolutely. Yeah, so that is actually, I think one of the options in that dynamic matching that I mentioned is for HTTPS to only match the secure requests, I believe. Jobs is asking us, is it possible to store a general intercept method and call it throughout different tests with a slight modification to the variables? Yeah, I would recommend something like a custom command for that. So essentially, in Cypress, you can declare custom commands. So I would recommend essentially passing through, like if you want like a certain query parameter and call it like sci.intercept with query and then you can pass through whatever the query parameters are and then have the sci.intercept declared in there. But yeah, absolutely. Excellent.
Comments