Selenium with Python | PyTest HTML Report Generation | pytest-html module

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
comment so as part of today's session we are going to see how to generate HTML reports for your disc cases and so far we covered how we can perform parameterization or we can be parallel testing or we can pass with command line arguments all these things and today's session will focus on how to generate HTML dewdrops so our PI test okay so this is very small topic so before that if you want to generate this report we need to add one package in PI Chun so the package is pipe test HTML so that is the package which we need to install and that will give you reporting mechanism so I'll show you how to install this one so let's go to pie chart so first of all we need to install through command prompt so first let's go to command prompt and open this command prompt so once you open the command prompt so here just type PI test list and it will give you water all packages or plugins installed on top of item and just cross it this whether it is there or not if it is not there we can install it is giving some error test so this is a list command yeah so this will give you the list of plugins which you have installed on top of Python so here you can see one option called PI test HTML this is the one this is a plug-in which we need to install by just HTML okay so this plug-in is there already in Python so we need to install this but already I have installed earlier so it is there so if you want to install this we can just type click install install my test five subjects pmf so with a center it will start installing so we already have this one so it is giving same same message so it is giving some message so requirement is already satisfied so that means you already installed this one so the next thing is in the pile chump also we need to install that printing so just go to the file and select your project here and go to the file then go to settings and in the project interdict a project interpreter here you need to search for this you already have in this is because I already install this so here you can see that one or if you don't see here you need to just install this just go to plus button here now here search for pipe is a fun HTML okay this is a package select this one and click on install package so this will install the package by just hon - HTML package so once we have done installation successfully then close this okay now we need to create a test case here okay let's create a new test case so let me just creating new Python files and here I will name it as something called orange test it is the naming convention interval okay test underscore in each other dot e bite so this is my module name and inside this I will create a class so inside this first we need to import selenium so selenium camp or webdriver and once we have imported and we need to also import five tests so we here we don't need to import by that HTML because the pie it is HTML will work out that the run time at the time of generating the report so here we know knitting Buddha so only PI test we have to use and then we need to create one class this is considered as one - case and test orange HRM application so this is my class on creating and inside this class I will create a fixture setup method feature which will execute before and after of every test method so first I will create depth setup matter this is depth select metal so insert the setup method I will create a creation of the driver opening the browser page all these things and here I will just create driver so self dot driver is equal to web driver dot own and we are going to specify the executable paths wherever the chrome driver is present so this is our executable path of my driver so C colon drivers these things self door driver is equal to web driver dot home executable path is equal to so here we should not put this executable path is equal to location of my time okay now don't make sure don't have any spaces or intelligence now we created one driver and then I will maximize this finger cell put our driver because whatever variables currently we are using within the method we need to refer them with a self keyword okay so self at all driver dot max - window - amaizing the window so these steps will be executed when I say this is a fixture method so here I will make it as spy - picture but my test dot feature so what this mean this butler picture i want to execute before and after every test method so these statements will execute before every test method so here I will create actual test method so let's say depth test underscore I will just verify the home page title first test underscore home page title so its title so this is a first test so this test required this setup method because I want to create the driver and maximize this window so I am just referring this picture called setup picture this is a picture I am referring so when I use this picture what happens it this will exhibit these steps first and then it will continue the rest of the code so here I will just say self dot driver here I'll open application URL of application so it's coffee b c VAR l of application right so now this is version and after acid has open this application I'll check the title of the page so we can use on asset command here so I'll say asset and I'm using PI test as it is we have only one asset asset sell Fodor to driver door title so this will give you the title of the page and should be equal to this is my expect a title orange a charm so this is my expected title so this is the first test okay but before this setup method will execute because I say setup here picture method I am referring okay this will be executed before this test method now after completion of this verification then I want to close my browser so again what I have to do is here I will add yield method so yield keyword so what this yield keyword will do is after yield keyword whatever statements we created will be executed after completion of this test method so here I will say self dot dr r dot close so this command will close the browser after completion so first two statements have been executed before the test and these statement will execute after completion of the test method okay because i have referred this picture here okay now the next one I will create one more test their test underscore login so I'm just verifying the login and this will also refer the same picture set of picture now here I will write the code for the login process so just go to application so here I'll say demo so this particular website I need to find out so here I need to identify username password and then login so let's try to identify this username and I am taking so here I'll just say driver so now this driver is there a so the same driver I am referring so here self dot self raw driver okay dot find element by ID and here specify the ID dot send keys off sending so I'll say at me login process and similarly self or dot I can at it I can identify one more element so let's identify this one and ID is password capture this ID now here self dot driver dot find element by ID and I get one more ID dot send ease of admin one two three so this is my password then I need to click on sign-in button login button to inspect this login capture this ID and here self dot self dot driver door find element by ID and this is ID so we need to copy this ID here and ID is this one BTN login is my ID specify this ID dot X so this is so this will perform the login operation now we need to verify this condition so log is character asset command I use asset self without driver dot titles after logging in so I'm just verifying the title is equally after logging also the title is same so orange return okay in that is if both are equal my test will pass otherwise my test fields so this is the test case our Creed okay now these are the actual test methods and this is a small fixture I created and the first was two statements before yield key will be executed before every test method and this particular statement after yield keyboard will be executed after completion of every test method okay so this is our test case now what I am going to do is I want to generate the reports so but before generating the report let us check whether this is working properly or not so what I can do is in the current project so this is my test cases test underscore test turner's what is the name of the test test underscore orange on the spot HRM so let us try to execute this first my test ikon b.i connects the name is this case name is best understood or HRM dot B Y so let us say get this okay now my test is started two items collected because two test cases I have the two tests I have in the discus so the first one is very fine a title which is passed now the next one is a login process I think it is getting framed I have closed my page actually okay let me just run one more time all right so now I have run one more time so first of all he is verifying the home page title passed now the next time okay one second please so this time I'm just closing the page go to terminal again and on the same command by test s okay and second test case is failing me so let's see why the second test case is failing so no such element exception it is giving so if you just go and read this error and the beginning first one is power second one is failed because test endures for orange failures let us read this error why it is getting failed and is saying setup is none so deaf just underscore log in self is a and setup is not mentioned so setup we main yeah and self-drive without find element by ID zenki so this basically this is not able to identify this type so what I can do is this but Allah driver I'll make it as a global okay I'll make it as a government so how we can make this as a global variable I can just make it as a global keyword here global driver okay so in this particular case this driver will be consider as a global so we can use in all the methods we can refer them in all the methods one more thing not exactly this one so actually we are directly trying to introduce the name and password without opening was because as soon as foster test is executed yield method will execute ideal method will close a browser but when I start tester no score login I am directly providing the username and password without using opening URL so I will copy the same statement here then it will open the URL one more time and then it will enter username and password okay so then this is not required so this is I that is actually students okay we are not opening this URL without opening miss Ural we are in take the data let's execute one more time close this to your buffer now the same command by test - B - s test our HR in dot peen 1 right so now to discus I started the first one is verifying the home page title okay now it is passed now the second one is launching the login process launching the browser entering user may and password now it is also passed so now two test cases are being passed so this is basically console output right so we need to see this output in the report so how it in generate by test HTML report so to generate by - HTML report we need to install this one by test - HTML plugin so just now some time back we have shown our showing you how to install this in the command prompt we are to just do you command pip install PI test - HTML this will install the plug-in on top of beta in pi jump so you need to go to file and settings under project Explorer you need to make sure that particular plug-in is available by test - eh statement like if this will generate a HTML report if you don't have you need to go to plus button search for this fight at PI test - HTML and then install that package oh wait now we already have this plug-in so now I need to generate the report for this to test so to generate the test for these two days we need to just pass one parameter let me clear this very simple the same command I am going to execute again but this time I will specify the one more argument here that is iPhone iPhone HTML is equal to report dot HTM so this is the file we need to pass this is another another parameter which we need to pass and if you install only biters HTML plug-in then only this will work okay otherwise this argument will not work so just we need to add a distance parameter here - - HTML is equal to report dot HTML along with this so we cannot few more parameters fall this is enough actually so if you want to this will give you a default reports that this will give you default report but if you want to do any set optimizations in the report and all we need to run we need to also give some other parameter - - self-contained - - self-contained - and this is a default argument this is mandatory - - hTML is equal to repo dot HTM but in addition if you do any customizations and all then we need to add this line - - self so sorry - - self - contained HTML okay this is optional even if you don't pass this argument you can generally will generate the report all right now where this report will be generated so this report will be generated inside the project itself inside the project level and if you want to generate this report in some other folder we can just configure the path on so first let me it exude this report for now for this person a test is now my test cases execution is going so first it will verify title of the homepage and one first one is passed and now it is executing second is case ok now it is also passed now it is passed now it is giving some message generated HTML file so this is exactly the poor file so where it is generated under PI test project on the project level the report on HTML is generated so if we just refresh or if we just come down this is a project right if you see here somewhere report dot HTML is generated and how to see this right click here open browser and we can open this HTML file in one of these browsers so let me open this in chrome browser now you can see this particular report is generated so if we see environment details will be displayed here what I packages we have used and which platform what are the different plugins we have installed and what is the Python version this will give you some environment details and currently two tests we have done so one is verifying the home page title the other one is login process so here they have provided some filters and if you see here there are two tests this is the one and this is about 2/3 bit passed how much time it is taken in to show you and if you click on if anything failure is happened if you click on show all the details okay no log output captured because the test case is passed if the test case is a fail then it will also capture the log messages and store those log messages inside this particular things here and here ok so let's see suppose I will make my test method failed one test method fail and then we will see how the law should be generated here and close this and this time I will I will save my report in my own vacation ok so let's go here again and what I can see here is I want to make one test method fail so let's make home page title is failure I just do something else so now this will be failure right as soon as it's failure what I can do is I can just rerun this ok or else I can just create one more folder here called as reports so inside this report folder I want to see the report instead of creating the report in the project level I want to see the reports in the report folders reports folders okay so now I'll execute this command one more time same command is - B - a - f in HTML and here we need to provide the location so here dot slash is representing your current project directory okay dot slash is representing your current project directory slash and which folder report folder so I'll just say reports reports slash and you were reporting you can give any name to this report so - - hd1 dot slash is representing your project current directory inside this reports folder inside this report dot HTML will be created now everything is exactly the same now this time one test method will be Pass one test method will be fail so let's execute this now two items are collected so the first test case will be failed so first one is failure and the second one another browser is launched okay this is your login so this film one failed one passed ok so overall it's page status but one grade one is passed now let us see the report where it is generated ok just go to reports folder now so in the reports folder you can see a new report is generated so we can save the report whichever location you want so just open this report in a browser the Chrome browser and here you can see that he put the new report which is generated so we can see now so you see hide all the details so one test method failure one test method is passed so we click on the show details it will also give you the ever so why it is getting P okay there is an assertion error because this assertion ever is not exactly matching so because of the reason actually expected is this one but we have specified is this one so that's the reason it is getting famed okay so this is a simple log which is captured at the time of failure so all types of test methods will be displayed in this report so this is a basically report which we are going to generate for your test case if you have more number of test cases it seems very good all right so this is how we need to generate for my district total so this is a report we are going to use as part of frame
Info
Channel: SDET- Automation Techie
Views: 25,067
Rating: 4.8192091 out of 5
Keywords: Python, Selenium with Python, Selenium webdriver, Automation, Testing tools, Selenium tutorials, Python tutorials, Manual testing, SDET, Java, selenium with java, big data, hadoop, postman, soapui, rest assured, ETL testing, SQL, Programming, gcreddy, Software Testing material, selenium videos, python videos, automation vidios, jira, jmeter, performance testing, functional testing, QA, QC, Agile testing, SDLC, PyTest HTML Report Generation, pytest-html
Id: xNo4G-njtJk
Channel Id: undefined
Length: 22min 36sec (1356 seconds)
Published: Fri Mar 22 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.