Session 38 – Selenium with Java | Screenshots, Headless… — Transcript

Learn how to capture screenshots in Selenium with Java using TakesScreenshot interface and new Selenium 4 WebElement methods.

Key Takeaways

  • TakesScreenshot interface is used for full page screenshots in Selenium.
  • Selenium 4 introduces screenshot capture methods on WebElement for specific areas.
  • Maximizing the browser window improves full page screenshot quality.
  • Automation scripts can capture screenshots automatically on test failures.
  • Screenshot files can be saved in multiple image formats like PNG and JPG.

Summary

  • The video explains the TakesScreenshot interface implemented by RemoteWebDriver for capturing full page screenshots in Selenium.
  • From Selenium 4 onwards, screenshot capture methods are also available on WebElement to capture specific areas or elements.
  • Demonstrates three ways to capture screenshots: full page, specific section, and specific web element.
  • Shows how to assign the WebDriver instance to TakesScreenshot interface to capture screenshots.
  • Emphasizes maximizing the browser window before capturing full page screenshots for better coverage.
  • Explains the process of capturing screenshots as file objects and saving them in desired formats like PNG or JPG.
  • Highlights the automation benefit of capturing screenshots automatically on test failures instead of manual capture.
  • Provides a practical coding example using Eclipse IDE to implement screenshot capture in Selenium Java tests.
  • Mentions the use of implicit waits and ChromeDriver setup in the demo code.
  • Clarifies the difference between Selenium 3 and Selenium 4 screenshot capabilities.

Full Transcript — Download SRT & Markdown

