You've got five minutes to purchase. Amazon did this to me the other day, five minutes to purchase, and I was like freaking out, and I went, you know, do I buy it? And I didn't, and then I refreshed the page, and it came back again, so like cool. So how would you test something like this without having to wait five minutes?
So you'd do the clock.install, and then basically expect the flash offer to be visible, right, so you've initialized the clock, and then you're expecting something to be visible, and then you fast forward by five minutes because then the flash offer is gonna be finished, and then you'll expect what happens on that page. You're gonna expect the offer expired to be visible. So that's how you run that test.
Let's have a look and see it in action. And my test passes, and you can see there my clock initialized. I've got five, countdown, and then I see the flash offers there, and then I basically fast forward, and I get my offer expired. So that's how you test something like that. Again, make sure it's using things like date.now and not something coming from the backend.
Cool, what about set up tests? So what about when you have something like a login scenario, something that you wanna do before other tests? So I've got a demo to show you this. Again, mpxplaywritetest-ui to open up that UI mode so that you can run your tests and play around with things a lot easier. So what we're gonna do here is I have a movies site where I need to log in to manage the list of movies. So my movie site needs to be logged in, and I can basically look up here in the UI mode because I've got UI mode open.
If I click this little thing, I can click on the setup test. I wanna show, I wanna see that. So that's hidden from it for you. You can click that to basically see it. So I've got my setup test, and I go and run. Now watch, I just run the add and delete a movie test, but it automatically ran the log in, the log the user in test, and then it went and ran the movies test. So it depended on it. The setup was run first. And then I can quickly run along. This is the really long test about adding a movie into my movie list so that I can create the movies that I wanna watch, et cetera.
So here is, again, really, really cool test. See how the UI mode, you can really easily see anything. You can click something there and expand that timeline, which is great for debugging and checking things out. My source code is down below. You've got everything else easily at hand to you. So how does that setup work? Well, basically, let's go back to VS Code, and you can see here my login.setup.ts file.
Comments