Hello, hello, hello, my name is Kevin and welcome, welcome, welcome. Today we are back
we are back, we are back with um the last, the last time video I did was around um page
object model, right? But it was a theory, process theory on a page object model
right? And I showed you this this page, right? So today we're gonna do some code pitch contract model
right? And try and get some implementation going, right? So all of this stuff will be on previous videos as well
right? So page model, the actual um putting it all together in an implementation video
right? This will take a while but let's go, let's just go with it
right? So our first page, if you remember would be this page
right? Page that actually the us it captures our user interaction, right
So let's create our first recruit office class map, right? Recruit office
first class map on this class file. Um We're gonna be using um
website called uh orange, you know orange, right? For, for our demo site
right? So we just call this, uh we just call this login go into a
hr M admin, right? So we call that log into each R M at the So this is our first
class, right? Our first class um which is gonna contain the all the user actions
that we're gonna be carrying out on our page, right? Which is an orange S R M
right? So we know that the first thing to do for this class file to run in serenity
you need serenity, run a class, right? So we we won't use this annotation run with right
Open. I'll close brackets along with any type of is there not dot
dot class? Mhm Too many class do class, right? So we hover over on and import that right
So, so far so good, right? This our test is gonna run in serenity because we have the serenity on the class right now
We want to uh have a browser, right? We want to be able to have a browser we execute
I mean create a brow, we're gonna use a browser to open our our our um did you want to interact with
Right. So if you go to in serenity, right? We have this serenity um properties file
We've already declared what sort of browser we want to be using in our test case
right? In our framework, right? So and and that's cool browser, right? So all we need to do here is go where cab
driver flavor and that, right? But we need
to hover over this and import that package right, import the driver package
right? So that's also in initialized our our browser that we're gonna be using
which is chrome, right? And also we've come across an annotation called manage Finances
This has to be capital, capital N managed, right? And this managed annotation is also serenity
right? It's also an annotation from serenity and it allows you uh to to
to manage your browser. So it opens and closes your browser every time you run a test
right? Yeah. Every time you run a test. So, so far, so good with all this uh serenity
we are, we are we are using so far the serenity annotations, right
So now we are really try to test, right? So who we all we do is public
public void and what we want to call our test, what to call our test a lock in two
uh orange hr M right? Open, close
Um And we just want to open our bras and
close our business, right? Sorry, get seven out of the way, right
So that's our our test structure rating, right? And we know that to
to run our test, right? We need to test, we need to test annotation
right? Which is test in G unit, we need to test annotation
right? So we go over that right? So now this structure is in place
right? This structure is in place. The first A a um the first class
first class file that is gonna hold all our um interaction, the user interaction with our page
right? This is a first class math. So we know that this is gonna hold the user interactions
Now we want to create methods around those user user interactions, right
And those methods that we're going to create, we want to hold it on a separate class file
right? We want to hold it on a separate class file. So if we go back to our um drawing here
right? So we have created this page, right? And now I want to link it to this one
right? So this page holds all our user actions, right? And this page we want to create methods for
those user actions, right? So let's go back. So here we can either go
and create this manually or here is something that a serenity allows you to do
right? If you say, oh I want to create a new class, right
And in here just call it, call this in a new class home page
right? And then just go home, right? And once you hover over here
serenity actually asks you if you want to create this as a class file
So now if you click onto that and it says yes, it's it gives you this pop up
Now, I don't want to, I don't want to put it into this package, which is this package
I want to put it underneath this package, right? This package here, right
So I see browse and then I select my own package and I say finish
right? So this is our method, our method class created our method class ma sorry
our method classified, right? This one that's what created this, right? So now we can start writing our methods
right? Those our methods. Um So the sort of things you might want to say if you go public
right? Great, right? The first of the thing you want to do when you
when you arrive on, onto your, onto your web page that you want to interact with is probably the title
right? So you see, OK, fine Fight title, right? Open and close
that and then, right? So that's our
first method. Our first method is to verify the title, right? And once you verify the title
you make sure you're on the, on the right page because our page requires a um a
a log in, right? So a user name and a password, right? User name and a password
So next one I want to probably see is enter user
name, pass word, right? So that's our our second method, enter user name
password, right? And the next, oh, sorry, I'm just copying on past this
right? And to waste too much time. And probably when you've logged in
when you've logged in to another page, so you logged in and probably a dashboard is displayed
right? So you want to call it is very fine dash, right
Verify passport, right? So now we have this in
place. We go back here, right? We go back here to our main where our main test class where all our user actions
are gonna be right here. Here we have several user actions. Now
this is key for serenity, right? On your main page where you have all your user actions that you're gonna be modeling all your user
actions, you have several actions there, right? So you use a annotation called steps
Now, this step stands for the several annotation, I mean several um actions you're gonna be carrying on on this page
right? And you input that, right? So on your main page, you will be carrying
carrying out several user actions, right? But on your method speech, you're gonna be breaking down those single er those
er user actions into single steps or into single methods on your method space
right? So here you want to use the artery a annotation called a step annotation
right? And then just hover over that and import the package right
Now, you want to put this on every single a method that you want to be carrying out and
everything. Another cool thing with um serenity is that you can actually see what you're gonna be doing in this step
right? So you can see this is to be uh
time, right? But it's completely because it needs this and then quotations or not quotations but not
close. Yeah. Right. So that's why I was completely right. And then you could see in this one you could see and
this let oh milk
No yet. But again, not a good person marks like
a, again, this one there's no see this, this ST
yeah. Oh
then um gosh, that's what I we
need to do. Open and closed, right? So now this is our
our, our methods, er our methods, class and our methods. Class fier
right? A method class fier. Now when this is a shell or methods class right now again
as we gather from our um theory or vision on page object model theory
um we need a third class file that's gonna hold our test code
right? That's gonna hold our test code. So we want to create I can
right? So we're to new class and then we want to call this orange which
are um called, oh I see test quote test just
got it now, right? So click finish right in. Yes. Well, we want to have the all the actions that we're going to carry
out. But here we're gonna be have the methods and the test
the test code, right? Test code. So again, same matters want to carry out
we just write out to the public. I'm worried 35 type
two, right? And the po includes the presets. So that's our
first test to write. I mean the first test coach to write on to verify title
Next one will be to next one will be to password
and then next one would be to verify dash but really
gosh, passport, right? So we got another empty, empty, empty skeleton here for
a a class, right? And this is gonna hold our desk, our our code
right? So we want to go back to the methods, right? And in here 12
we're going to link this and see the actions we're gonna be doing
right? So this method as gonna be linked to this code, right
We've already now we want to link this page, right? So we want to link this page to
our method speech, right? I want to link this page to our method speech
right? So we call this again home, right? And there we go
All right. And all we could do now from this page to call our test code
right? All we could do from this page to call our test code is just to type who dot I'm
sorry on the wrong, on the wrong page. So on our methods page
all we want to do to call our code page, which is our code, er our code which was not written yet
All we have to do is just go here and go home a lot. Very fine title
right? And that's all we have to do there. And there is only four uh enter user name
password, right? And the final one is dot verify dashboard, right
So our methods, file is complete. Our methods file is complete, right
So now let's go write some code that goes with our methods
right? Let's write some code that goes with our methods. And here we go
we have him, I wanna get driver which is serenity as well
Cad driver dot Nope, not insight can drive a dot ok. Just
right outside thought and
your beans. Yeah
it's definitely can drive a dot We
want to find our, I want to make sure she gets Mhm
Yes. Want to get the title right when you title. So we
have to get OK. No, but
right. See why, see why that's not because here now this is this is good
This is good because we need to extend this page to get web element facades
right? I'm trying to type in web element facades and it's not happening, right? So this is very good that you
you got that right? So you all you have to do is you have to extend this class file
right? Extends this class file to get pi object class, right? So you could get a
web Element facade, right? So hop over here and put that, that's why I was typing the code for
for, for um serenity and it wasn't coming up, right? So get a driver dot No
not do you have to do first and then dot And you would get Thank
you, right. So that's us, we've said get driver and we've got that title right
But this is gonna be returned in a string, right? It's gonna be return in a string
So we go to retaining the strings or what we call this
we call this a too bye. So we retained that
in our string, right. We'll retain our title in a string and then we can use this now to do an asset
right? Assert A dot Password. And they could say, oh no
no, no, no, no, no, I don't want to, I, I really want to er Right
Absolutely. I wanna use do as uh
true. I also want to go with true, true and bull, bull condition
right? Boot condition. Now we go with type two. So true. If type two contains
right? If title contains, yeah, orange
Italy orange hr M bye. So now that's
that one. So if your title contains orange, then ok, then
that, that passes, passes that condition, right? And uh so you're on the right page
right? And now all we have to use for seven. It now with um um the
the element facade you have watched before. All you have to do is a dollar sign and then it sign by dot And then you
use ID dot id, right? And
or we need to put in here and then do, ok, I G dot
What do you want to pass here? So what are we wanting to do? We want to say enter on a type
So I want to say type OK. What do you say? So I type in uh
the user name, right? So it would take him right? I never close up and then in here
we'll put in our, I've already done the inspect, right? So I know what the the ID um element is or what it's called
Let's open our orange hr M page, right? So that we have it open there
So you can actually see what the page is, right? So this is a page we're trying to model
right? Uh So let me grab, do you use any for? All right
So I'll put it in here. Now. We want to do the same and we want this
I want to enter password, right? So I want to do the password and then here as password
pass. What? And yeah, here I want to say type and enter
right? So I want to say type dot dot type and enter Selenium
allows you to do that. And the password I want to enter is admin 123
right? Admin 123. I don't want to close down, close off, right
So, now that's you done, right? That's you done with your uh your user password
And here we want to do the same thing, but this one is a URL
right? So we say get driver dot Current. Hm. It's
not giving me anything there that I again, I forgot to use my open and close brackets
site dot print. So current URL, right. That's all right
Again, this, you can return a string. So I say string, I would call that correct
You are of pickles, right? And again, we just do our asserts
right? So these are things that would you wanna assert? Oh, sorry
not OK. Down here you have salt uh dot Don't
assert again, it's true. Right. True bull condition. And you
say current you are pale dot
contains dot contains gosh. Yeah
Right. And that's a good, that's a good er a, a class finished
right? That's a good class finished. So we finished our code er code class or test code class
This one. Can we finish this one? And now we go back to our main class file
our main class file where we want to run our test, right? So here we want to be able to say driver dot
g get your right and then we pass in our URL for a while
right? Copy this, let's close this so that it doesn't er close this so that our
test doesn't get confused when you try to run anything. No, the actions we've done now is
to go the URL, right? To go the URL. Next, I want to all the user
user actions that we carried out, right? That we've made a, we've had methods for and now we have test kits for it
So we just work home dot 35 they talk or
dot P user password? Nice then dot
Verify dashboard, right? And that's our test complete. That's our test complete
Right? I know you've watched this theory video which had this. So that has made you understand this a little bit more
right? So what happened is this is our main classify our main class fier whos the um the interactions that we're going to do on
the, on the page, right? The page that we are trying to look into, which is our orange orange hr M page
right? And we have to link this page this uh main page to our home page
which is gonna hold our methods, right? So that's how we linked this one to this page
right? And this page holds our methods, right? Hold holds all our methods
Don't forget for serenity, your main page will carry the annotation steps
right? Because it's got it's got these steps, user actions here, right
And then on your methods page, you split down the step, the method
the the steps into single steps, right? Single steps with the single methods right
Now that carries the annotation steps, right? And then we've linked our methods page with our test code execution page
right? And then we've written our code in here, right? So now if you go to our main test and our main file and we
run this and we'll see what happens, right? See what happens. Fingers crossed
this works, right? And uh, if this works, I'm gonna leave this just now because the
videos got too long. Right? And we're gonna, uh, see how we get the reports in the next video
Ok, see how we get the reports in the next video. Hopefully this runs and passes
I forgot to extend my, my, my test class file to show
Um, so now we can get some, er, pick up your classes class
right. There we go. Well, that held that we tested him and logged in
right? And then it's got dashboard on there, right? So you should close this automatically
If it doesn't, then that's it. So test passed, right? Test passed
So this is too long right now, right? Um I've gone on trying to refresh here and um I'm trying to get the reports
but um we'll do that in the next one, the next time, next feature
we'll see the reports from this test. Ok. Hopefully that um explains the implementation of a page model
And um my name is Kevin. We try and remember we are trying to improve ourselves in this channel by of skilling
ourselves and learning new technologies as we go along, right? Which would help us
you know, 9 to 5 would help us in if you want to go to do any um gigs on by yourself to make some
extra cash. Ok. So my name is, and I'm signing up. Bye