How To Generate Allure Reports in Selenium with Python & PyTest

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to earth this is powering to minus DT channel in this video I am going to show you how to generate a you reports in selenium using PI test now let's see the agenda the first of all we will see how to set up a load on Windows then we will write one test case which will generate a new report then I will show you how to add scheme short to the Lu reports and then we will discuss some of the decorators supported by Lu reports and finally we will see how to share our earlier report now let's get started the first thing is we need to set up earlier on windows so to do this we need to download a Leawood software let me just go to earlier report official website so Lu report download for Windows just go and google it so on your report download for Windows and this is official website test report and framework for writing self documented or you can go with this also Lu report all your framework now go to this puddle website and here in the first section you can see there are multiple sections have provided and here they have given some instructions how to install our L your setup on Windows so installing a command line go here and they have given some installation or some instructions to install install earlier so through command prompt we can install by giving this commands group install Lu and you can also do manual installation you can just come down here they have provided some instructions to how we can do manual installation and we have to download the zip file from maven central and then we have to unpack the zip file and you will get one folder structure inside this we will find bin directory and then we will find inside the bin folder we will find a low dot pad then finally we need to set system path so I will show you how we can perform these steps so let's go to this maven central link and here the latest wash means to 10-0 it is not a latest version i think - 13 0 is a latest version just click on this and you can see multiple versions or multiple things are there you have to download the chip file so this is a zip file which we need to download now click on this file and it will start downloading a zip file a your command line and once you downloaded this zip file we have to extract the zip file let me just go to the Downloads folder and inside the Downloads folder you can see the chip file then extract here inside the folder and after extracted you will find a load to 13-0 version inside this you will find a few more folders and inside the bin folder you will say Lu not bad file then we have to copy this folder keep that in somewhere C or kita wherever you want I already copied that in the C Drive so we can see my for the Lu 2.13 dot 0 so this is the first thing we have to do so we have to download the software and in the form of zip file extract it then keep that folder in your drive and after that we have to set system path so we need to go to till bin folder and copy this location after that go to right-click on this PC go to properties we need to set path for that a Europe so go to advance the system settings and here you can see environment variables and here just go to path variable directly and click on edit so here we need to add so just click on the new and copy this one and then click on OK button and then close windows I hope I already added this path earlier so somewhere it should be there I already done this earlier if not you can keep you can skip having the same key no problem so if you already have you no need to add once again so here you can see it is already added so let me remove this one ok so I already have the path so I'm just removing it so after setting this path just to close this window and close all these windows so that's how we need to set earlier so after that this is just a setup we need to do on Windows operating system so after completion of this then we have to write test case which will generate the elyo report so the first prerequisite we already downloaded and set up our install earlier on Windows operating system because we can generate a your report through command prompt we have to run City commands through command prompt and then only we can generate a your reports and for that we need to write a test case now I'm going to write a test case using psyllium with Python and I will also use pide pide test framework inside now to do this we need to install two packages in pycharm so I'm going to use PI chomp as a IDE in which we need to install two packages one is selenium and PI tests so that we can write one test case our using Python and selenium so using selenium and PI tests now let's go to PI charm I will show you how we can install these two packages now go to PI charm now here I already created one pack or project called selenium class example so inside this I need to create a new folder and then I can push it further but before that we need to have these two packages selenium and PI test to write our cilium test cases using PI test framework now go to file and here settings and here just go to project and project interpreter so here you can see lot of packages I already installed earlier now we need to install selenium and PI tests so for that what I have to do is we need to just click on the plus button here and just search for selenium right so now we can see psyllium here so I already installed this package earlier so does the reason it is giving in the blue color that means it is already installed on my PI charm so in your case just select this and click on install package and then it will automatically install this package in pi jump and then you can close this window and similarly in the same place we need to also install PI test so it just click on the plus button and search for PI test and you can see when PI tests also have installed on my PI chump it is giving in blue color so this is already installed so in your case select this PI test and click on install package and it will be installed by test package after installing these two packages selenium and PI test you will see something called PI test entry here PI test and also you will see one more entry called selenium selenium webdriver also you can see that so here it is selenium so these are the two packages along this you need to also install one more package called a your PI test so this is another package which we need to install so just go to the plus button again so search for a your iPhone PI test a your iPhone PI test so this is another package which we need to install a your iPhone fighter so totally three packages which we need to install on PI chump let me write it here I'll provide all the links in the description in the pycharm we have to install three packages one is helium package and then PI test package and then a your - PI test package so these are the three packages which we need to install on pycharm so once they are ready then we are ready to write our automation test case using PI test framework now let us create a new package inside the project and I will name it as Lu Reports demo and then click on OK now I just created a new package inside the project so inside this package I am going to write a new test case I am just taking python file and here i will just name it as we have to start with the test keyword when I create a new python file as per pi test standard we have to you follow the strictly we have to follow the naming conventions so whenever you create a file name here it should start with the test test underscore after that you can give any name so here I am giving test underscore RN HRM and extension by default will be added because we are taking the Python file enter now it is created new python file it is acting as a model now inside this model I am going to create one class inside the class I will write the test methods each and every test method will perform certain validation on my application now let us start writing my test case so here to write the test case before we need to import certain packages so the first package should be from selenium we have to import webdriver and after that we are going to generate Lu rapport so we need to also import a your this is another package and along with this we are going to use PI test framework to generate a to create or test cases so we have to also import PI test package so these are the two packages which we need to import and after that let us start writing the test case so before that let me just create one class and class name is always start with the test and then you can give any name to that so I'll say test HRM inside the class I will create some test method so first to test method I'm going to create is def and test method we'll start with the test keyword which prefix beta test test underscore I will verify the logo this is my first test so I will implement this later and then allocate one more test we'll say def test underscore list employees so this is another test I am going to create and implement I will implement the body later and after that I will also write one more test I'll say def test underscore login so self evil by default will be added to the method and that is representing the class now the test methods I am going to implement only to start with the first one so here inside this method I will just initiate the driver so whatever variables we are defining inside the method we can start using those variables by using self keyword so for example normally when I create a driver we will write like this driver equal to web driver dot Chrome this is also perfectly right perfectly right but if you want to use is available in other test methods you have to make it as a global or we need to make this variable as a class variable so for that I can just create this variable as a self dot driver so self dot driver means this variable is belongs to class now this will as-sunnah as soon as i create a self driver so in the next two statements I'll use the same thing self no driver wherever I want to refer the driver and just specify self dot driver now this will launch my browser Chrome browser it will launch after that after that we need to launch my you aren't and one more thing is here I have not specified any Chrome related driver but if you go for silly with Java and all we need to specify the location here okay so why I have not specified the location of my Chrome browser driver is because I already added all my drivers into Python script we just go to Python installation location I am just going to python installation location just a moment let me just go to python so inside the python if i just go to the script folder i already added my chrome driver dot exe and gecko driver ie driver if you all drivers you copied in this directory you no need to specify the location here or else we have to specify the complete path of your driver ok now this will launch my Chrome browser and then I'll try to open my URL say self dot driver and here I will try to open my URL of application so let me open my application let me show you in the browser so I have opened my URL so this is orange HRM application so on that application I'm going to show you few test cases so let it open it is taking some time yeah so once it is launched then as soon as the page is launched first I will verify the logo present or not and then I will verify the login also ok so now let me just launch this URL and the self driver self no driver dot get so get method out of yourself dot private or get now this statement will launch my browser and you are and after that as soon as I launch my URL I will verify whether this logo is present or not so I'm just capturing this element and I am just capturing X part of this element copy X part of the image and then let us try to locate the element how to locate the element against Alfred or to drive or dot find element by XPath and specify the expo so double quotations insert the double quotations are not allowed so we have to just single quotations and I have located that logo and Here I am using some conditional statement or ease displayed and this method will verify that Lobo is present or not and after displaying after getting the display status I am saving that status in a variable I just create one variable called status and then I will verify the condition here if status if the state does equal to is a true if the state is equal to true and then I am asserting true that means this is a peiter secession it will make my test method passed and suppose else if it is status is equal to not true then what I should do is I need to make my test method false so I'll say Assad Falls I'm saying as it falls right after say as it falls and after that after validation is done then I am closing my browser cell 4.2 drive or dot goes so this is my first attest I have implemented now after that let us try to implement this one so I just write something here so the first a test case I'll make it a pass and because I am verifying the condition so the second test case second test test on Paulista implies I am NOT implementing anything here but I want to skip this test so intentionally I'm going to skip this so I'll write pretest one I will make pass one I'll make skip then I have one I will make fail because I can see three statuses in my report now this particular test a list of employees I'll just make a skip so to skip this test method intentionally I have to specify pipe test dot escape and here I can just specify some message and skipping esto skipping test later I will implement it okay so I am just writing simple message so this test method will be skipped so after that I will try to implement one more test method and your intend Asian is very very important in Python so we have to carefully use tab spaces now this method I am going to implement test underscore login so here I'm going to verify the login test so here again we have to create the driver so let me just create the driver and opening URL same two statements are copied and after launching my page I will try to locate the username and password so inspect the username inspect the user name field and I can find idea of that element I'm just using ID here so again cell phone or driver dot find element by ID and specify the idea of the element dot Cindy key is off specify the username and password so my username is admin and these are first element and the second element highlight the second element and capture the idea of the second element that is fee xD password now self dot driver dot find element by ID specify the ID and dot sendkeys admin one two three this is my password so after that we need to click on the login button so let me just click on the login and I have a name attribute available or ID is also there so let me click capture ID now again write self a dot driver dot find element by ID specify the ID of the sign-in button dot click so after performing these things or then I will verify the after successful login you will get a the page will be changed or you will navigate to the dashboard page then I will verify the title of the dashboard page so if you are able to successfully login then you will able to see the admin page here so now I want to infer the dashboard admin page so to do this I will put one verification point I will capture the title of the page at the runtime so self or dot driver dot I title so this will give you the title of the page and I'll store the title in a variable called actual title and now I will compare this actual title with our expect so here I'm putting one condition is actual title equal to and I'm expected title will be orange HRM I expect a title okay this is my expected title and if it is so then I'll say self dot driver dot close I'm closing my browser and then I will make assertion is true that means my test method will pass else else I need to make my test method failure so for that before that I'm just again closing my browser so self dot driver dot close and then I'll send assertion is false so that this statement will make my test method failure so that title is exactly matching my test pass or title is not match my test will fail okay so this is another desktop creator so first test is a logo verification and then list of employees and then test logging so three methods are implemented three methods are implemented there's a plane test case by test using PI test framework in Python alright so now let us execute this test a load and later we will see how you can generate report all these things so let me just check all the test methods are properly working or not the first method I hope it will pass because I capturing the status I'm verifying the status is true or not the second test method will will be skipped and the third method will be passed because I have given the proper title here now let us execute how to run the PI test so to run the PI test we need to run only through terminal so let me open my terminal in my PI charm and here we have to give one command called PI test - before where boss - s for printing the statements and here we need to specify the location of your test file test underscore orange HR on which is present inside the earlier reports demo package that we have to specify so first we need to go to L your reports demo slash test underscore or with HRM dot P by alright so this is my file name then execute it and it will on your test cases no the items are collected now it is launched on my webpage now it is trying to execute three test methods so the first method is completed and second one is skipped now the third method is a login test so we will able to see the login process yes it is entering admin admin 1-2-3 and successfully logging and browser is closed now we can see here and it is saying - got past one is got skipped so two got passed means the first method has got passed and the test log is also got passed and test aleast employees got skipped okay my test cases are about executed successfully and then what I will do is let me just clear this and always we have to run the test only through command prompt now so I will intentionally make my test method fail the second one because I can see a status in my earlier reports so to make my test method failure I just give some invalid title then obviously my test method will fail okay now let us execute one more time so this time we will expect one should pass one should fail one should skip and we are going to see all three statuses in my earlier report so the first method second method is executed now it is executing the third method all right so everything is done now let us see the status now one got failed one got passed one got skipped so till now we have just created a very basic test case in psyllium python using pi test framework now the next step is as soon as we have successfully executed our test cases we will see how to generate the report so how to generate the report so before generating the report so I will also show you few more things which are supported by all your reports so what are the things which will support so it supports something called decorators we can also add skin short on failures and we can all so you sit in kind of decorators so we can also define the severity of your test methods and on failures we can also add skin short or to your earlier reports now let me add these two and then I will show you how to generate the report okay so here I have written just to play in this case right so now I want to also make sure the skin sort should be attached to the L your report on failures okay so I here test login I'm intentionally failing my test so as soon as my test got failed I am going to attach the screenshot to the L your report okay I want to attach the screenshot to the L your report so how we can attach the screenshot and it is very simple or here this is a test method I am going to fail right and as soon as this title is not match else part will execute so in the else part before closing my browser I will write one statement which will capture the screenshot and it will be part of your L your report now what the statement is we have to use L your package so L your dot attach this is the method elio dot attach and here we have to pass three parameters one is we have to pass a method called self or dot driver dot get the screenshot get a screenshot as PNG there is a method called get the screenshot as PNG so self door driver dot gets injured as PNG so this particular statement will capture the screenshot and then the second parameter will be the first parameter the second parameter will be the name so which name you want to display my report for that particular screenshot so that you have to specify so this is I'm just giving like our test login screen test to login screen with this name it will save the screenshot on my report okay name equal to and test to login screen these are another parameter now the third parameter s you can also write in the next time now third parameter is attachment type you how to specify attachment underscore type and here we have to use special called attachment dot which type you are going to specify which type la PNG or jpg which one so that we have to specify so attachment type attachment underscore type equal to attachment type of dot attachment type dot I'll say PNG so here it is giving attachment or type is not correct let me just remove the a spelling mistakes attachment type so still it is giving some error so what is error unresolved reference attachment type it is asking to import one more package called earlier underscore comments underscore types underscore attachment type so click on this link and then it will automatically imported this one okay now these are the three parameters which we need to pass inside a your dot attach so this will capture the screenshot and these are value which is given to the screenshot and the report we can see that name and the format of the report we have to specify so this particular statement will capture the screenshot of your screen then automatically attach it that the screenshot to your earlier report okay this is one thing I am going to show you and wherever your test no test fail your happen so there you can just add this statement it will automatically capture the screenshot attach that into the earlier this is one feature apart from this we can also specify the severity of the test methods and which can be populated in your earlier report so how we can specify the severity of the test methods so we have to add certain kind of decorators and these decorators can be add add to the class level or method level so if you want to add a decorator at the class level we have to say like this at the rate L your dot severity there is a method all our lower case letter elio dot severity and here we have to specify a your dot C we are till level and dot normal normal minor blocker so there are multiple severity levels we have so let me just have a normal so if you want to define the severity level at the class level how to add this decorator we can also add decorators at the method level suppose I want to make this method and this method I want to make like minor because this is a logo test so simple is a minor here dot uppercase letters we have to say it's minor and the severity of this test matter is minor and similarly I will also add some of the decorators for rest of them so here list of employees and I'll make it as a normal normal and login if the login is got failed is a severe so I'll say high severity so let's go put the decorator and here I can say blocker or critical you can specify the blocker dot blocker or we can also specify the critical whichever you want so this is how we can add decorators for a class level and each method level okay so these decorators will be populated on your L your reports now we have created basic test case and then we have also written the statement which will capture the screenshot and make available that screenshot on the L you report and then also have shown you how to add the decorator for every test method right and then let us execute this test and then we will see the L you report but how we can execute this test so if you want to generate the L you reports we should not run method we should not run file directly like this previously we have run the test like this PI test - B - s verbose and the printing statements L you repose demos - test orange HRM to RT y so this will just execute your test but it will not generate any L you report but to generate L your report we have to add one more Altman command-line argument here that is iPhone iPhone let me write here - I fun L or L your dir and you have to specify the location where you want to generate the location so iPhone iPhone L your I load the ir equal to in the double quotations you have to specify the location so where you want to generate the report so what I will do is I will just capture the location of my folder lü reports demo inside this I will create a reports ok so what I can do is I will just capture right-click on your package name and copy path you can get the path here yeah copy relative path and copy path at me copy this path and then paste it over here so I fan - lu dr and then you have to specify the complete location and inside this i will create one reports reports folder inside the reports folder and even though if you don't have reports folder it will automatically generate that folder inside the report folder reports will be present now this is the additional argument you have to say - - lu they are and where you want to save your lu reports that we have to specify followed by your test so this is how we need to pass additional argument now once your test case is got executed then you will see a new report generated inside the folder let me run my test again press enter now it is connected three items are now started running my test cases so i have run three test cases one is got past one will fail one will skip so now it is trying to execute the last and also on failures we also capture the screenshot and that screenshot should be part of your l your report right once everything is done so here we can see the status one is got failed passed and skipped so after the execution is complete there you will notice one thing here in my package it is created new folder called reports so if we expand this report all the report files are available in the JSON format and there is a PNG this is screenshot actually but we have to we cannot see the exact report by using these files so till we have not generated actual report but it is generated some reported files but based on these files we need to generate the lü report so we cannot directly generate the elio report it is a little in process so as soon as I have run this command it is generated all the reported files inside the folder now to run this to generate the Lu report we have to run a command through CLI mode so in the first step I already told you first step we have installed earlier on Windows right so we need to go to that folder if I just go to C Drive and we already configured a path of our Lu right so till bin folder we have captured this right so we have to use this lu dot bad command to run our or to generate our lu report okay so what i have to do is after running yours test cases you will create a new folder called reports right after that what you have to do is we need to capture the location of these reports copy the location copy the path and currently all your reported files are available in this particular folder now go to the command prompt so I'm just opening my command prompt CMD and we can run now a your bad file from anywhere because we already added path into our system meter so here what you have to do is we have to run one command that is L your serve command we have to run l your server LCR ve and followed by you have to give this location where exactly these files are generated so copy this entire location and then paste it over here now once you run this it will start generating the Lu report so as soon as it is generated you can see the report here okay this is actual Lu report if I go again go to the command prompt you will see something here report successfully generated - so in this location the report is this is a temporary location in your system so this report is generated in this location right so internally it will use JIT server and it will automatically generate the report so this particular command serve command will generate the report and you run any number of times the same command it will generate the new reports and one more important thing is you cannot see report in one single HTML files because if we just notice this report there are multiple pages are there in the report there are different pages so you cannot see the entire report one single HTML ok so as soon as I have run this command a yourself and specify the location where your reports are generated and it will again generate the actual lü report in the temporary location in this location your reports are available now let us explore this report so initially over you and here L your report is a name and date and three tests have executed and here you can see Lu repos d'amour this is my package name click on the show all then it will give you all the test cases under th test HRE means my class name inside this I have a Thetis matters so test the list employees test login test log one is got skipped and this is a skip you can see the status here and message is also it is displayed and you can also see here severity level normal and I already have specified the severity level normal here the same thing is populated here and you rationed zero seconds because you have not executed this we have just skip it then go to the failure case test our login so here assertion is failed and thirteen seconds here the exception also we will get so the same method whatever you have written we will get it here the code also and it's a critical societal level we have updated as a critical and 13 seconds of time it is taken and one more thing is it is also attached to the scheme shot here on failure if I just expand here test body you can see the screenshot here okay so this is another beautiful feature from Lu report now go to the past one so it is past is a minor severity so it is taken out eight seconds of time and you can also go to the graph section you can see the beautiful graphs here see where the graph status and duration graphs and time line how much time everything is taken and behaviors in detail we again here and packages this actual package inside this there are two three test methods are created right Lu reports demo is my package testing score orange HRM is my file module inside this Testament is our Creator so this is a Lu report guys okay so but after again if I run the same coming up suppose if I execute my test cases one more time every time these files will be replaced every time you have to run this command to generate the Lu report okay because you cannot save Lu report statically in your system but whenever you run this command in the temporary directory the HTML files will be generated by this a your server command and if you just go and see this location let me just copy this and I'll show you that right click edit and copy and go to that location and here you can see actual files there are so many files are there you cannot see the entire report if within single file okay so there's a reason we cannot directly share these files with your team because these files are automatically generated by the Lu and which will be generated in the temporary folder and these results are not permanent every time you have to run when you run this command in the new reports new reports will be generated okay so let's go for the next level so we have seen so far how to generate Lu reports how to add screenshot to the Lu reports also we have discussed some of the decorators means how we can add severity levels to your test methods and finally how to share Lu report just now I have told you Lu report is are not a single file if it is a single HTML file we can easily share it right but it is not a single HTML file which contains many files but it is directly not possible to share with the team because as soon as you run this command it will automatically generate your report dynamical you cannot say with the team but still I will show you one way to share the report but this is not official process what I can do is we cannot export Lu report a single HTML page because Lu report is not a single Paige as I told you before so we cannot save save eat and send as a file to your team but because L you report internally generated by jetty server these are jetty server instance and this serves a command will generate the report but how we can share it if you still want to share it we have one more approach we have a way with to shell the report to others so here I have a website called net Lafitte comm just go to that website so net nifty comm and you have to log into this website if don't have any login you have to create your account it is a free you have to sign up and create account and then log in into this website so net net Lafitte calm so in this website you can see here deployment area as soon as I log in you can see some deployment area and what you have to do is wherever the reports are generated in the temporary location right you have to open that location we already open that here and just little go back you can see the folder right so this particular folder we have to just drag and drop into that putler website so I'm just drag and drop the entire folder here basically what I am doing is I'm just deploying my HTML pages into the server cloud environment so it is still uploading and published as soon at is is published you will get one link here so if I open this link on the browser again you will see the same report so it is trying to open so now what have done is whatever reports we have generated a local system I have deployed all my HTML files into some hosting server and it is automatically generated one URL for us and if I share this URL to anybody else they can easily access your reports and this URL you can miss share everybody can access your report with this URL and the same report you can see again here same report again you can see here right suppose if you need any modification suppose you have run this command one more time and the new reports have generated a new command is run one more time but again how we can modify that report again go back here and again drag and drop the folder here you can just go to the deploy section go to the deploys and you can see the previous deploys also and here again drag and drop the folder one more time and every time whenever you run the command new reports will be generated and drag and drop those come drag and drop those folders again it is generated the link link will be the same but it's a published again so again open this link in the browser you will see the reports so this is just another way I have found where I can share your report if I share this thing to everybody else anybody else they can easily access your report and which contains all the pages ok so this is how we can also share all your report ok so what we have seen is how to download and install all your or windows and how to generate alia repost i have created one test case and also i have shown you how to ask in short on failures to the low report then we have seen decorators and also shown you how to share l your report ok so there's all for this video guys thanks for watching
Info
Channel: SDET- Automation Techie
Views: 24,204
Rating: 4.8959107 out of 5
Keywords: Python, Selenium with Python, Selenium webdriver, Automation, Testing tools, Selenium tutorials, Python tutorials, Manual testing, SDET, Java, selenium with java, web services, postman, soapui, rest assured, SQL, Programming, Software Testing material, selenium videos, python videos, automation vidios, jira, jmeter, performance testing, functional testing, QA, QC, Agile testing, SDLC, Automation Step by Step, restapi, Generate Allure Reports in Selenium with Python & PyTest
Id: kP-PnWBJPqA
Channel Id: undefined
Length: 41min 20sec (2480 seconds)
Published: Thu Dec 12 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.