Page Object Model (POM) Design With Selenium - Part -4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to Devine automation labs guys we subscribe to this channel anyways this is welcome again this is Naveen here okay guys so thanks for waiting for the module 4 4 page object model this is a part 4 and I think after that one more part will be there part 5 but this part is very important for designing point of view ways so in this particular part we are going to cover you know how will you implement data-driven approach in the existing frame book and we will know that ok what is the concept of at the rate cache a look up in page Factory and we will see that webdriver fire event also that is very interesting topic to generate the selenium blocks and we will implement our lock for J API also and then I will tell you that how to add extend report to generate the reports and results and everything ok so uh yes recording is on so let me open my Eclipse race so so far we have seen that let me close all these classes so ok so far we have seen that in the last session we covered a couple of things that we'd created number of you know classes like contact page test class home page test class and login page test class and we were executing through test changing dot XML file and through test change it or XML file we have added three classes together and it will be executed in the sequencing mode fine so basic skeleton and the foundation we have already created and now we will see that how can we add the data driven approach ok in our free book so for data driven approach we need to prefer once in our UI let's see I will go to this particular site and this free CRM calm just a minute saving some problem with free CRM let me open in Google Chrome so okay so maybe some problem with Firefox so I'll remove my Firefox okay so this is a free CRM dot-com and after login and do the system what I want that I'll go to contacts page okay I will go contacts a new contact and what I want I enter some values over here let's see I enter dr. and let's see first name is Tom last name is Peter write some mandatory fields so all these are mandatory fields you have to fill so a couple of information let's see we will fill company name is let's see Google okay something like that and then I have to click on save so let's click on save and you will see that data has been added the contact has been added and then I'll go to contacts tab once again and we will see that the Tom Peter has been added or not okay so we will see that we will add number of values we will add number of contacts okay because obviously I cannot add a Tom Peter every time so we will add different set of data from the excel file we will pass and then we will see that okay multiple contacts we are able to create a lot and later on for your practice point of view you can go to other tasks other tabs like deals tasks cases so if you go to deal and if you go to new deal you can add new deed also over here same thing for tasks also you can create new tasks so in this particular video I will cover only new contact and rest of the things you can practice guys because everything will remain same then okay so let's do it and okay but before we start we have to before coming on this particular page what we have to do is we have to go to new contact so we have to mouse over and click on new contact but we know that after login first time we are coming on this homepage right first time we are coming on this homepage and off from the home page you have to click on contacts so we know that contacts link and this new contact link is available on home page so on homepage dot java i will create the method to click on contacts ok to click on new contact right so i'll go to my page ok and this is my page package and i will go to home page and inside this home page and create my click on new contact right so I will create a method public void what is a method name let see click on new contact link ok guys click on new contact link now to click on new contact you remember I covered in actions class that we have to mouse over to make it visible to live okay we have to make new contact to visible then only we can click on it if you directly try to click on it like this it will give you element not found exception we have to make it visible then we have to click on new contact so we have to use actions class right so simple I'll use my actions action is equal to new actions and I'll pass my driver here okay so actions classes are used to cover mouse comment and drag and drop right like all these things so action class is available in selenium so just import it okay and what we have to do after that we have to mouse over on contact action dot we have a method move to element on which element so the contacts link page factories guys we have already created three contacts link page Factory we have only created that we have to mouse over on this particular contacts link so that element object we have already created right so instead of writing driver door find element by Road XPath I am directly passing this contacts link I wanted to find the expert for this so what exactly it will do it will do it will do mouse moment okay and then we have to use dot build and dot perform okay rod builder perform whenever you are using actions classes we have to use it's compulsive to use dot build and dot perform now it will move on that particular element and then we have to click on new contact okay so for new contact I will create one XPath so right click and just a minute just a minute face this is the new contact right click and so I think ok let's create the same expert it will be I think same or let me open in Firefox it will be both clear and it will be visible more clear in Firefox okay I'll open free CRM calm and for a new contact I have to spy in fire paths so that will be a better option that despite new contact what is happening just a minute guys just turn it okay so what I'll do I'll inspect this particular neo contact link and I know that this is a a-okay and the text is new contact okay text is new contact so I will again I'll create the XPath for this just like this okay so what I'll do this is the XPath for element for contacts link and then I'll create for new contact new contact link and this is the text of that particular link so a which contains what this contains text is like this okay so new contact link then I have to click on it after mouse moment so mouse movement and then this dot click okay so it will click on that particular link fine it will click on new contact link so after clicking on new contact link what we have to do is after clicking on new content link we have to fill this particular form and this form is available where this form is available on contacts page right this is the contacts page so what I have to do this okay filling the form method I will create inside we're inside the contacts page now right because this is not this is not the home page now this is a contacts page so I'll go to my contacts page dot Java and here I will create that method to fill that form right simple I'll write one method public and couple of methods we have already very written over there where if I want actually a bill and select contacts by name so I'll write one method let's see public void let's see my method name is create new contactor right create new contact okay so how to create new contact so I know okay I these information I have to fill so one by one and despite all these elements so let's see for this element quickly I'll inspect this is a title and this is a title is available inside a select class and the name is title so this is a drop-down okay so this is our drop-down so for drop-down what we have to do for drop-down we have to select you select class so simple let's see I'm creating one select class select is equal to MU select and I'd have to give the element or driver or find element by dot name name of that particular element that select class okay I have to use select class and then this is a select drop-down so I have to give the element of driver out find element by dot names title and you can create the same thing you can create the page factory also ways okay and you can pass that particular element over here like that also you can iterate so I am giving you both the examples with page Factory and without page factory also it's not compulsory that every time you have to use page factory okay some elements you can ignore paycheck trees also now with select object we have under method select by visible text and what is the text let's see I have to select mr. mr okay so this is a title so what I want I don't want to hard code my value so I will pass one a string variable like this string title okay then this particular title value and pass so while calling this method from a test in G class I will pass this particular parameter okay guys see and then after title what we have to do we have to enter first name so for first name I'll spy first name is again let's see I'll use ID so if IDs available so or I can you can design the page factory quickly over here okay so let's see for first me when design math first page factory first name and instead of expert we have ID available directly so I will be used ID is equal to what is my ID ID is this first name okay ID is equal to this first me and for last name okay we have to enter last name also for last name ID is equal to surname so for last name also well quickly I will create one page Factory and this is my face right element name is last name and ID is surname okay IDs surname fine after that let's see okay so only these two fields are mandatory okay but let's say I want to enter some other information also let's say I want to enter company company also I and company CID is not available so we can use name client underscore lookup okay so I'll use name so instead of ID I'll be using name is equal to this is a name trying to look up the name okay and this element is what company element something like this okay anyways if you want to create for this also you can create for select drop-down also you can create okay so let's see these four or five information I want to fill okay these four or five information I want to fill so now what I have to do so I have all the elements already okay guys all the elements are ready my first name is ready after selecting the title so selecting the title from the drop-down so we have to use select class but now we have simple text fields first name dot sendkeys and whatever the first name you want to enter over here we will pass in the form of a string so I'll pass one more string here let see my first name is okay name something like this or I'll write something like this F F T name first name and comma string LT name and then a string comma company okay so these information L pass so first name and pass over here F T name okay and sorry I added over here guys sorry sorry sorry that's my mistake I need to copy I need to use over here in this method sorry guys okay so title and then F T name and then we have last name so last name dot send keys okay last time but rent he's LT name see guys now this is a basic scenario just simples selenium concept we have to use so I'm not going to waste time in these things easily you can do that and then we have to use comp okay and the company value over here okay so what exactly it will do it will select the title it will fill this value ft name LT name and company name and then you have to click on save so let's spy the Save button also so first save there using input type equal to submit value equal to save okay so I'll create one expert property for that for save okay XPath is equal to and we know that this is a an input field so I'll use my expert will be like this input which contains okay or I don't want to use contain because there is no need of you contains now so simple I'll use in put at the rate class is equal to sorry claw and use type equal to submit and the rate type is equal to submit and one more property we will use this let's see value equal to save so at the rate value is equal to save make sure s capital S capital submit as a small and type T small to be small okay fine and this is for Save button save BTN I'll use like this so BTN and after that we have to click on it so save BTN dot click ok so this is a method I have created for create new contact okay guys so create new content and we are passing all these variables over here and so contacts page we have created like this one method we have created to fill all these values and clicking on save link okay now we have to write two test cases so page layer is done we have to write the test case inside this contacts page test so contact page test let's see three test cases we have already written remember in the previous session and like checking the label and title and you know selecting the checkbox is those things now I'm going to create one more test case in the test cases let's see my test cases public void I'll my test case like this validate create new contact like this right validate create new contact okay and then create new contact what we have to do first time it will come on the home page right so first time it will come on the home page and then it will click on contacts link okay but now what we have to do we have to click on new contact a new contact method okay we have already created clicking on new contact method we have already created on the home page so what we have to do we have already having this home page object so a simple call that method home page dot C click on new contact link three days so click on new contact link we just created right mouse moment by using actions classes inside the home page class so we have home page class object and click on new contact link we have created so it will what exactly it will do it will mouse over and then it will click on new contact now we are on this page right now we have to fill this form to fill in this form we have already created one method inside the contacts page create new contact so to call this method we need contacts page class method so for contacts page class method is already here okay so what we have to do inside the setup method we have already initialize all the methods so contacts page dot create new contact and now here we have to pass the value so let's see first time I'm passing the value mr so the value is let's see i am passing mr dot mr okay and let's see first name is tom last name is see right now i'm just giving the hard-coded values tom and let's see peter and the cheap peter tom Peter is working in Google like this and this is a priority is equal to HM giving the priority is equal to four okay that's a simple test case I have created to create a data validate create new contact okay so first to create a new contact we have to move to click on new contact link like this new content link by using the action class we are moving on that particular element contacts link element and then a new contact link element we are clicking on it so we will be moving to new what we will be moving on this particular page contacts page write this so contacts page will give you one okay okay it will be redirected on contacts page and now from contacts page we have to call this particular method simple right so let's run this only run this method to run this method just select this method and right click and run as test change II and we will see that it is adding these values or not okay fine it's entering the values username password now it will go to new contact fine and then it should see it's entering the values and clicking on Save button simple okay and if you see the test Keys got passed no failure one task is got passed okay okay so we have added one more test case to period the contact but the problem here is and passing these hard-coded values tomorrow if you add let's see 100 contacts if you want to create 100 contacts with different set of data over different negative testing like blank values or garbage value or special character values in okay you have to pass then right so we have to pass every day you probably time you are not going to change the values again and again right so we have to use data driven approach here right so data driven framework we have already discussed with the help of data provider right so case we will use data provider here so quickly data provider first of all I will create my data okay in excel sheet so I will open one excel sheet one excel file i will create let's see my excel sheet name is contacts because this is for contacts let you tomorrow you're creating for deals so you have to create for deals like this offered for tasks you have to create like this tasks like this okay so different data you have maintained in different worksheets so four DS and task guys you can practice and for context and prepare the data for okay for the scenario so I know that I need what are different information I need I need first column is title and then I need first name last name okay and company these four values I need and this is my data so let's see this is my column and these columns let's see I'll provide something like this and my title is let's see mr dot first name is Tom Peter HT company is Google and the second title is dr dr dot LSE David let's see Chris and the company name is Amazon okay company name is Amazon and one more add the team this is okay let's see we will add some lame let's see okay and the company name is even okay so these four values and adding over here fine and I'll save this particular sheet on my let's see first time on my desktop so on my desktop and the sheet name will be I'll write something like this guys free CRM and this test data okay give some proper name and let's see a store over here on my desktop with this data okay and what I'll do I'll go to my desktop and this is a free CRM test data and I'll do I'll copy this copy this and go to my Eclipse and if you remember in the second session we created this package test data package and then I'll paste it over here so I will move my excel sheet over here okay guys I'll move my excel sheet from there so let me close this and I'll open this section sheet now so if you see this is excel sheet I had created which is available inside this package test a data package fine now what we have to do we have to use data provider so I will create one data provider annotation method ok data provider and my method name is G public void get get test it okay and from which sheet let's see I'll pass my parameter get from this particular sheet name okay so we will pass the sheet name from this sheet you want it okay or maybe I'll do one thing that lets you remove this simple kay get test data method I will create ok guys and what I'll do inside my test - util dot Java arrays okay I have already created this method for you ways get test data method I have already created okay so get test data method is accepting one sheet name and it's a very simple logic I have written that very exactly your test data sheet path so my test sheet path over here so I will give me a test sheet path that one static string variable I have created okay so this is my excel sheet so I have to give the path of my excel file and let's see this is my path of my excel file and give it over here okay like this I'll create okay and this test data sheet name this is the method I have created so Kay this method is exactly what exactly doing this method is returning one to dimension object array try to understand this concept now this sheet name it will iterate this sheet on the basis of rows and columns so that I have created two four oops one is for row another is for column and row by row and column by column it will pick the value and it will store in this particular object area okay in this particular array and then I am returning this particular object array see this data the returned the type of data is object array two-dimensional object array so the property of two-dimensional object arrays like this that see it will store the data like this it will start my row equal to two and column equal to 1 like this row equal to 2 and this is the first quantum so whatever the value is available cell by cell it will pick the value it will pick first mr then Dom then Peter then Google ok and then it will pick dr. David Chris and Amazon and then for third row it will pick the data for miss mrs. Mukta Sharma eBay like this okay so it will pick the values like this so that's why I have started my loop this is for Rose and this is for columns see get last row number get class to a number means get last row number like this and then guys get row count you get total number of cell get last cell number so get laughs and number is this so this is a logic you just need to use and why I am using get row I plus 1 because my actual data is available from here so I will just ignore I equal to 1 I will start from I plus 1 so you can use this particular utility this is a very good utility simple one method has created and we just need to call this get test data method okay from our test class so inside the data provider method so let's seek it I'll change the method name somewhere like lets you get test [Music] CRM test data okay and that method is available in test util - test - util dot method name is get test data and what is your sheet name ok so what is your sheet name for contacts what I'll do I'll define my sheet name over here that my sheet name is string sheet name is equal to this is my sheet name contacts okay this is my sheet name context and what I'll do this is my sheet name and pass Sydney so what exactly it will do sheet name is contact it will go over here get test data it will do all these things and then it will return one data that is two-dimensional object array simple what I will do I'll store somewhere in two-dimensional object array so in create like this case object let's see data is equal to this okay to dimension object array I have created very simple so don't be confused at what is two dimension why 2d array we are creating this is in object array the only most of the time be you always used to dimension object array we can use array list also but this is a very good utility that I have created simple you need to call just pass the sheet name it will give you the complete data which is a very okay in the computer which is available inside that particular sheet okay guys now this data is available computer is available in this particular two dimension object array this complete data if you have 100 rows that hundred rows will be stored in this okay now what we have to do this method is returning words I'll use one return statement this data is returning data dot just a minute yeah simple return data and I have to change this void from why - because void min does not return any value so why to object array like this okay so what exactly it will do sis data provider is fetching data from this method and returning data returning to dimension array okay two dimensional array now this is a data provider my data provider name is get CRM test data so I'll use it over here that comma data provider what is your data provider name this is my data provider name CRM data so whatever the data this method is fetching this gets your M data it will pass this method to this particular test case why because inside this at the rate test annotation we are using this data provider who is the provider who is the data provider for this method the provider of the data okay of this particular method is this method because we have written clearly data provider is equal to get CRM data right data provider is equal to get CRM date right and now how many columns are there four columns right so guys we have to create four columns here like this string title comma string first name comma string last name comma string company so guys always remember whenever you are writing data provider using data provider so if the data provider is fetching the data from excel sheet obviously data provider is fetching data from this exegete how many columns are there one two three four same four variables we have to create inside the at the rate test method also it's compulsory otherwise it will give you error it will give you mismatch error a column mismatch error because you are fetching a later from Excel files four columns are there right it means it's compulsory that four variables because this is the data is provided from this method but who is getting the data these four variables are getting the data one by one it means if you have let's see five rows or two rows or three rows if you have five rows 5 times this particular method will be executed right so that concept I have already covered with s20 data provider session so please go through it half an hour session is there you will get to know so many things with respect to data provider okay so now I am passing this method okay wait and now one by one I'll eliminate this thing now so I'm not going to use these hard-coded values I'll pass my actual data from excel file now so simple contacts page dot create new contact what is your title this is my title what is the first name this is my first name what is your last name this is my last name what is a company this is my company okay so one by one I am passing the values and all these values will be given to this particular method create new contact method it will come over here it will select the first value is mr. Tom Peter Google mr. Tom Peter Google second value is dr. David CFS Chris Amazon dr. David Chris Amazon and similarly third value right so I am passing the value one by one like this so I'm eliminating this Hardy's hard-coded values now this is a perfect data-driven approach I have used oh he raised and then quit the browser one by one okay so let's do it let's run this program and we will see that it's actually entering the data or not okay so let's see login now it will go to new contacts and first later Tom Peter Google and save it close the browser again open it login for the second set of data is this is my second data see David Chris Amazon so it will go to new contact now dr. David Chris Amazon and save it fine now the third is mrs. Martha Sharma and eBay it will go to contacts new contact will select mrs. Martha Sharma and eBay and save it and my single test case got passed but it got executed three times okay see three test cases got executed and with this set of data to validate create new account with this set of data where I did create new account with this set of data dr. David Chris Amazon well did create new account with mocha Sharma like this okay so see three test cases gotta execute it with three different I mean same test case you gotta execute three times with three set of data so we have used data-driven approach holds over here okay guys so we can say that this is a page object model with data-driven approach right here I'm not using any keyword driven value so we never use keyword driven with selenium CEO driven is the worst approach I would say hybrid framework we combined in the form of data-driven Plus page object model rates don't use keyword driven okay so I'm not going to cover keyword event tutorials also if people are asking for keyword Durban please I never recommend keyword-driven keyword driven for maintenance point of view it's really difficult okay guys so for data-driven is really good now you can create a data for deals and tasks like this simple now if you see the data is actually added or not so you will go to contacts and we will see that see David MA Tom Peter got added although I have already created two times earlier so okay these values are getting added over here and you can validate that no validation part you can do you can you can put one assertion over here then after create new contact you want to validate how will you buried it you will come to contacts page and you will see that that David Chris got added or not you will verify that okay David Chris available on water simple right like that you can validate okay so similarly you can achieve for deals okay for tasks cases called number of things are available you can do number of data you can add you can create a data from excel file created data provider like this and you can perform it okay so this is a data-driven approach also right I have told you with page proper page object model okay so the second thing is that what is the purpose of a direct cash a loop concept see guys add the red cash loop one sub is a new annotation is available in page factory API what is the purpose of this quickly I will tell you whenever you are defining on the pages lets your home page we have these at the red fine by add red fine by right you can do one thing that after add red fine by you can add one more annotation for this particular element let's see at the rate cache a lookup add the rate cache look up means it's available in selenium only add the red cash will look up means this is the annotation which says that okay it will store this particular user label name okay in a cache a in a memory okay so every time whenever you are interacting with this element instead of from the page it will get that per to the element from the cache it okay so the spirit of your framework speed of your stick will be improved the performance of this script will be improved what exactly it will do because see if you don't try to add the rate here shall look up it will every time if you are calling this method if you call this element let's see 10 times so every time it will try to interact that okay TD which contains user Naveen here like that it will try to get that expert from the HTML Dom but if you write a dread cache a lookup what exactly it will do it will create one small memory and it will store that particular element into that particular memory into that particular cache a that memory is called cache memory and then instead of going to the browser page again and again it will get that particular data from that particular element from cache memory obviously so wait let's see if you are calling this particular method this particular element hundred times so instead of going to the web page 100 times it will pick from this particular cache but the problem here is there is see I will tell you with the one example see try to understand they might ask you at a time of interview okay the thing is I have this particular browser this is my browser and this label is available here in this particular browser okay this element is also available here in this particular browser new contacts link also available here this is the browser let's see this is my Google Chrome this is my Chrome right and I am using this script for let's see these element for 100 times so hundred times I have to attack my browser I have to hit my browser again and again again and again right it will try to get the x1 what I am doing here is by using this annotation at the read cache look up annotation this particular notation base what I am doing I am creating one cache over here simple one more cache memory over here okay this is my cache memory and if you are writing at the ratcatcher lookup it means this particular element is marked with cash it means P's store this element into this particular cache memory okay if you are writing at cache look up for this particular element also it means this particular element will be stored in this particular element in this cache memory also similarly for all the element will be stored if you are declared with the at the read cache look up all the element will be stored in this particular cache memory ok guys so this is my cache memory cm now if you are using this element dot click or dot send Keys it will not go to the browser it will directly pick it from here alright so it's available in your program only it's available in your you know and the in the background so instead of going to the browser you have to go to the browser from here to here and then browser will give you the response at XPath is available or not so let's see there are thousands of elements are there getting called by 10 10 to 20 times it maintains thousand times you have to call the browser again and again alright you have a ten thousand times we have to send the keys and all those things you have to perform I mean I mean you have to validate the XPath or ID or name so instead of doing those things we create one CM cache memory like this so instead of going to the browser it will take all the values all these element from here so sometime it is a good practice that we write at the read cache look up for all the elements like this but the problem here is let's see you are on the home page and somehow that element properties or element is refreshed or page got refreshed let's see the page you got reference then in that case this cache memory will be corrupted some of the element will be corrupted some of the elements will be stale ok in that case it will give you stale element exception ok if the page got refreshed let's see this is the first instance of page and after refreshing the page or maybe some Dom property has been changed the dorm and document object model of that particular page got changed at the run time let's see one this is the new version to get it created okay now this cache memory objects all these elements will be disturbed will be stilled so obviously it will give you immediately it will give you a stale element exception so if you feel that this particular element won't be changed then only you should provide at the rate cache look up you should not use a dread cache look up for each and every element okay guys but this is very powerful to improve your performance of the script your script will be faster if you're using n thread cache look up so they will ask you at a time of interview that how will you improve your script performance so you have to use a dread cache look up ok guys so this is a concept of add the read cache look up ok let me remove these okay now the third concept is what is the webdriver fire event ok what is webdriver fire event see guys webdriver fire event is amazing amazing things to generate this is two for selenium action logs it will give you very good logs see what you have to do you have two guys add one class that is the class name is webdriver listener class in your utility package in your util package web event listener class you have to add C this is the class and this event listener what exactly it is doing this class is extending your base class as well as this clock is implementing your webdriver event listener interface also and this is the standard template you have to use what you have to do we have different actions in selenium right we have before navigate after a navigator okay we have clicking on click method is the sendkeys method is there different find wire methods are available okay so different script level actions we have what you have to do you have to just simple webdriver web web event listener or java class you have to create the exact thing you have to create just copy/paste there is no concept simple webdriver event listener this interface what exactly it will do it it will provides a mechanism that whenever you are navigating to the browser or whenever you are clicking on a specific element it will call these methods one okay it will call these respective methods let's say you want to click on any specific element so it will print it will call this method it will print like this trying to click on element or to string okay what is the element on which element you are trying to click on that you want to click on login button so it will say there trying to click on login button something like that it will say on the console so you will get proper what exactly will get you will get proper error logs I mean the proper console logs you will get the proper exact you know proper language you will get that what is happening during the execution ok so I will provide this webdriver I mean baby event listener dot Java please see the URL in the description of the video and I'll provide that particular java class okay i'll share with you just need to copy paste and provide it over here and one more configuration you have to chain go to your base class ok guys you have to go to a base class what you have to do guys see we are launching our chrome like this web driver driver equal to new chrome driver after that what you have to do you have to create the object of this event firing web driver class event firing web driver class you have to create the object of the see even firing web driver class is available in selenium what you have to do simply create one the reference variable over here let's see I have created Ionesco driver is two new event rival firing driver and pass your driver over here and what where exactly your web event listener D and all the listeners we have created over here so these are the listeners I have created right that obviously this class I will provide to you that is what we just discussed all okay the event listener class I have okay we have this thing you have to create the object of this particular class also so this is the object of event listener is the object of this particular class now you have to register your event listener how to register you have to register your event listener class object with event firing web driver object so this is a method en Dusko driver don't register event listener and what is your event listener imagine astir is the object of this is the custom events we have created okay okay guys and after that what you have to do inside this event okay you guys you can use any name ABCD whatever a door driver or en desu ka' driver whatever the name you want to give you can take but what you have to do you have to create those three four steps you have to write a simple event firing web driver slash object create okay after that this is my event listener class object you have to create and then you have to register your event listener with E and s co-driver which is fine and then you have to okay assign this e and s co-driver to driver just give this particular event listener driver to this particular driver that is our main driver that's it these four lines of code you have to write and this a web event listener template file you have to listen a template file you have to add in your project and then you are good to go now if you run your program very see I'm going to run my program if you see the console output noxee the logs see it's giving you the proper information before navigating to navigated to CRM dot-com and then I'm entering my username okay then I'm entering my password damn I'm interacting with this particular XPath for a login button then I'm moving to trying to find element by sea by it would expand on this particular contacts then element found contacts element found so you can track each and everything over here right see the full expert it will give you whatever that whatever the expert you are using all these experts and each and every information for each and every event it will give it to you okay so you can track from the locks itself from the console itself what is happening in my script okay so this is very important so this is the concept of ways this thing webdriver fire event one more important thing of webdriver fire event you can customize like this base we have one method whenever any exception is coming in your program okay in your script if any exception is coming you can create one listener like this on any exception I want to throw some error fine okay so this is the error will be thrown immediately whatever the exception is tail element exception element not found exception or any exception if you are getting immediately it will print on the console second thing is I want to do I want to capture the screenshot also okay guys I want to capture the screenshot also see whenever I want to capture the screenshot only and only when any exception is coming otherwise otherwise what is the need of accept other otherwise what is the need of taking the screenshot I want to take the screenshot only and only when any exception or any error is coming so that's why I have written throw able throw able means it will handle exceptions as well as errors so what I want I'll call this particular method it will this particular method will be called automatically through listener if any exception is coming automatically it will take the screenshot so no need to write a screen short method again and again okay in your script okay whenever your I think that if going to this else let the title is not available and then you want to take the screen shorter so no need to write that method if-else condition so many else condition simple if any exception is coming most of time with what we do we write try catch block if the control is coming inside the catch block if any exception is coming it will come inside the catch block then we are taking a screenshot so so many times you have to call the screenshot method but here you just need to write if any exception is coming or any error is coming simple take the screenshot right so we just need to write one method take screenshot and of test method okay so this method - simple screenshot method we will create so let me I have this method just a minute see simple this method we have so I'll copy this method and put it inside my util where it is test2 util dot Java because this is my utility right so I'll put it over here and this is the screenshot okay see for a screenshot also I have written like this oh just a minute guys I'm using Mac books so I have configured like this so let me remove this okay so case if you are using windows okay today's if you are using windows guys you have to change the you know path like this so what i'm doing here see this method what exactly it is doing same method get a screenshot as method user dot di here and then copy this file into on this particular location asleep current directory this is my current directory and create one screenshot folder append with plus means append with current time okay in milliseconds and then dot PNG just added dot PNG like that okay so it will generate the screenshot like this okay guys so and this particular take a screenshot of method is available here and make it a static okay so what I'll do we will call this method from test2 you take like this okay so test util dot take a screenshot and of test method will be called whenever any exception is coming in your program during the execution whenever any exception is coming it will okay take the screenshot solo need to write a screen short method again and again again and again inside a try-catch block or something like that okay guys so let's see if it is generating the screenshot or not so let's see I'm going to call this method I will disturb the XPath or maybe let's see login method is there and for username what I'll do and for password also and write like this obviously my expert will be disturbed so it will give you element not found exception or something like that and then will see it is taking a screenshot or not let's see I'm just assuming eyes oh sorry sorry sorry not a variable name the name equal to I will change like this okay like this and what I'll do let's run this program okay so let's see contacts page that's not it because every time before running any test case it will execute this method setup method it will go to login and it will check the username is name equal to name one one and password equal to password one one which is wrong okay by dot name is wrong by dot name is wrong so it should give error so let's see it is one hunting or not nice I mean this topic is amazingly this session is amazingly good and see a lot of things I have covered so please guys practice I cannot cover each and every scenario test case twice but please you have to practice like that so see it is not able to find username password so it's gonna wait because I have given the implicitly rate of fighting 20 seconds and then see it's giving some some error see no such element exception it means exception occurred exception occurred it means this particular event will be on exception event will be called ok so it will call take a screenshot and okay this particular third will be called ok guys and it's creating the screenshot it should create screenshot directly one folder and let's see what we have to do we have to refresh project current directory and see a screenshot and I see this is a time current time in milliseconds okay and if you open it see this is a screenshot guys on the login page it was getting failed right see isn't it amazing this is a power of okay web firing event web driver firing event if any exception is coming immediately it will take only then only it will take the screenshot okay if you want to change the file name if you want to append a find them you can give the file name also it's up to you but this is amazingly good I always use firing event like this you just need to create this where we went listener dot Java class that's it okay so let me close this Chrome and let me change this login page or Java back to normal the correct values okay guys so this is about webdriver event listener now guys these two topics add log4j API okay I will cover in the next session guys I think this is enough for these things okay and in the next part five I'll be adding the art part 5 okay in next two days it will I'll add lock how to add log4j API and how to add external reports okay because already it's one hour session it's already done and I'll add these two things and then in part six we will see Jenkins and the dead code repository and all those basics things so I think you can expect two more parts okay but those will be the basic configuration of your log4j and extend report and then maven and jenkins integration we will see but the coding part most of the coding part is done the framework designing part is done guys so please practice okay guys it's really important and don't jump into part 5 part 4 part 5 directly please see the approach first in part 1 then part 2 see how exactly we created different page librarian page factories in part 3 how exactly we created a different test cases in part 4 how exactly we created a data-driven approach what is the concept of cashel look up what is webdriver fire event okay all those things and then in part 5 we will cover log4j api and exchange report how to generate the logs with the help of log4j api I will cover amazing thing ok very good learning you can write in your resumee also rock forge a play an extend report very good report we will generate and and then in part 6 we will cover maven and Jenkins part and then I think if any enhancement we will see we will see if part 7 we can create but I think in next 2 session it will be over the page object model will be completed okay guys so that's all from my side and see I'm creating video at 3:30 in the night for you guys I'm getting not of request ok from a different folks that please let me create the part 4 ok so just because of you guys I'm creating and that's all for today and guys please subscribe to the video go to my channel and then ok please share the videos and like and please if you have any queries please put the comments over there definitely I will try to reply that's all for today guys thank you so much
Info
Channel: Naveen AutomationLabs
Views: 147,103
Rating: 4.9557195 out of 5
Keywords: pom cachelookup, WebDriverEventListener, Complete Page Object Model (POM) using Page Factory in Selenium, page object model framework architecture, page object model for selenium scripting, Page Object Model, hybrid framework, page object model framework in selenium webdriver example, Naveen AutomationLabs, Page Factory, Selenium, WebDriver, page object model framework in selenium webdriver, page object model framework in selenium webdriver java, page object model selenium java example
Id: H2-3w-GQZ3g
Channel Id: undefined
Length: 63min 40sec (3820 seconds)
Published: Thu Oct 05 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.