Selenium Framework - Advanced- 14. Create Login Test - To verify custom log functionality of Extent

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back guys uh video 14 of this advanced level framework development series uh and my last video i did spoke about uh creating action engines where we can log each and every test action into extend report or you can prefer logger as well the same steps you can repeat with loggers okay in this video number 14 i am going to talk on basically i am going to show you how uh this logging happens by creating a sample login test okay just to verify the parallel execution like till now we didn't tested the things right so we'll test it with parallel execution and the custom messages locks okay so to begin let me go to my eclipse okay and what we did in last video is we created action engine and we did created uh three two i guess couple of only okay couple of methods send keys custom method click custom method okay so i wrote few more methods which i might be needing that is clear method move to element method if i want to hover my mouse to any of the elements so again everything remains same try catch block under try whatever i want to perform and wherever i want to lock the message for positive message or success message status dot pass and status dot fail for exceptions and going to put the exception as okay and wherever i want to access the driver for example here i want to use actions uh under for for using actions class i would need the driver right so for using drivers what i'm going to do is i'm going to access my driver how driverfact dot get instance dot get driver because we already did the set driver into my before method next i wrote for is element present it is going to written me true or false boolean result then select value select drop down value by visible text or by value then assert equal which we will be using like whatever we do right instead forward where we do assert dot assert equals expected value and actual value but because we are doing custom logging right into extent report or your logger whatever so what we'll be doing is if this assertion is true or it is success then it is going to write this particular entry into the extent report if it is failed because of the assertion exception or could be different and any kind of exception it is going to mark it as a failed with proper uh error message final method i wrote it as a get text and there could be any number of methods okay it all depends on how your application is what and all different things you need to test your application so going forward as and when we need the things we are going to put it under actions engine or let's see if we can create some utils class okay for now we are good okay now what we are going to do in this video what i told you is we are going to create a login test okay now in order to create the login test login test uh let me go to my url and let me start my server game a minute guys okay so i'm going to start my apache and mysql because i'm using the application which is deployed on my local that's the php application okay qdpm application and it is deployed on port 8090 fine what i'm going to do is i'm going to login by entering email password going to click on login that's what and i'm going to see whether it logs all the message that is i'm i'm doing send keys over here i'm going to do send key that password i'm going to click on login button right so i'm going to do all this stuff okay now uh the login page is basically uh i need to go to the page objects and under page object if you remember we did created a method called as login right now in order to access this particular login method what we need to do is we need to uh create object of this particular class login page object so what i'll do is i'll go to test case and i'll say login page objects let's say login is equal to new login page objects and here i need to pass the driver so i'll say driver factory dot get instance dot get driver get driver okay this would give me the current driver instance okay but you know one thing what i'm concerned here is about let's say if i am launching five for different five or six different instances at the same time it is going to create for you six different login objects and that is going to mess up the things because the object name is going to be remain same and i believe that will mess up okay so i need to change my approach okay so what i'll do is now i'll okay i hope you got the problem the problem here with this approach would be uh if i'm creating 506 let's see if am instantiating five different test cases execution at a time in parallel right now the value of this particular staff driver factory dot get instance dot get driver is going to be different for all five test cases right so that won't be possible with this particular combination all right uh it might create let's see if it is creating five different login objects with the same thing it will hold only last object and it will mess up the things so this particular way is not possible okay so let's see let me delete these things for now okay so that means i cannot pass the web driver object something like this uh instead can i i'm just thinking can i hard code the object over here can i can i do something like this okay or better better what i'll do is i will drop this idea okay so whatever page factory we were using right in our last framework i'll drop this idea for now what i'll do is instead of this page factory uh what i'm going to do is so definitely we are going to follow page object model only but not a page factory okay so instead of using this find by annotations now what i'm going to do is i'm going to use let's say string or let us use by class okay so i will say bye and what is my first i'll i'll first write it and then i'll explain it quickly so what is my first web element first web element is email so i'll say email uh email uh i'll say email let it be email as equal to by dot what i need to use over here we did use name right and the value of name attribute was this thing so let me use by name and my name value is going to be this okay so if you remember we write something like some something like this driver dot find element by you remember we write something called as by so i'm using the same by over here so this by if you see it's the abstract class right that's the class basically which we are using where we have all these abstracts method by uh static methods basically by id link text virtual link text expat and whatever whatever methods we are using out of there okay so i'm going to create object of this by okay so i'm not going to use this find by next so i'm going to do the same thing for all the web elements what i'm going to access second thing i'm going to create it for password and third one that's basically xpath okay let me copy this x path and it is it should be xpath okay and it should be password and it should be uh what's that login button login underscore button okay uh what i'll do is because because these are static things right let me make something like this email password login underscore button we may make these things as a static final shouldn't be any issue because these locators are very much constant for any number of instances you are going to create okay should be fine even if i make them as a static okay i'm not going to use this stuff now okay now how to get the locators out of this particular because these are just by class object right and in order to get the web element what we need to do is we need to use something called as driver dot find element now how to get the driver object by using driver factory okay that we did earlier give me a minute driver what's happening driver factory dot get instance dot get driver okay so this will give me a driver object then on this driver object we are going to do driver dot find element and at the bye we are not going to do something like buy dot name or buy dot expert something right because that is something we already uh implemented on this line number 15 16 17. so initially i'll go to email and on email what i want to do is i want to do the send keys so i'll do dot send keys and this should work perfectly okay but uh if we use send case like this then there is no use of what we created something called as action engines right because we created a custom method called as send keys custom right for entering the keys right so we should use this particular method in order to do the custom logging right so i'll call this particular method now in order to call this method it is present under actions class and i don't want to create object of actions class everywhere but what i remember is under test base we did extended actions class okay so what i'll do is in each and every page object what i'll do is i'll extend test base right because it will indirectly reference all the methods from this actions engine okay kind of inheritance not a kind of inheritance in fact okay so i'm not going to do something like this the same thing we are going to achieve but by using our custom method that is send keys custom and here what is my web element my web element is going to be this right this is my web element what's the field name okay before that what's the value value is going to be email and what's the field name so this is something which we are going to use for logging the message into uh your accent report or logger whatever this to identify what field it is for so i'll say login email failed okay great now this is how i am going to do the send case across all the uh application okay email enter is done next thing i'm going to do the things for password and finally i'm going to click ok let me do the same thing for password because the things remain same uh instead of email i need to use something called as password over here password okay and that's the by class object okay and here login i'll say password okay and here value i should put is password that i'm going to ask to the from the caller okay now for cl for click again i should not use directly this click method because i want to do the custom logging so for click we did created this custom method right click underscore custom so i'm going to use that particular method and that is going to be here click custom and what's my web element my web element is going to be driver dot find element by and what is that by buy is login button so i'll just change that by and what's my field name my field name is uh let's say login button okay great great i'm done that's pretty simple okay now in order to uh in order to access this particular login method i need to create object of this particular class but this time because we don't have any explicit constructor we need not to pass the drivers and all right so i'll say login page objects login page is equal to new login page objects okay you may consider creating that in test base itself should be fine okay because but in my case because i am just creating couple of uh test classes so i'm not going to follow that but yeah you can do that just uh to use that globally now now in order to login what i'm going to do is login page dot i'm going to call the login method and here i need to pass my email and my password okay now your question might be uh how can i directly log in so if you remember we are extending i mean this test this class is extending test base and if i go to the test base you see something called as before method and this is something which we already implemented and tested that is setting up this browser maximizing the window setting up implicit timeout and navigating to the url and url is we are referring it from properties file so these things we are already doing as a part of before method so that is something we need not to repent so because we are extending test base whenever it it comes to this at the right test annotation it will look for before method and yes it is there so it will execute okay now this login page method should get executed okay and let me put out my credentials so my credentials i'm going to use something admin and password is going to be this okay so this is just a login step okay i'm not going to go ahead out of that but that's it because i just want to test uh and in the second case as well i'm going to uh do the same thing let it be uh let the things should be same or let me make the password let's say one two three four okay i'm not doing any kind of validation so my test case might not fail but we will see the same things into the reports okay and do we have earlier reports created let me quickly refresh and now my reports folder is empty great now one thing we need to remember we are we are doing extent reporting and the extent reporting part we implemented mostly into the listeners right we are initializing that under listeners only you see create test we are doing under listeners only so you need to make sure that if you see if you uh run the test case directly something like this let's say i am going to run this particular test case directly like this you see the execution has started and it will launch the browser but it should give me an error okay you see it is giving me the failure error and why that failure is if you see it says null pointer exception and it is coming at line number 29 over here and it is on this extend method right because we are trying to call this extend get extend method but it is not it is not started yet when it will get started it will started only if you if you uh use this listeners implementation class and how we use listeners we go to testnj.xmls and let me check if we have added yeah we already have added this right listeners annotation so make sure that you have this listener's annotation already in place so that this listeners will get invoked before your test execution gets started i'll right click on my let's say testing.xml and run it and test ng test so now i have two test cases and uc does launch a jet has launched to chrome driver at a time and you see it is working with two instances and it has entered some value and once the load get completed it will close the instances and yes both the test cases got executed and test cases were executing in parallel without any issues okay now what i'm more interested in i'm more interested into seeing my report i'll go to the reports folder and here is my latest execution report and you see it has created two uh nodes basically test one and test two if i go to test one you see how good logging is it okay so because i'm using dark theme it is bit uh difficult to read for me now but you see uh it is logging all the messages like login email field and entered value as whatever value you were trying to enter login password field entered value as admin at the rate one two three clicked on login link and this is pass okay so you can do a better reporting than this okay so this this is just because of the this is just because the sample i'm just trying to show you how we can lock the messages but make sure that we make the messages more readable more understandable even these are understandable but you can put it in better way ah if i go to test tescus2 you see the password what we entered it was one two three four right that means my extent report logging custom report logging uh is working perfectly okay without any issue it is working for my parallel test execution as well whether the parallel execution is with thread count as method thread type as method or classes or whatever different options we have we'll see that in our last few sessions whenever we do the integration parts and all but for now it looks good to me if i go to my dashboard it show me two or two discusses are passed and i have already shown you this particular environment variables what we are adding and how much time it has taken only 17 seconds and all okay so yeah that's it i was more interested into seeing this particular custom message logging into my accent report and because i am seeing these kind of messages that's the reason i'm basically not using logger file into my personal uh projects as well okay so i don't prefer basically because i do the deep logging into my extent reports itself okay so i think that's it for this video i'm going to end this video over here what we did is we did uh we just uh use login method only one login method on login page okay and just to show the usage of custom message logging into your accent okay now uh in next few videos what we are going to do is we are going to start writing our actual test cases okay so let me show you my actual test case just give me a minute if i have that already in place yeah so these are here okay so i have just taken the screenshot so these are my test cases okay i'm going to navigate login and navigate to task and also i'm going to start my work on further screens okay so yeah and one more quick point here is going to be that would need a little rework from my side because we are not going to use the page factory right and the limitation why i already told you right we are going to we are going to follow this particular way right so i need to repeat the same stuff for all this stuff whatever we did okay so this is something i will complete and i will continue in my next video uh for creating some into interesting okay so i think yeah that's it stay tuned thank you
Info
Channel: AutomationTalks
Views: 3,462
Rating: undefined out of 5
Keywords: selenium code for login page in chrome, how to automate gmail login using selenium webdriver java, login page validation in selenium webdriver, how to automate gmail login using selenium webdriver python, selenium test cases for login page, selenium login example java, how to verify login in selenium webdriver python, selenium test cases for login page using testng, selenium test cases for login page python, selenium script for login page in java, selenium code for login and logout
Id: 6kuJUsS1haI
Channel Id: undefined
Length: 22min 16sec (1336 seconds)
Published: Sat Sep 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.