00:03
Speaker A
In the last class, we have seen JavaScript executor, which is one of the interfaces that is also implemented by the RemoteWebDriver class. So, if you look at the hierarchy of Selenium classes and interfaces, JavaScript executor is one of the interfaces which is implemented by RemoteWebDriver along with the WebDriver interface.
00:19
Speaker A
executor is one of the interface which is implemented by remote web driver along with the web driver interface and other side we also have another uh interface called take screenshot so this is also another interface which is also implemented by
00:35
Speaker A
On the other side, we also have another interface called TakesScreenshot. This is also another interface which is implemented by RemoteWebDriver. So today, we'll discuss about the TakesScreenshot interface. This interface especially has some methods through which we can take screenshots, like page screenshots.
00:53
Speaker A
automation test script sometimes it is got failed in some particular page so immediately we can capture the screenshot of that particular page and that we can send to the developer so T screenshot is another interface which is also implemented by remote web driver
01:10
Speaker A
Suppose sometimes when you run your automation test script, it fails on some particular page. So immediately, we can capture the screenshot of that particular page and send it to the developer. So TakesScreenshot is another interface which is also implemented by the RemoteWebDriver class.
01:28
Speaker A
screenshot but later on R from selenium 4 onwards uh in the web element also uh capturing methods are provided so we are able to capture the screenshot of specific area from the web page suppose I don't want a full page screenshot I
01:46
Speaker A
So now, let's see by using this TakesScreenshot interface how we can take the screenshot. One more thing, before Selenium 4, up to Selenium 3, we had this particular interface through which we could capture the full page screenshot. But later on, from Selenium 4 onwards, capturing methods are also provided in the WebElement.
02:00
Speaker A
screenshot or some particular section from the page if you want to capture that can also you can capture and those methods are especially provided in from selenium 4 onwards and those methods are from web element not from T screenshot
02:14
Speaker A
So we are able to capture the screenshot of a specific area from the web page. Suppose I don't want a full page screenshot. I want a specific area or specific section from the page. Screenshot of the specific area from the page, that we can capture. Or I want to capture a screenshot of a specific web element, like a logo screenshot or some link screenshot or some particular section from the page. If you want to capture that, you can also capture it.
02:31
Speaker A
immediately your automation itself will capture the screenshot instead of taking screenshot manually your automation skipt itself will capture the screenshot and save them in some place okay the first thing first concept how to capture screenshots okay so there are three uh
02:57
Speaker A
Those methods are especially provided from Selenium 4 onwards, and those methods are from WebElement, not from the TakesScreenshot interface. Okay, so let's see how many ways we can capture the screenshot of the web page.
03:21
Speaker A
from selenium 4 onwards previously only we have full pay screenshot okay so now we'll see how we can capture the screenshot in three different ways let's go to Eclipse new package day 38 capture screenshots okay now uh I'm taking uh demo
04:06
Speaker A
A very important concept: suppose if anywhere something is not working on your web page as per your expectation throughout automation, immediately your automation itself will capture the screenshot. Instead of taking the screenshot manually, your automation script itself will capture the screenshot and save it in some place.
04:27
Speaker A
end the entire page screenshot I want to capture so for that let me start writing the piece of code go Eclipse so this is my driver instance web driver driver equal to new Chrome driver and this is my implicit
04:49
Speaker A
Okay, the first thing, first concept: how to capture screenshots. Okay, so there are three approaches by which you have to capture the screenshot. The first approach is full page screenshot, and this is possible using the TakesScreenshot interface.
05:05
Speaker A
size it is captured but better to maximize the page before capturing the entire screenshot now the first option is what full page screenshot capture full page full page screenshot okay so as I said to capture the screenshot of the page we have a
05:29
Speaker A
And specific area of the page and specific web element, so these two are newly introduced from Selenium 4 onwards. Previously, only we had full page screenshot. Okay, so now we'll see how we can capture the screenshot in three different ways. Let's go to Eclipse, new package, day 38, capture screenshots.
05:43
Speaker A
executor right similarly we need to assign the driver into take screenshot because this is also another interface so how we can do this we have to first create a variable takes screenshot takes screenshot es equal to driver and we will import this T screen
06:13
Speaker A
Okay, now I'm taking a demo application here to capture screenshot. You can take any application. So here, I'm taking ecommerce.com. Okay, so in this particular page, I just want to capture full page screenshot first.
06:37
Speaker A
different type of interface which is nowhere related to web driver interface but what exactly we are doing is we are assigning the web driver variable into text screenshot this is not possible okay suppose if the variable is created
06:52
Speaker A
Okay, I want to capture full page, means from the beginning to end, the entire page screenshot I want to capture. So for that, let me start writing the piece of code. Go Eclipse. So this is my driver instance, WebDriver driver equal to new ChromeDriver, and this is my implicit wait, this is application URL, and then maximize.
07:06
Speaker A
screenshot so the object of the child class we can store into parent class variable so if you are creating this one like Chrome driver driver equal to Chrome driver then we can directly assign the driver into T screenshot this
07:19
Speaker A
So whenever you want to capture full page screenshot, better to maximize the page. If you're not maximized, it will capture the small page. How much page by default it is displayed, only that much size it is captured. But better to maximize the page before capturing the entire screenshot.
07:36
Speaker A
casted so once youve done this now by using TS we have a method called Tex screenshot that is what get screenshot as get screenshot as this is the method TS do get screenshot as in this we have to specify in which format of the file
07:57
Speaker A
Now the first option is what? Full page screenshot, capture full page, full page screenshot. Okay, so as I said, to capture the screenshot of the page, we have a special type of interface called TakesScreenshot.
08:15
Speaker A
understandable format but we need to take the file because we want to capture screenshot as a file and all extensions are supported PNG jpg okay and uh whatever file uh image files extensions are there all extensions are supported most of the
08:33
Speaker A
So now what we need to do, we need to assign the driver to this particular TakesScreenshot variable, just like JavaScript executor. We have first assigned the driver equal to JavaScript executor, right? Similarly, we need to assign the driver into TakesScreenshot because this is also another interface.
08:49
Speaker A
capturing the screenshot in the form of file so this particular method will return a file type of object or file type of variable so now here I'm getting I'm creating one variable called file type and it is uh I can call it as a source
09:10
Speaker A
So how we can do this? We have to first create a variable TakesScreenshot ts equal to driver, and we will import this TakesScreenshot. Let's say control shift O. Yeah, just I have imported TakesScreenshot from org.openqa.selenium.
09:28
Speaker A
variable and that variable we are uh specifying as a file the type of the variable is file this is also predefined class in Java now we have captured the screenshot also we have saved that screenshot uh in a variable but where
09:48
Speaker A
So now tell me, is this correct syntax? Can we do like this? I have directly assigned the driver into ts. No, why? Because TakesScreenshot is a different type of interface which is nowhere related to WebDriver interface.
10:06
Speaker A
so somewhere in the memory the screenshot is available it is finally captured the screenshot but we don't know exactly where it is stored but still even though we don't know the location of the file we can refer that
10:18
Speaker A
But what exactly we are doing is we are assigning the WebDriver variable into TakesScreenshot. This is not possible. Okay, suppose if the variable is created for ChromeDriver directly, right? Same concept in JavaScript executor also we have seen.
10:32
Speaker A
particular file into some location that we know okay so how we can get this file into our own location is we will create another file object let's call it as a source file Target file so this particular file we need to get into our
10:51
Speaker A
Suppose if the driver is created directly with the ChromeDriver, so then it is possible because the ChromeDriver is a child class of TakesScreenshot. So the object of the child class we can store into parent class variable.
11:08
Speaker A
exactly you want to capture the file so file Target file equal to new file here we have to capture the file so now what I'll do is you want to capture the file wherever you want but I want to capture
11:18
Speaker A
So if you are creating this one like ChromeDriver driver equal to new ChromeDriver, then we can directly assign the driver into TakesScreenshot. This is correct syntax. Suppose if you create a driver with the WebDriver instance or WebDriver interface, then we have to do the type casting.
11:36
Speaker A
want to provide this path into this new file okay so when you're capturing the file here why didn't we create a file object because this itself is will return the file top of a variable so this variable we defined as a file but
11:53
Speaker A
Okay, so same concept in JavaScript executor also we have seen this. Now type casted. So once you've done this, now by using ts, we have a method called TakesScreenshot, that is getScreenshotAs.
12:06
Speaker A
inside my project that path I will provide how to capture this path go to properties and here it will show you the location of the file so that I can specify so in this particular folder SL slash what is the name of the screen I
12:24
Speaker A
GetScreenshotAs is the method. ts.do getScreenshotAs, in this we have to specify in which format of the file we want to capture. Now it is image format, but here we have to pass one parameter called OutputType.
12:49
Speaker A
suppose if I move this project to some other location tomorrow in some other system this path will not work this path will not work so what I will do is I want to capture this path till here this
13:03
Speaker A
OutputType is what? Here you can see four options, three options: Base64, bytes, file. Base64 is not understandable format, but we need to take the file because we want to capture screenshot as a file, and all extensions are supported: PNG, JPG.
13:22
Speaker A
part and here write system dot system Dot get property of user DOD so what this part will do system.
13:38
Speaker A
Okay, and whatever file image file extensions are there, all extensions are supported. Most of the times we use PNG or JPG. So ts.getScreenshotAs, output type is what? File, that we have to specify.
13:53
Speaker A
pH okay so what we have done so far we captured the screenshot by using get to screenshot as a method and store in a variable but we don't know the location we cannot see the file because it is
14:05
Speaker A
So what this getScreenshot will return? It will return something called file type of object because we are capturing the screenshot in the form of file. So this particular method will return a file type of object or file type of variable.
14:20
Speaker A
then we can see the screenshot how to copy the source file into Target file two files how we can copy so simple method is there so get the source file dot there is a method called rename to source file dot Target file is what
14:39
Speaker A
So now here I'm getting, I'm creating one variable called file type, and it is, I can call it as a source file. Okay, now this file we need to import from java.io.
15:00
Speaker A
doesn't matter so this is copied into our own location source file to Target file so so that we can see the file okay so what is the target file is representing the location so in this location our source F will be copied so
15:17
Speaker A
So now if I look at this particular statement, the getScreenshotAs method will capture the screenshot in the form of file that we are storing into a variable, and that variable we are specifying as a file. The type of the variable is file. This is also predefined class in Java.
15:33
Speaker A
then I'll explain one more time run as Java application see this is my page right now go back okay so once it is executed under screenshots this is a folder which you already created under the project that I already shown you we
16:01
Speaker A
Now we have captured the screenshot, also we have saved that screenshot in a variable, but where exactly it is captured, in which location we can find the screenshot? We don't know that.
16:20
Speaker A
so this command will return the current project location because instead of hardcoding the full path I just written a shortcut way system. getet property this will be very useful suppose if you use this what is an advantage tomorrow if you copy
16:35
Speaker A
Okay, so this particular method has captured the screenshot, but it is saved somewhere in the memory. We don't know the exact location where the screenshot has been captured.
16:52
Speaker A
once you refreshed you can see open the folder you can see full page.png file just double click on it so the full p.png will be open on this Eclipse itself and if you want to see another way you can also open this you can just
17:09
Speaker A
So somewhere in the memory the screenshot is available. It has finally captured the screenshot, but we don't know exactly where it is stored. But still, even though we don't know the location of the file, we can refer that variable with the file object.
17:27
Speaker A
by calling get a screenshot as source file we will get once you get a source file that we copy into the target file location so Target file is nothing but a new file system. getet property screenshot full page.
17:41
Speaker A
Now we can call it as a source file. Source file is nothing but the file which is captured, stored somewhere in the memory, but we don't know where exactly it is stored.
17:59
Speaker A
is present in our memory so what we need to do is we have to capture this file we need to copy the source file into our Target file our own location okay for that reason we will create another
18:12
Speaker A
Now we need to capture that particular file into some location that we know. Okay, so how can we get this file into our own location? We will create another file object. Let's call it as a target file.
18:25
Speaker A
that path we have to specify our own path you can put in C D drive wherever you want you can put but where I have put here is inside the same project if you copy the path of the current project
18:38
Speaker A
So this particular file we need to get into our target location. So file target file equal to new file h...
18:56
Speaker A
driver and selum web driver this will give you this entire path so instead of writing this entire path I just written system. get property of userd so this particular command will return current project location dynamically this particular command will
19:15
Speaker A
return the project location dynamically in this I go to screenshot folder in this folder I'm saving the screenshot with this particular name you can give any name I'm just giving full page.
19:32
Speaker A
P clear so this particular file name is representing one single file okay if you capture another file you can give another name you need to create another variable or else you can save that file also in the same variable because once
19:49
Speaker A
you create a variable you can re you can reuse multiple times but the problem is get a screenshot is Method right which is cap caping the screenshot and storing this in the variable next time when you capture another screenshot again you
20:04
Speaker A
have to use same method it will capture another screenshot that also referred by the source file then what will happen the old screenshot will be replaced with the new screenshot that is a problem so suppose if you want to capture two three
20:19
Speaker A
four screenshots you need to create a different variables okay multiple screenshot will be referred with the multiple variables why because screenshots are different we cannot refer multiple screenshot with the single variable okay so this is a concept now suppose this is a approach which we
20:41
Speaker A
have from the beginning evening from the starting versions of selenium so t a screenshot is a main interface so in this we have a method called get screenshot and here this method is available in which interface takes a
20:56
Speaker A
screenshot so we captured the file so now from selum 4 onwards you can also capture the screenshot of web element or specific section from the web page yes every individual screenshot if you want to capture we need to call this
21:12
Speaker A
method get the screenshot as but while implementing the project or in the framework we don't write this much code every time suppose I want to capture 10 screenshot in different 10 different places we don't write the same coding 10
21:27
Speaker A
times we will create one user defined method in that method we will pass One driver instance okay and then we will also pass uh where exactly we want to capture the screenshot location so that user defend method will capture the
21:45
Speaker A
screenshot so once you created a user defined method you can call it multiple times so that is an approach we normally follow in our projects okay we don't write the same skip for 10 times for 10 different screenshots no only one time
21:58
Speaker A
we will create but whenever you want to capture the screenshot we will call that method so that method will capture the screenshot or keep it in your screenshot folder so that is an approach normally we follow in our
22:11
Speaker A
projects fine so now let me show you another way so first this is the approach which is available and uh by using capture screenshot method we can do it now these two approaches are introduced from selenium 4 onwards how
22:27
Speaker A
to capture specific are area from the page so for example let's say this is my entire web page now I don't want full page screenshot I just want only this part featured products okay this particular section there are four products are there under
22:47
Speaker A
featured so I want to capture only this part of the page not in the beginning not in the bottom so in the middle of something so this particular section of the page I want to capture screenshot is very very simple only thing is we need
23:03
Speaker A
to write proper X path which is pointing exactly this particular section okay let me inspect this elements so feature products I want to find so go to selector Hub so just try to highight properly so you can see yeah see now I just
23:34
Speaker A
highlighted exactly whatever you want and click on it see this EXA feature product box I have viated so this is capture and X PA see when I press enter this is pointing one element what is that one element is this entire box is
23:53
Speaker A
considered as a one single element inside this there are multiple web elements but we are not in individually identifying them so this everything the entire section du is there du is nothing but a division okay so the entire
24:09
Speaker A
division we are identify by using xal so simply you can see here product grid homepage product grid is there if I highlight this D tag it is exactly highlighting the entire section featur products section the feature product section is highlighting with this x path
24:27
Speaker A
so normally we will write an part for individual elements and these individual elements are present in one single block or single division so this division is identifying that so we need to capture X paath for that particular division so
24:44
Speaker A
this is xath I'm using this particular X paath is pointing what this particular section featured products now go back and whichever section you want to capture from the page we will capture the xath from that particular section right so capture the
25:08
Speaker A
screenshot from the specific section or we can say screenshot of specific section okay simple very easier than first one so what we have done we have captured X paath which is pointing to specific section of the page whichever
25:27
Speaker A
section you want you can capture X paath for that so I want to capture only featured products from this page so what I will do is I can simply say driver.
25:38
Speaker A
find element find element or find Elements which one we have to use I written X paath which is pointing to the entire box as a one single web element now which method we have to use find element only because we want to
25:53
Speaker A
capture the entire box as a one single web element Now by X paath okay now observe so this is the element we captured this is a featured box featured uh products this particular box and this box I want to capture as a
26:12
Speaker A
screenshot so on this element okay what you can do is you can store into another variable store this box in a variable I call it as a featured products section okay and uh what type of this variable it is what is the type of this
26:33
Speaker A
variable we captured the entire box as a one single web element so this will be obviously a web element now import this web element so everyone carefully listen this I don't repeat again if you're not if you're asking me repeating means you
26:49
Speaker A
not listening properly already repeating two three times okay listen very carefully so I captured this box and put into this variable what is the type of this variable is web okay now we need to capture screenshot of this particular element so now
27:08
Speaker A
feature products dot same method get a screenshot as get a screenshot as whatever method we used here also we use same method and same parameter output type output type is what five and once you capture screenshot we can put that
27:29
Speaker A
in a variable so initially I'll comment this part so same process again same process no change I just copy these three lines okay so yeah this we have to store in again one more file variable because this is
27:50
Speaker A
our source file and now we need to create our own Target file so file where exactly you want to store again in the same screenshot folder but my file name is different I can give a different name called
28:07
Speaker A
featured products. p and now we copied the source file into Target same method Source file. rename to Target okay now tell me the difference between this particular get screenshot and here get a screenshot as what is the difference here and
28:34
Speaker A
here what is the difference so here the get to screenshot as method we are calling from interface takes a screenshot interface remember get the screenshot as method we are calling from which interface takes the screenshot interface now here the get to
28:55
Speaker A
screenshot as method we are calling from which from where we are calling from web element from web element we are calling web element is also an interface web element is also an interface so here the get screenshot as calling from T
29:13
Speaker A
screenshot interface but here the same method is implemented in the web element interface also so get a screenshot as method we are calling from web element interface that is a major difference but the functionality is same functional is
29:28
Speaker A
same okay so what is this feature product feature product is a web element feature products is a web element and here we don't need to use T screenshot interface why because the get screenshot as method is comes from web
29:45
Speaker A
element interface itself so that is the reason we're able to capture screenshot of specific web page both interface has the same parent no web element is different interface web element interface is comes from the search context if I look at this
30:04
Speaker A
hierarchy one more time so text screenshot interface is also different interface implemented in web driver remote web driver right so web element interface is also part of the search context actually that I have not mentioned here but web element interface
30:21
Speaker A
is uh a child interface of the uh SE context itself web element actually that should come between search context and web driver okay so that web driver in the web element interface is also implemented by remote web driver class
30:40
Speaker A
directly okay so everybody is clear on this how we can capture the screenshot of specific section of the page okay the only difference is here get the screenshot as method we are calling from takes the screenshot interface but here we calling get to
30:59
Speaker A
screenshot as method from web element inter that is a major difference from selum 4 onwards this method is implemented as part of web interface also web element interface also so now I have changed the name of the file
31:14
Speaker A
previously I given full page.png now I have given the another page okay now execute and see I'm running and after execution I just want to close my page also I can say driver. quit okay now it's done let's go back and
31:40
Speaker A
refresh your page yes now we can see featur products. PNG open this now we can see only feature product section I can capture from the web page only this particular section so like this only everything is depends on the expa so that expa should
32:01
Speaker A
exactly point to that particular section then only it is able to capture okay now I'll simulate the same thing for specific web Bel let's say I want to capture the image of this logo okay that logo image file I want to capture this
32:19
Speaker A
is a specific web element right so let's inspect this element okay same concept but uh here I capture feature products which contains a multiple uh multiple uh products now I want to capture screenshot of specific element screenshot we cannot edit okay
32:41
Speaker A
how can we edit can you edit screenshot manually no right so similarly we cannot do that just we can capture the screenshot that's it right so now the third thing if you want to do any editing in the screenshot once you capture the
32:59
Speaker A
screenshot then you can do editing by using some snipping tools out there so we can just highlight something or we can edit something on the screenshot okay so now I say capture the screenshot of web element actually this
33:21
Speaker A
is also same because the entire section we consider as a one web element and here we will take a specific element let's say the logo is an element let me inspect this logo and yeah now this is pointing one
33:38
Speaker A
element so let's use it same thing same process driver. find element by dot X path so this is the element which is representing the logo so this is a web element now I want to capture the screenshot of logo how we
33:59
Speaker A
can do it logo dot get a screenshot as logo do get screenshot as again the part of the what is the parameter output type is what file so that I can store in again source file and I can store again this I copy
34:24
Speaker A
into Target file so I comment same variables I can't use it again so you need to create another variables or you can comment the above code so now I copy the same stuff okay now here I'll change the name
34:44
Speaker A
of the file called logo.png and this is again Z source file we are copying into the target same thing second and third is not a different actually both are same but in the second uh we written the X
34:59
Speaker A
path which is pointing to entire box consider as a one single web El but here we taken one individual web element that image logo we have taken individual web element but actually second and third are exactly same why because here also
35:14
Speaker A
get screenshot as method we are calling from the web element here also we do the same thing get screenshot as method we are calling from the web so second and third are exactly the same all right let's execute
35:30
Speaker A
capturing the screenshot of specific web element yes it is more targeted element yes but most of the times we take enter screenshot not specific section or element most of the times we captured full page okay now refresh whenever you
35:51
Speaker A
refresh then only you can see okay don't forget to refresh as soon as you executed your script you need to refresh it so now I'm refreshing now you can see logo.png my logo image is got captured okay these are the three
36:06
Speaker A
different approaches which we have to capture the screenshot capture full page for that we have to take the help of T screenshot interface and capture specific area or web element we have to take the help of get a screenshot as
36:23
Speaker A
method from the web element interface okay so everybody's understood now how to capture the screenshot please confirm in the chart box we'll move on to the next topic editing or modification of screenshot is not possible okay through automation just we capture the picture
36:50
Speaker A
and keep that in a folder but once you get the screenshot into the folder then you can modify this by using any snipping to you can highlight something or you can write something comment whatever you want you can do
37:05
Speaker A
that but automation cannot do that because this simple image static image right we don't take screenshot of every test case every time so normally what is the real scenario is suppose you have a 10 steps in your test case you're
37:21
Speaker A
automating all the 10 steps okay suppose somewhere if it is got failed in some particular step is got failed then what we will do based on the condition we will call take screenshot method so that is a process so let me show
37:38
Speaker A
you but actually I'm going to show you this as part of the project then you will get more clarity but here I'm just giving the uh basic idea how exactly we'll capture the screenshot so we don't capture screenshot for every test case
37:54
Speaker A
for every step so normally what happens let us say you have a test case like this you have multiple steps are executed while executing the test case somehow some particular step is got failed it is getting some exception or
38:08
Speaker A
because of some Auto some because of some functionality failure this step is not executed so in this case what you will do immediately whenever particular step is got failed any step is got failed if the part step is got failed we will call
38:26
Speaker A
capture screenshot method we will create this method separately so suppose if the step is this step is got failed immediately we will call this method and capture the screenshot suppose this step is got failed then we immediately capture the screenshot method and it
38:42
Speaker A
will call capture the screen chot so whichever step is got failed wherever it is failed we will just call this method and it will capture the screenshot okay but before that we need to find out we need to put put one
38:58
Speaker A
condition on failures only on failures we will capture the screenshot not every time only when you test cases got failed then only we capture the method but how we will know whether test is got failed or not suppose I have written 10 steps
39:13
Speaker A
how we will know this particular step is got failed or how we will know the entire test is got failed or not after execution only we will know that right the time of execution we don't know after execution is completed then only
39:25
Speaker A
our test is failed or not we will come to know other we don't know but after execution of the test we will capture the information and if the test is got failed capture the screenshot if the test is got passed provide that details
39:41
Speaker A
in the report so these are all called post actions okay these type of conditions we can verify using test NG listeners there is a concept of test NG listeners that we will cover in the test NG sessions okay so that concept I'm
39:59
Speaker A
skipping for now so only on the failures we will capture the skreen chart so normally we don't capture screenshot for every step no need not at all required so if there is any failure based on the failure immediately we call this method
40:14
Speaker A
that will capture the screenshot okay I will explain this concept in test NG then you will understand so for now just understand how to capture the screenshot uh the steps that's it this is the real scenario all right now let's move on to the next
40:37
Speaker A
topic so in selenium web driver it is provided some default class called Chrome options this is a predefined class provided in selenia web driver and uh for every browser there is specific classes there suppose Chrome options Edge options
40:58
Speaker A
okay Firefox options like this every browser is having a different class suppose you have created web driver okay for Chrome browser like this then you can use this chrome options suppose if I created a web driver for Edge driver class then you have to use
41:21
Speaker A
Edge options if I create a driver as a Firefox driver class so then you can access this Firefox options but what is the use of this options class Chrome options class Edge options class Firefox options we can use this options class
41:38
Speaker A
for multiple purposes okay so we will see what is the purpose of using this what are the different purposes and where exactly we use this options classes you can take anything but currently we are working with a chrome
41:52
Speaker A
driver Chrome browser so I'm trying to use Chrome options so whatever method the methods are there in the Chrome options same methods are there in Edge options and Firefox options no difference but depends on the type of the browser you have to use particular
42:07
Speaker A
class so now let's see how we can use Chrome options class and what are all things we can achieve with the Chrome options class one by one so the first thing by using this chrome options or Ed options Firefox option we can control
42:27
Speaker A
the settings of the browser so browser settings normally where we can do if you just go back and open your application you can here you can see three dots here there are settings so here you can see there are so many settings you can do so
42:43
Speaker A
the all the settings like plugins related uh settings okay and any other settings we can do through your Chrome through your settings option provided in the browser so almost every type of browser you can see this set so these settings we can control using
43:01
Speaker A
Chrome options class methods there are certain methods are available in the Chrome options by using those methods we can control browser specific settings browser specific settings are different zoom out or zoom in in the last classes we have seen right that is
43:18
Speaker A
a different that is just a size of the browser but I'm not talking about the size settings of the browser okay for example uh I want to have this particular plugins enabled I can make it available I can make it
43:33
Speaker A
disable Okay so like that so there are many things we can do I'll show you multiple scenarios which are very very helpful in real time also see how we can use Chrome options and depends on the browser you
43:47
Speaker A
need to choose the right options class if you're working with Chrome browser use Chrome options if you're working with edge browser then use Edge options similarly for every browser there is an options class is available so let us see
44:00
Speaker A
how we can work with the Chrome options class so first use case we can achieve headless testing we can make our test case headless I'll tell you what is headless testing very important listen very carefully headless testing means what
44:21
Speaker A
when I run your test case normally what happens is you're able to see browser is launching right it is interacting with some element navigating with different web pages every UI actions you are able to see that when you run your automation as
44:38
Speaker A
a user I can see each and every action is performed on the particular web pages so what is headless testing means I will run my test case but that will execute in the back end I don't see any UI actions I don't
44:55
Speaker A
see browser is launching clicking on the element navigating pages I I don't see any action on the web page everything will execute back end that is called headless test so without seeing any UI without seeing any actions on the UI
45:11
Speaker A
just execute our test case at the back end and you will get only final output whether test is passed or not that's it but you don't see anything which is happened on the web page that is called headless testing and I will also discuss
45:26
Speaker A
advantages disadvantage ages where to use where we should not use all the topics I will discuss one by one first of all let me show you how exactly headless testing works okay so let me you can take any test case any test case
45:42
Speaker A
you can execute in headless mode okay so what I will do is I will create I we already created one test case right here okay so I'll take this particular small test case same test case earlier we have done I
46:00
Speaker A
copied here headless testing okay so what exactly I'm doing in this is I can remove all these things I'm currently enabling my Chrome driver these are the rest of the drivers I have so open this URL and title I'm
46:48
Speaker A
validating something I'm doing here and my browser is closing or you can pit from the browser after execution okay so this is small test case I created importing my Chrome driver let me execute this run as Java application so when you execute the
47:20
Speaker A
normal test case what will happen it will launch my browser open the URL and everything is doing right open URL getting the title and finally I got a test pass I'm able to see the U actions and everything so
47:33
Speaker A
now I want to run this same test in headless mode means without having any UI so that time we have to use something called Chrome options class remove everything I'm taking simple test case you can run any test case in headless
47:52
Speaker A
mode simple test case now I make this in headless mode how we can make this head mode very simple after creating the driver you create one more variable for Chrome options okay so or before creating web driver also you can do this so here I'm
48:11
Speaker A
creating one variable called Chrome options options equal to new Chrome options okay first we need to create an object for the Chrome options class Chrome options options equal Al to new Chrome option this options is just a variable you can create you can put
48:31
Speaker A
anything Chrome driver sorry Chrome options options equal to new Chrome options and we need to import this chrome options so this is a package Chrome options from open q selenium do Chrome okay now once you created this chrome options
48:51
Speaker A
class by using this options object we have to set we have to create some settings now I'll say options dot there is a method called add arguments options. add arguments in this we have to pass one parameter by default
49:11
Speaker A
headless mode uh by default test cases will be executed in the headed mode now we to we want to make that as a headless okay so how we can make it happen in the double codes we have to pass one parameter that is I
49:26
Speaker A
I headless I I headless equal to new semal so this we can do before creating the driver we have to do this before creating the web driver variable so Chrome options options equal to new Chrome options using this options
49:49
Speaker A
object I set some configuration add arguments iPhone iph headless equal to new so what the state will do this statement will setting for this is actual setting for headless testing headless mode of execution headless mode of execution so
50:13
Speaker A
what this option will do this will make our browser headless okay now let's execute a normal script just observe I have added this setting also right Chrome options options equal to new Chrome options add all I'm executing my
50:31
Speaker A
test see still it is launching my browser still it is launched my browser I'm able to see the action but how it is possible because still we have not we created the settings here but at the time of launching the browser we are not
50:47
Speaker A
seeing anything so what we should do now whatever options object we created that we have to pass in the Chrome driver then only this setting will be applicable for the browser if you don't pass this options in this these settings
51:05
Speaker A
are still there but they are not applicable for the browser that's the reason now I'm able to see the browser launching and everything this is just normal execution happen so now execute this so this time I don't see any
51:18
Speaker A
browser so everything will execute at the back end and you can see just you can see test pass execution is done but everything is done in the back end it's not launching any web page anything everything is done in the back end so
51:33
Speaker A
this is called headless mode of execution or headless testing okay so this is a setting we have to do first step we have to create a chrome options object and then we need to call one method called add arguments in this this
51:49
Speaker A
is the parameter we have to specify iph iph headless equal to new and this particular setting once you created this settings we need to pass this options object into the Chrome driver if we do not pass it again it will run in headed
52:05
Speaker A
mode normal mode but if you pass this options here then it will execute in a headed hold on hold on I'll come to that part I told you beginning itself I'll tell you advantages disadvantages where we will use where we should not use
52:23
Speaker A
everything I will discuss first let us see what is headless testing okay so understood everyone so headless testing means what without seeing any UI without seeing any UI actions the test will execute at the back we will see only the
52:40
Speaker A
test passed or failed that's it but what exactly happening inside we are not aware of it but execution is happening execution is happening the browser is launching doing every action on the page everything is happening but it everything is happening the back end
52:55
Speaker A
side we don't see what exactly happening in the back end but finally we are getting the output here this is called headless testing this we can achieve by using Chrome options I'll put this this is a one new sketch by using
53:13
Speaker A
Chrome options we can achieve headless testing okay now let's understand why we need it where we will use headless testing advantages and disadvantages first we will see advantages of headless testing the First Advantage is we can do multiple tasks means
53:37
Speaker A
what aru add arguments is a method okay this is a parameter we have to pass this is a fixed parameters okay these are all provided by documentation selenium official documentation they provided all these things so we need to
53:51
Speaker A
remember this no camel case nothing we need to pass exactly the same thing if you pass uppercase letters it will not work this is a syntax okay now come back to the advantages what is an advantage of headless testing the First Advantage
54:07
Speaker A
there are two advantages the first advantage of headless testing is we can do multiple task since execution is happened backend what is multitask suppose if you're executing your test case in headed mode now I have run this test case let's I have a very
54:26
Speaker A
big test case 10 to 20 steps test cases is there now I'm running my test case in headed mode normal way when you are running your test case while your test case is running can we do any other
54:38
Speaker A
activity parall if you run your test case in headed mode normal mode can you do any other activity parallely while your test case is executing can we do any other activity parall no why because if you do any other activity that will again
54:56
Speaker A
distur your execution if you do any the other activity parall that will disturb your execution right so when you run your test cases in eded mode until the test cases got passed or failed till the test case exited we need to just wait
55:12
Speaker A
and see otherwise we cannot do anything else so any other task parall task we cannot do once you run your test case we need to wait till the test case completion test case is completed but meanwhile you cannot do anything when
55:26
Speaker A
you run your test case in headed mode headless mode because your test case is executing the back end no matter how much it is Big your test case is executing the back end so you can do any other activity parallely so I can open
55:41
Speaker A
notepad or I can open another browser I can browse it anything you can do that will not disturb your execution that is one advantage of headless Tes one advantage because your testing is test case is executing at the back end that
55:56
Speaker A
will not by any other activity you do in your system so multiple tasks you can do that's the first Advantage we can do multiple tasks since the execution is happened at the back end side second Advantage is what faster
56:11
Speaker A
execution faster execution is very faster when you compare with the UA actions because when you run in a headed mode it should launch web page and execution step by step it will go through each and everything so that will
56:25
Speaker A
take some time actually but when you run your test case at the back end it it no need of any UI actually test case will execute in the back end so that execution Wise performance- Wise headless testing is very faster but if
56:39
Speaker A
you run smaller test case you don't see any difference but in the Real Environment when you run 50 test cases or 100 test cases at a time you will see lot of difference so headless testing is more faster than headed mode of testing
56:54
Speaker A
that is another advantage so we can do multiple tasks even though execution is happening parall we can do another task and execution is very fast so in these in these are the two advantages of headless testing and who
57:10
Speaker A
will prefer when to prefer we will discuss that part so these are the two advantages now come to disadvantage when you come to the disadvantage disadvantages user cannot see any actions as a user suppose you already created some new test cases and you hand
57:29
Speaker A
over to someone else to run it and he is a new guy he don't know any functionality anything but he is just running the test case but normally begin as a beginner what I will do is if anyone provided my test cases to me at
57:43
Speaker A
the time of execution once I run my test case I will know exactly what is the flow of your test case so what exactly my test case is doing I can easily understand if I can see the UI if you do
57:55
Speaker A
not see the UI it is just executing the back end and giving the result as a beginner I can't understand what exactly the test case is doing I'm not aware of any flow before right by depending on execution I cannot understand anything
58:09
Speaker A
what exactly it is doing I don't know so that is a disadvantage so user cannot see any options on the web page so he cannot understand the flow or functionality of the test so for beginners it is not
58:25
Speaker A
recommended okay this is the main disadvantage but when we will prefer when we should not prefer initial stage of development like initial stage of automation anyway you have to know UI because to get the xarts of the element
58:41
Speaker A
locating elements so these things will be involved at the beginning stage definitely right so at the beginning stages at the time of writing your test cases or at the time of developing your test cases we always prefer the headed
58:54
Speaker A
mode of testing because we have to inter with the UI we need the UI like what are the elements we want to interact where exactly they are if you want to know this definitely we have to interact with
59:05
Speaker A
the UI even that at the time of execution also we want to see what exactly our test case is doing so at the beginner level at the time of developing your test cases at the time of executing your test cases we prefer headed mode
59:20
Speaker A
testing only but when we will prefer headless testing suppose your automation is completed you have 100 test cases all 100 test cases are finished your automation framework is ready test cases are finished everything is there now we will run your automation multiple times
59:38
Speaker A
in multiple rounds in the coming Future Okay suppose your automation is running on the devops environment or in the ca environment in that particular case you don't need to see any UI so what is your priority in that case is
59:53
Speaker A
execution should be faster okay because you are already test cases are executed many times and your test cases are already passed many times so you are very confident on that so in that case whenever you want to run your
60:05
Speaker A
test case you just execute a test case in the Headless mode because execution is faster and you no need to see the UI also you don't want to see any UI you don't need that kind of requirement because you already gone through many
60:18
Speaker A
phases of your development implementation of test cases you have seen the UI everything is done earlier and once you come to the last stages of your testing you run your test cases on devops environment on CA environment in
60:32
Speaker A
jenin in those cases you will prefer headless mode of testing because execution will happen backend you don't need to see any U you can Con on other task you just need only report passed or failed right so in that
60:48
Speaker A
particular scenario The Headless mode testing is preferred and also by default Jenkins Jenkins is a continuous integration tool that will execute your test cases by default in headless because they don't need any Ur So that is a preferable so
61:05
Speaker A
at the beginning stages of developing your automation test cases or executions you don't prefer headless mode once you done your framework once you automated test cases in the further levels you will execute your test cases multiple times in that case you will prefer
61:21
Speaker A
headless testing okay this is a Advantage disadvantage when to prefer when we should not prefer okay but at the beginning stage we don't prefer headless so most of the times we prefer this headless testing only in the devops environment we will
61:39
Speaker A
see that later I'm not going to touch the topic now CI CD or devops environment what it is how how test cases will run there all these things we'll discuss in the upcoming sessions that's the last topic for now just
61:54
Speaker A
understand this what is headless testing Advantage disadvantage when to prefer when we should not understood everyone okay so whenever our tests are completed build is stable execution is happening properly happening in the Q environment then we will push our code
62:20
Speaker A
into the remote repositories and we will run our Automation in the devops environment so there are many phases are there many cycles are there I'm not going to that now we will have a separate concept for that okay just
62:35
Speaker A
remember this much for now this is one advantage of chrome options class we can achieve headless testing using Chrome options class okay now what is the next advantage of chrome options what else we can do other than this headless testing
62:54
Speaker A
what else we can do by using Chrome options class for headless testing we use one method called add arguments in this we pass some parameters along with ADD argument there are many methods are there in the options class for different purposes we
63:07
Speaker A
will call different methods from chrome options class okay now the first use cases headless testing we're able to achieve using Chrome options class now we will see another scenario SSL handling secure socket layer handling that also we can AI by using Chrome
63:29
Speaker A
options listen carefully SSL handling is also another concept what is SSL handling secure socket layer let me show you an example when you're accessing some websites internet or in the real time that website needs something called SSL certificate SSS socket SSL means
63:54
Speaker A
secure socket layers certificate it's a kind of a certificate which is required to browse such type of web pages some kind of security they will provide so if you have this type of certificate SSL certificates then only you can access everything from the web
64:11
Speaker A
page otherwise we can so if you're trying to handle such type of pages through automation that will give you an exceptions so SSL handling by default cannot handle by our automation so we need to do some kind of a settings I'll
64:26
Speaker A
show you practically what is this SSL and everything so I'm just and it is very difficult to find out these type of pages but I found one single page let me show you I'm launching this page expired. bad
64:42
Speaker A
ssl.com see now you will get these kind of Errors if your website is having SSL certificate if your website is trying to suppose if the ssl's certificates needed by the website so you will get this your connection is not
65:01
Speaker A
private so you will see this kind the website is properly fine this is okay fine is saying not secured but we still want to hand still want to access this website normally what we will do in this is we can simply
65:15
Speaker A
say go to Advanced and here you can say proceed to this one unsave even though it is unsafe and we can proceed this so once you click on it now we'll get actual page expired Bas s this is homepage of the
65:29
Speaker A
page nothing else but initially when you launch my web page I got some error kind of thing but when you go to Advanced and select that option now I got this option so that means what I'm uh I'm accepting
65:43
Speaker A
the SSL for that website see again I'm launching this page see already accepted the certificate now I directly go to the web page but when you open this first time will you get the page like this no when you open the first time you won't
66:00
Speaker A
get the page like this once you accepted that SSL then you get this page okay so manually already accepted so now on Words If any number of times you open URL you will directly get into the page but first time when you open the page
66:14
Speaker A
you will not get it okay so let's try this through automation what will happen handling SSL save this new class handle SSL SSL is something security kind of a thing you know need to understand more about this but uh we will know how we
66:41
Speaker A
should know how to handle this if any web page is having SSL how to handle this okay very simple I'm just writing a small piece of code just observe I written this three lines for the same web page I'm importing this
66:57
Speaker A
driver Chrome driver I'm not passing any options nothing I just launch this page and I'm getting the title okay as soon as I launch my page I'll get the title of the web page and see what will happen I'm running through
67:15
Speaker A
automation just observe so this is the error we got right when you open the site manually first time I got this error you said connection is not private so so this is the page you got but now I
67:28
Speaker A
want to handle this I want to get exact page what is the title you're getting is privacy error actually it is not launched actual page it is giving an error page so the error page title is privacy error now we want to handle SSL
67:42
Speaker A
so that we will get actual web page so how to handle SSL we use Chrome options class create variable for Chrome options Chrome options option equal to new Chrome options and then import this chrome options and now yeah how we can set this
68:09
Speaker A
SSL what is a method is available options dot there is a method called set accepted sets this is the method set accept insecure sets this is the method set accept insecure set set is a certificates set accept insecure certificate what exactly we are
68:35
Speaker A
doing is is we are asking accept insecure certificates and by default it is a false now we need to make it as a true by default this setting is false so we need to make it as a true so this is
68:49
Speaker A
a setting so this will accept SSL set certificates from the web page so now if you want to apply this for the driver what do you need to do now we have to pass this options into this drive if I
69:07
Speaker A
don't pass this options here the setting will not be applicable okay so this is a command now execute and see it will directly go to this page and this time we will get a another title of the page because it
69:20
Speaker A
will automatically skip the SSL uh error page now let me run it as Java application so you can see the page see this this time we won't get an error we directly go to the page and now see the
69:37
Speaker A
title This Time title is different after accepting the SSL certificate the title is different so this is the actual page we are expecting but initially before accepting certificate we got a privacy error but after accepting the certificate we got actual title of the web
69:59
Speaker A
page okay it is also same for all the browsers only thing is instead of using this class you have to use another class so as I said beginning if you're working with the Chrome browser you have to use
70:13
Speaker A
Chrome options if you're working with edge browser then you have to use Edge options similarly for every browser specific options class is available and methods are same exactly so whatever methods we are calling here same methods are there in every options
70:30
Speaker A
class understood everyone so this is another use case so Chrome options class also we can use to handle SSL certificates of the web page very very rare case you will get these kind of a scenarios but remember interview point
70:45
Speaker A
of view this is very very important how to handle SSL certificate of the web page by using Chrome options what is a method set accept insecure we can make that property as a true so that op the options we need to pass at
71:01
Speaker A
the time of creating the driver if you don't pass this here the settings will not be applicable okay this is one use case so let me copy this handling SS so this is another use case so can put this this is headless
71:30
Speaker A
testing so this is hsl handling Chrome options is a class Chrome options is a a class so headless testing we have seen second scenario is SSN handling now the third scenario everyone is clear SSL handling yes now the third
71:58
Speaker A
scenario and where else we can use chome options yeah very very use case so let me show you this when you run any automation test case you able to see one option there suppose uh you can run any any any test
72:17
Speaker A
case suppose I'm running this test case when you run your test case any test case through automation on the browser you are able to see this message Chrome is being controlled by automated test software will you see this message every time whenever you are
72:38
Speaker A
launching the page through your automation you're able to see this what this message is saying this message is confirming that this particular page is launched through your automation tool or automation script Chrome is being controlled by automated test software
72:54
Speaker A
but I don't want to see this message every time unnecessarily I don't want to see this message how we can do this at the time of launching my browser through automation I just want to H hide this particular message I don't want to see
73:10
Speaker A
this message so that also we can set by using Chrome options class let me show you so this is another scenario how to remove this option remove Chrome is being controlled by automated so this is there is no much
73:30
Speaker A
use of this okay this this is one of the option which is available in Chrome option just I'm showing you this if you want if you don't want to see that you can hidden that you can hide that if you
73:41
Speaker A
still want to continue no problem that will not impact your execution and because of making hidden you will not get any additional Advantage okay it is just a option which is available if you don't want to see you can make it hidden
73:53
Speaker A
if you still want to see you can continue with that so there is no additional Advantage we won't get anything from this just an option is available that's the reason I'm showing you this okay suppose if you just don't
74:05
Speaker A
if you just want to if you don't want to see this simply what you can do is I can run again same test okay so I can say you can take any test case I'm just taking this again one
74:23
Speaker A
more disable automated message on screen okay so now by default when you execute you already know right by default when you execute you will see that message and every browser so if you want to remove that message okay simply
74:50
Speaker A
what you can do create Chrome options class as usual and using this object we have one method called take this object dot options dot there is a method called set experimental options options dot set experimental option and this is a
75:17
Speaker A
method options dot set experimental option here we have to pass uh few parameters the first parameter is two parameters we have to pass set experimental option we'll take two parameters so first parameter is exclude switches okay this is the option these
75:41
Speaker A
are the options recommended by selenium okay in their official documentation exclude switches this is the first parameter exclude switches comma in the second place we need to create one string object actually that is a new string string array object and in that
76:05
Speaker A
object we have to pass one string called enable ion automation this is little complicated but can just copy the statement somewhere and whenever it is needed you can use it so this is the option they have recommended so exclude
76:22
Speaker A
switches is the first parameter this is is all second parameter from here to here this is all second parameter so new string is a string type of array object in this we are passing one parameter called enable I automation so this this
76:38
Speaker A
particular statement will disable that particular option from the web page okay let's try in and already passing the options in the Chrome driver right so just observe now I'm just removing this option so so every time when you run it
76:57
Speaker A
we will able to see that option but we can see this time you don't see that option so running through automation software is gone so that's you cannot see that this is another simple option which is available if you want to use it
77:13
Speaker A
you can use it or else ignore it's not having much advantage of this this is second remove the Chrome being controlled by automated software so these are the settings and you can copy all these settings in one place so
77:31
Speaker A
that in future if you need this you can just use these commands you don't need to remember anything in this just have these commands with you whenever it is needed you can use in your automations right so this is another use
77:46
Speaker A
case okay now so far we have seen three use cases for Chrome options one is headless testing second one is is SSL handling third one is removing uh Chrome is being controlled by automated test software now fourth use
78:06
Speaker A
case we can run our test in incognito mode or we can run the Tes in privately do you know what is incognito mode see this is my web page so normally when you're working like this when you're browsing the pages
78:26
Speaker A
uh whatever you are doing on the browser everything will be captured and everything will be monitored this is completely public okay so whatever action you're doing on the browser everything publicly available because the communication will happen from front end to back end
78:43
Speaker A
everything is public but if if you want to do this privately suppose tomorrow if someone comes and open your browser and whatever you want to see they can see it but if you execute everything through privately if you browse anything through
78:59
Speaker A
privately nobody can see that that's called incognito mode so how we can achieve this manual is very simple so when you launch your browser here in three dots you can see an option called new incognito window when you click on
79:14
Speaker A
this you'll get the window like this now you can browse it in that window so here I can browse it so this is a private activity you know so this is a purely private activity other people if you access the browser they
79:30
Speaker A
cannot see what exactly you have done in this page or history or cookies or nothing so this is called incognito mode of execution you can see this tab also at the corner you can see Incognito so when you see this
79:46
Speaker A
option uh you are currently running on incognito mode okay so in this case any history or cookies will not be recorded history will not be saved nothing will happen this is completely your private execution so this I want to achieve
80:02
Speaker A
through my automation I want to run my test in incognito mode that's my use case we'll see how we can do this through Automation and all these options are not much important but if you need you can use it otherwise you can ignore it there
80:20
Speaker A
is no much advantage of this so most of the times you don't run anything in Cognito mode but still if you want to run them privately you can do this so another use case is to run the test in
80:32
Speaker A
incognito mode so how we can set Chrome options so now I'm going to run the same test close this take the same test run test incognito mode run test in incognito mode okay now I remove this option same
81:07
Speaker A
D case first thing we need to create a chrome options class okay so we need to create a chrome options class now what is a parameter we have to set to run our test case in incognito mode or options dot add
81:27
Speaker A
argument add arguments in this we need to set a small property just like a headless testing we use add arguments right similarly in headless testing we set another parameter I I headless equal to new but here in add arguments method we have to
81:43
Speaker A
pass another one I iph Incognito iph I Incognito this is the option we have to set on semicolon now we can pass this options in the driver itself so now this time it will launch my browser in incognito
82:03
Speaker A
mode see this my browser is launched in the Incognito mod so now all the execution will normally happen but it will not remember any history it will not remember or it will not capture any cookies nothing it will just blindly
82:18
Speaker A
execute your test case privately or in incognito mode so this is a option which is available to run the test in incognito mode you have to set this parameter okay now what else we can do we can have the extensions on the web
83:02
Speaker A
page so normally when you open the page when you open the browser by default you will see all the extensions whatever you have installed you can see I've installed Uh u u block like block uh you can add you can block the ads right so
83:17
Speaker A
if you suppose when you open the web page by default you will get some Dynamic uh popups ads and everything so I just want to block them so I have used one plugin called uh here this is the one plugin U block and
83:32
Speaker A
I have some more plugins related to selector Hub and so on so by default your page is showing all the plugins here right but when you launch any browser through automation all plugins will be disabled plugin will not be available
83:50
Speaker A
because your automation will open a new instance of the browser so whatever extensions or plugins you have installed in your browser that you can see only in the uh design time that means whenever you launch your page then you can see
84:05
Speaker A
manually but when you launch your browser through automation you will not able to see I think sometime back some people have asked I'm able to see selector Hub here when you're inspecting this option and these extension but when
84:18
Speaker A
you launch this browser through automation I could not inspect any element I could not see the selector Hub and everything right that is how normally it will do but now my requirement is even though I launch my page through
84:34
Speaker A
automation I just want to see my extensions whichever extension I want to still see I should able to see that so how we can make it happen so we can also enable extensions in automation see how we can do this
85:02
Speaker A
enable extensions at run time so normally they are not enabled okay but we have to make them enable at the runtime by setting Chrome options okay finish all right so I'll copy the same code let me take another
85:39
Speaker A
page okay simple uh okay main method is missing okay so I'm just created a simple piece of code web driver home driver and remove the option simple I just created one web driver I'm launching the URL let me run
86:06
Speaker A
this so when you run this page you don't see any extensions are present in this page you can see I just launched page I can see some ads see there are so many ads randomly I can see this and you
86:20
Speaker A
don't see any extension if you click on here you don't see any extensions which are there in this page okay because extensions are not good suppose if you open this page manually I open this page manually like this I can still see the extensions also
86:41
Speaker A
I'm not able to see the ads can you see any ads here in this page no right because this ad blocker you already have this extension so this extension is already blocked all my ads in my web page few ads cannot be blocked but most
86:57
Speaker A
of the ads are blocked by this exchange so I'm able to see all this extension when you open the page manually but I cannot see these extensions through automation when you launch my page through automation this is not there so
87:10
Speaker A
ultimately what I want to do is when you launch this page you can see different kinds of ads on your web page right but I don't want to see that ads if you don't want to see the ads
87:25
Speaker A
what you have done manually you installed particular plugin add blocker so this particular plugin will block all your ads so now through automation also when you run your web page when you launch of web page if you're able to
87:43
Speaker A
make this enable this plugin is enable or this extension is enabl that will able to block the ads right so through automation script you cannot control ads you cannot directly uh handle the ads which are displayed because ads are more
88:01
Speaker A
Dynamic that comes from AdSense so you don't expect what kind of ads will be displayed on the page so through our automation script you cannot control the ads whatever is displaying on the web page but how we can do this by making
88:19
Speaker A
this extension enable add blocker extension enable we can can make our Pages block free so or add free right so that we can do it so there are two concepts will be covered here one is how to make these extensions
88:38
Speaker A
enable at the run time once it is enabled this particular extension will block all our ads you understood my point first thing is through our automation we have to make this extension should be available by default it is not enabl by default is
89:00
Speaker A
not available when you run through automation but we have to make it happen we have to make this extension should be available so that indirectly this extension will block all your ads that is a context clear everyone understood my
89:16
Speaker A
context first thing my overall requirement is what I just want to block my ads on my web page I want to block my ads so that that is disturbing my execution so I want to block all my ads
89:29
Speaker A
so to block my ads through automation directed is not possible only through extension I can block my ads but this extension are not these extensions are not visible through automation when you launch my page through automation the extensions are not enabled so what we
89:46
Speaker A
can do is first we need to make sure whenever you launch your web page the extension should be enabled once it is enabled that extension will take care of blocking the ads okay same thing we can also make
90:02
Speaker A
selector Hub also available at the run time suppose if you run through automation your page is launched through automation you cannot see the selector Hub but still we can make this extension available in the runtime also this is
90:16
Speaker A
the context so now we'll see how we can achieve this there is a process only Chrome options class cannot do it but before that we need to do a lot of things let me show you the context is
90:27
Speaker A
what how to enable extension at the run time we'll see this first how to enable the extension once it is enabled it will start working suppose if you enable blocking ad extension that will block the ads indirectly that we don't need to
90:41
Speaker A
do directly so the extension will take care of it but our job is what our responsibility is what we have to make that enable we need to make that extension enable that's the main thing so to achieve this we we have few steps
90:55
Speaker A
to be followed four steps to be followed let me put those four steps so the next scenario is enable extensions in browser how to enable extension in the browser any extension there is no specific extension so we will use
91:15
Speaker A
extensions of different purposes selector Hub is one extensions add blocker is one extensions suppose whenever some videos are playing if you want to download that video you will use some other type of exception but different purposes different extensiones
91:29
Speaker A
normally we use in our browsers but those extensions will be disabled by default when you run your automation but if you want to make them available this is the process we have to follow okay the first thing is you can apply this
91:44
Speaker A
process any type of extension now there are few steps are there Step number one two three and four step number one is we need to get one specific extractor called CRS extractor or downloader to Chrome browser this is
92:02
Speaker A
another extractor we need to get actually this is also extension from Chrome browser but this extension is needed to get CRX file of the extension that means there are multiple extensions are here so to disable to enable this
92:17
Speaker A
extens extensions through automation first of all we need to have CRX file for every type of uh every type of extension so whichever extension file you have installed or whichever extension you have install on your browser for every type of extension
92:36
Speaker A
there is a CRX file will be available what is CRX file which is a kind of an installer for the extension so we need to capture the CRX file we need to have the CRS file then only we can do all
92:51
Speaker A
these things okay so to get the CRX f file for the extension it can be ad blocker extension it can be selector Hub exception or it can be any type of exception any type of extension we need CRX file which is specific to that
93:06
Speaker A
extension so how to get the CRX file for that extension is matter so here we need to install CRS extracted extension this is also another extension through this we can get the extension of the CRX file of the extension I will show you don't
93:24
Speaker A
confus let me install CRX extractor just type this so go to browser okay so here I'm searching for CRS extractor downloader it is basically an extension for the Chrome browser so go to this so you can find in the Chrome web
93:50
Speaker A
store in the Chrome web store search for CRS EXT raor or CRX downloader so by this what is this plugin will do this plugin will get the extractor file of any other extensions you understand you understood my point why the CRS extractor plugin is
94:10
Speaker A
needed by using the CRX extractor plug-in we can get CRX file of any other extension files let me show you first let me add this to Chrome add to Chrome I'm adding this ADD extension okay done so I have added CRS
94:31
Speaker A
extractor or download so here you can see that so this is here in extension so in this list you can see CRS extractor you can pin it if you want so this is the extractor plugin which we have so what is the use of this
94:46
Speaker A
extractor extenstion is we can extract a CRX file for any other plugins so now let me handle add blocker extension so now what we need to do is go to same Chrome web store and uh Second Step is
95:04
Speaker A
what we need to add selector Hub plug you can add any plugin selector Hub Plugin or any add blocker plugin anything so let me add select our plugin okay let me make enable select our plugin later I will show you add blocker
95:17
Speaker A
okay now in the same Chrome Web Store install any other plugin select Hub we already installed so we already installed so if you don't install you can do it no need to remove okay so now two plugins are
95:33
Speaker A
there so first thing CRS extractor plugin is required to extract the CRX file off any other extensions and we need selector H plugin because this is the plugin I want to make available in the run time suppose if you want to make
95:48
Speaker A
a add blocker and add blocker available in the runtime you need to install that plugin both have in inst so if you look at here I have ADD blocker I also have a selector both I have so but currently we
96:01
Speaker A
will see selector okay so once we have installed these two manually then we need to capture CRX file of selector Hub extension so whichever extensions you want to enable on the browser at the run time you need to get CRX file of that
96:18
Speaker A
particular extension so selector Hub extension I want to make available in runtime so we want to capture CRX file of selector Hub suppose we want to make a add blocker extension enable at the run time now I want to get CRX file of
96:36
Speaker A
add blocker extension everybody's following me so CRX file for which extension we want to get the CRX file whichever extensions we want to enable at the runtime we want to capture CRX file of that particular extension but how to get the CRX file
96:55
Speaker A
to get the CRX file we already added another extension in the beginning CRX extractor by using that plugin you can see this is the one by using CRS extractor we can extract CRX file for any other extensions so now I already
97:13
Speaker A
installed selector Hub now I want to get a CRX which uh extension I want to make it available is selector Hub so I want to capture the CRX file of selector Hub extension how to get it go to web store
97:28
Speaker A
open selector Hub okay just right click on this as soon as you right click you can see an option called download CRX for this extension earlier you won't see this once you install the CRX extension plugin then only you'll able to see this
97:45
Speaker A
this option is by default enabl download CRX for this extension you can use this option download CRX for this EXT once once you click on it it will start downloading the CRX file so this is the CRX file selector hub. CRX that I'm
98:02
Speaker A
going to store in a uh place let me go to somewhere to this PC C drive Automation and uh automation files CRX files so previously already downloaded I'm just going to replace it selector hub. CRX plus that's how we need to download CRX
98:28
Speaker A
file okay now three steps we have done we have to install CRX extractor to Chrome browser because this is the main plugin which will extract the CRX for any other extensions and then we have added selector Hub plugin so that this
98:42
Speaker A
is the plugin which I want to enable at the run time then I have captured the CRX file of the selector Hub extension now I want to enable selector Hub at the run time through automation now go to
98:53
Speaker A
autom inform so in this again I will create Chrome options class Chrome options options new Chrome options okay now import this chrome options okay now what is the method we have to use options dot add extensions this is the method options
99:22
Speaker A
dot ADD extension whatever extensions we want to add to the browser at the run time we need to specify the path of the CRX file which we have downloaded so we already downloaded CRX file for uh selector Hub right where it is on the C
99:38
Speaker A
drive automation automation files and in the CRX files so this is my location in this selector hub. CRX file is present that you need to specify so this is a path actually but before that we need to create one uh
99:57
Speaker A
file object file file equal to new file off and this is a CRX file this is our CRX file and we need to specify the name of the file in the C column in this what is the name of the
100:20
Speaker A
file selector hub. CRX so this is a file name we have to specify and say double double slashes all are double slashes and close it okay now import this file and this particular file we have to pass in add
100:44
Speaker A
extensions that's it okay so this is a so Chrome options we need to create first and we will have the file CRX file wherever the CRX file is present for the particular extension we need to specify the file and that we
101:00
Speaker A
need to pass and finally these options we have to pass in the Chrome driver as usual okay so now when you run the script what will happen the selector Hub will be available for the browser suppose if you
101:16
Speaker A
don't use this setting for example I'm not using this setting if you run your page okay if you launching your page can you see selector Hub on this page can you see selector Hub anywhere if I right click you can't see here and when you
101:32
Speaker A
inspect also when you press F12 even in the dev tools also you cannot see selector Hub anywhere because that extension itself is not there now after enabling this option I'm passing this options into web driver so what I've done I created Chrome options class
101:51
Speaker A
and the file I captured see CRX file of selector Hub that I have attached here in add exchange as so when you run this now we can see selector Hub on that particular web page so even though this
102:05
Speaker A
page is launched through our Automation in this page you can see selector Hub plug-in so once it is launched now you can see select see the option you can see here here also you can see if I click on it here you can see
102:28
Speaker A
select our h l you can pin it and if F2 F12 if I press F12 also here in the D tools you can see selector Hub can see selector okay everybody's understood now how we can enable extension on the
102:47
Speaker A
browser at the run time by default it is not available by default all extensions are disable but we can make them available that's what I'm saying so these are the three steps we need to remember so these are the three steps we
103:05
Speaker A
need to remember first step we need this CRS extracted extension because this is a extension which is used to capture CRX file of any other extension so then add selector H plugin so because this is the plugin we want to make available at the
103:21
Speaker A
run time so anyway we should have it then we need to capture CRX file of selector Hub and then we need to pass CRX file path in our automation script in Chrome options so this will enable Chrome selector Hub plugin at the run
103:37
Speaker A
time so how did you get the CRX of the selector Hub I already shown you I'll show you one more time go to Chrome web store so normally where will search for extensions in the Chrome web store right
103:50
Speaker A
in the Chrome web store you can find selector Hub here it will show you this so this is a installation place right so if you click on here you will get add to Chrome actually if you not install
104:03
Speaker A
selector Hub earlier you will get add to Chrome so you need to install this after that to get extractor CRX extractor simply you can right click on this here you can see one option called download CRX for this
104:18
Speaker A
extension you will get this option only if you install CRX plug-in before otherwise you won't get this option okay here you can get it download CRX for this extension how we will get this option in the first step we have added
104:33
Speaker A
the CRS extraor extension so that will give you that option otherwise you won't get it okay so now same thing we will see for ad blocking so in the browser if you want to block my ads so I have installed one plugin
104:49
Speaker A
called U block this is the plugin I have installed but at the runtime this plug-in is not available so if this plugin is available then I can stop my ads right I can uh block all my ads so this plugin will
105:05
Speaker A
automatically block all your ads so then how we can make iten we'll see so same code but instead of selector Hub we have to use add blocker CRX that's it same thing everything is exactly same I'll show you so if you want to block ads from
105:28
Speaker A
your page you can go with this approach this is the piece of code you can write blocking ads blocking ads the web page okay [Music] so finish so I'm just copy the same code so this page is having so many ads so if
105:55
Speaker A
you open this page manually you can see a lot of ads I just want to block them go back open see as soon as you launch my page you can see so many ads because I already enabled this extension see so
106:10
Speaker A
that's the reason it is blocking me suppose uh if you just uh I just want to disable this plugin for some time so that you can't see any uh if I block this you can see all the ads actually okay so let it be there so
106:30
Speaker A
I have already this plugin so that's the reason I'm not getting any ads here but in the runtime what happens when you launch this page you will get so many ads okay suppose uh I don't want to do
106:43
Speaker A
all these things let's say comment by default when you launch this page you will get so many ads I remove this okay main method is missing okay so I just commenting this remove the options so by default if you
107:18
Speaker A
launch this page you can see so many ads displayed on the web page so this is the page now you can see as soon as you launch my because in this page uh all my extensions are gone see
107:34
Speaker A
there are so many ads right side video ads image ads so many ads you can see so how we can disable this if you have this ad blocker extension enabled these ads will be blocked so when you do this
107:47
Speaker A
manually I already have this plugin it is already blocked 20 ads it is already blocked so if we make this extension enable indirectly this will automatically block all the ads so what we need to make sure is we need to make sure this extension
108:04
Speaker A
should be enabled at the run time so how we can do this add blocker so now we need to we already have installed add blocker extension again same three steps so this we already done and instead of selector hub
108:23
Speaker A
we need to have ADD blocker extension so that also I have installed this is basically uh the name of this extension is you block origin in the Chrome web store if you find you will get it suppose let's go to
108:42
Speaker A
google.com Chrome web store the Chrome web store you can find that uh extension U block or you can use any other extension not only this U block origin search for it now you'll get it this is a one so I already added this so I'm
109:04
Speaker A
getting remove from chrome but in your case you need to add this add to Chrome so this particular extension will block all your ads so I already have this now what is the next thing we need to extract CRX file that's the most
109:17
Speaker A
important so whichever extension you want to enable on the browser we want to get CRX file of that particular extension so what how do I capture the CRX file of this simply right click on this download CRX for the extension
109:35
Speaker A
download So once it is downloaded so where you want to store it you can put anywhere I'm going to C drive and go to automation go to automation files CRX files I already earlier I already have it but again I'm
109:51
Speaker A
replacing with a new one yes okay we got a extractor so what is the next thing we need to get the location of this we need to get the location and name of this file so this is a CRX file name just you need to
110:07
Speaker A
enable this chrome options file options and here we need to just change the name path is same so ublock origin.
110:18
Speaker A
CRX so this is the extension I want to make enable on the browser so this file you have to pass in the add extensions and options class we need to pass in the Chrome drive so when you pass this
110:30
Speaker A
options in the Chrome driver then only this setting will be applicable or else not so this time we are making add blocker extension enable indirectly this will block your ads on the web page because once it is enabled obviously that will block all
110:48
Speaker A
your ads so execute now you can see this time the ad blocker is enabled that should block all your ads see now everything is gone no adds nothing it is already blocked but at the time of launching we
111:19
Speaker A
are able to see one or two but after that everything is blocked and where you can see that extension you can see here block origin still it is available okay so this is how we can enable any type of EX extension on the
111:34
Speaker A
browser at the runtime through this chrome options what is the prerequisite we need to capture CRX file of that particular extension if you have that CRX file of that extension you can make that available on the browser at the run
111:50
Speaker A
time any type of plugin I shown you two plugins selector Hub and add blocker so similarly you can try any other plugins whatever normally we use you can make them available on the browser so this is a concept so how after that the next
112:10
Speaker A
scenario of chrome is enable browser extensions enable browser extensions at runtime so so this is a option here we need to specify the file CRX file okay and then we have seen how to block ads how to block ads on the place using
112:37
Speaker A
U block origin and there is another plugin called add blocker this is also another most popular plug-in most of the people will use to block ads from your web you can use any of them okay so how many many scenarios
112:53
Speaker A
totally we have seen for Chrome options first one headless testing we can achieve second SSL handling third we can also disable this message automated message fourth incognito mode execution we can do fifth we can enable the extensions and then through which we
113:16
Speaker A
can enable yeah this is the one enable extensions at the run time and then we can block ads we can block the ads so totally five to six scenarios we have seen using options okay so understood everyone pleas confirm in the chat
113:44
Speaker A
box so if anybody ask you during the interview what is the use of chrome options what you can achieve then you can tell all these options options list of options okay so on day-to-day basis while automating the test cases you may
114:05
Speaker A
get these type of requirements okay randomly but they're not they are not regular requirements actually but once in a time in that case uh you can have these concepts with you and you don't need to remember anything okay just you should know concept have
114:21
Speaker A
this code with you and all the options and whenever it is needed you can apply them that's a reason and these are not regular things which we are using in our automation so once in a blue anytime if
114:37
Speaker A
you need you can use this options otherwise no headless testing at the in the last stages we do headless testing one or two rounds not every time and suppose you need any extensions are available on the browser then you can
114:53
Speaker A
enable the extensions so it that's the reason I'm saying these are not regular requirement but once in a broom whenever you need you can use these options right so that's all for today's session I'll stop here and we'll
115:08
Speaker A
continue tomorrow
Topics:SeleniumJavaTakesScreenshotWebDriverScreenshotSelenium 4WebElementAutomation TestingChromeDriverTest Automation

Frequently Asked Questions

What is the TakesScreenshot interface in Selenium?

TakesScreenshot is an interface implemented by RemoteWebDriver that allows capturing full page screenshots in Selenium automation tests.

How did Selenium 4 improve screenshot capturing?

Selenium 4 introduced methods on the WebElement interface to capture screenshots of specific areas or elements, in addition to full page screenshots.

Why should the browser window be maximized before taking a screenshot?

Maximizing the browser window ensures that the full visible page is captured in the screenshot, rather than just the default smaller viewport size.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →