‫I guys in this video, I want to talk about the hoax.
‫I think most of you already know this, and especially if you are coming from Slonim or any other framework.
‫Basically in Cyprus, we are losing Moga, which means we have access to the Farouk's and it's before
‫and after and before each and after.
‫So let me give you an example.
‫Let's open our last spike and we can implement our hopes here.
‫And let's say you want to run some code or some test steps before you actually start executing your
‫test within the text context.
‫And for that, instead of writing and separate eight for that, you can actually use hooks.
‫So let me show you an example.
‫First book is before oops sorry.
‫Like this before and basically in Puerto Rico the Conqueror.
‫And here again, specify your code.
‫And it doesn't need to be code coming from Cyprus.
‫It can be any code.
‫And the typical example for usage of before hawk can be when you actually need to set up your test data
‫or context or when you want to call your reset or database function.
‫And for that, this is a good place to use before you.
‫So I'm going to give some comments to what's the actual usage of this book and first, this runs before
‫all those inside describe, which means if you have been described and you have, let's say then a box
‫and before on the top, first in the before, before each of these, it starts to execute.
‫I mean, not each, but all.
‫I hope you understand what I mean.
‫And for example, it's good that you can, for example, set up your test data or test context.
‫Or you can see it or or that the database.
‫And in the case of this test, it would make sense, for example, to take a home page and load it from
‫the before function, you know, so the requisite for this actual scroll down and up is to load the
‫home page, because loading the home page is not in the context of scrolling up or down.
‫And basically, if we have before we need to have after so we have also went after.
‫And basically, after work runs, after all, tests inside described block are gone, which means after
‫all your steps are finished, then it will run this after function.
‫And what you can do here is good for, let's say that clean up or basically if you want to, for example,
‫let me give it on the next line, green cookies or local storage, etc., you know, pretty much in
‫after you would use a lot of like cleaning functions.
‫And I know after hook is not used that often as before, but sometimes you need it.
‫So it makes sense to know how to use it.
‫But that's not all, because before and after and only before the test started and after they are finished.
‫And what if you want to run some code before each of these individuals?
‫Let's say you have like five, eight and you want to run the same code in all of them.
‫So your approach can be that you can go to that step into each of every eight.
‫But of course, that not is dry.
‫And for that, Moka gives us another hook, which is called Before Each.
‫And basically, again, it invokes function.
‫And this works basically the same as before, but instead of running before all it works, it runs before
‫each in block.
‫So runs before each egg block and described, which means if you have five, eight and five times once
‫before each of the start and same we have after each.
‫And again, it grips a function.
‫And this one is similar, except it's run after each eight.
‫So runs after each blog and describe.
‫So, yeah, I think that's pretty much it, uh, I know in most of the cases, you probably will not
‫need to after or after each, maybe even before each.
‫The most useful is before when you basically need to set up your data and context.
‫But it's very important to know that you have all these four options, because when the scenario games,
‫which will require, for example, look, some information after each end is pretty much to do here,
‫or if you are, for example, want to prepare and load some data before Egypt, you can use me for it.
‫So I think that's it.
‫And we can move through next week because we have some more which actually not touch the test preparation,
‫but it works itself.
‫So I'm going to show them in the next video.
‫So until.
‫See.