Category
📚
LearningTranscript
00:00Hi everyone, in this video we are going to see how to set up and configure Selenium WebDriver
00:06and also we will see how to write the first Selenium script. So let's get started and
00:13how Selenium WebDriver works. Let's say for example we have a browser.
00:19And we perform some user actions on this browser and we wanted to automate these actions and that
00:25can be done using Selenium WebDriver. And we discussed what's a WebDriver in the
00:32introduction section. So WebDriver is a set of libraries. Using these set of libraries
00:39WebDriver is going to communicate with the browser, right? And how are we going to use
00:45this WebDriver, you know, to write the automation scripts. So for that we can have
00:52any ID of our choice. ID is integrated development environment. So it's a code editor like Eclipse,
00:59NetBeans, IntelliJ, any editor, right? Code editor you can choose and we write the script using this
01:06code editor. And how do we write the code is WebDriver has said it's a set of libraries.
01:12Meaning library is a collection of, you know, jar files and each jar is in turn a collection
01:18of packages and classes, right? So using the again the classes will have methods, right? So
01:25using these classes and methods of, you know, this WebDriver. So this has methods and classes
01:33and we'll use this class and methods and write the automation script in using this IDs, right? And
01:41WebDriver knows anyway knows how to communicate with the browser. So this is how we are going to
01:47write the script and this is how WebDriver will communicate with the browser. And this is how,
01:52you know, WebDriver works. WebDriver is called as API application programming interface as it
01:58acts as the interface between our, you know, our code editor and the browser, right?
02:04Now, as a first step, what we'll do is WebDriver is an open source. Selenium is an open source,
02:10right? So we are going to download this WebDriver and as a second step, we'll open any ID of our
02:18choice. And then we'll configure. We'll see how to configure this WebDriver in our ID,
02:24followed by a first script we are going to write using Selenium. All right, so
02:30just type Selenium.dev you'll be navigated to the official website of Selenium. So this is the
02:41official website of Selenium. You can see the components, three components which we discussed,
02:45right? These are the three components Selenium WebDriver, ID and
02:52Selenium. So you can see downloads here. Just click on this downloads,
02:57click on this downloads, slowly scroll down. You will see the WebDriver language bindings, right?
03:02So these are the programming languages supported by Selenium. You can find Java here and you see
03:07a stable here, right? So a link here always you'll have a latest stable version for download here.
03:15So don't bother about this version. Just go ahead and click on this link and always download the
03:20latest stable version. Now see a zip file is started getting downloaded, right? So
03:27fully and once the download is done, right? So you will see something like this, the zip file, right?
03:36This zip file. So just ignore all the other files. Just see this file. So this is how you'll
03:42get a zip file in your case. And it's always a practice to actually create a folder, maybe in
03:49any drive. I created it in my C drive. So with the name drivers and copy this zip file here and
03:56then extract it. Right click extract all. I already extracted this file. You can see that here.
04:01Just open this. Once the extraction is done, you can see number of jobs.
04:05I'll click on create a Java project as that will be the first step, right?
04:10I created a project. I'm going to create a package. I'll name my package as something like com.sample
04:24and then we'll start creating the class. Okay, let's create a class. I'll name my classes
04:32first Selenium script.
04:40Alright, first step. What we'll do is we'll actually add the web driver to our project.
04:45And how do we do that? Right click on the project, go to properties, click on Java build path.
04:51You'll see the number of tabs here, right? So click on libraries. Click on the add external
04:59jars and you can see here, right? I'll navigate to the web driver folder where you extracted it.
05:07So you can see all the jar files here, right? So just do control A and then click on open.
05:19So all files got added. Go back and select all meaning do again control A.
05:26Exclude lib directory as we already added the files under it.
05:31And click on open again. So all the jar files got added to the project. Now just click on apply and close.
05:37So we have the libraries which come with the web driver. We added them to our project now.
05:43Alright, now we are ready to write our first automation script. So I created a class.
05:48So I have a main method in it and I'm going to write the first automation script now for that.
05:54The first step would be system.setproperty.
06:03So system is a class and set property is a method which actually takes two parameters key
06:09and a value pair. So a key and a value pair. So key will be webdriver.chrome. I'm going to use
06:17browser as Chrome here. So webdriver.chrome.driver and value will be the executable for the browser,
06:26right? And how do we get the executable? So what's the executable first of all so
06:31executable of a browser is so webdriver needs to launch the browser, right?
06:37So to do any user action it needs to launch the browser and how do it launch so it needs
06:43the executable. So we need to download the executable and for that we'll again go back
06:48to the official documentation of Selenium and slowly scroll down here. You will find
06:54something called browser. So click on that here. You see all the supported browsers by Selenium.
07:00So as we wanted to, you know, automate the script for Google Chrome. So just click on
07:05Chrome documentation.
07:11You will see all versions available in downloads and latest beta release latest table release
07:15as well, right? So how do we download or which file to download for that? We need to know which
07:23Chrome version we are using how to find Chrome version is you see three dots on the top right
07:29corner, right? So click on that go to help about Google Chrome. You will see the version of your
07:35Google Chrome. So the first two numbers are the first number which comes before the dot, right?
07:42So that's called major version and whatever is after that is called as minor version. So you
07:47don't need to bother about this minor version at least before the dot should be considered
07:55till here, right? This is my Google Chrome version so that we need to find it out here.
08:04So if you don't find that here as a latest table release, so you will actually click on
08:09this downloads and find the correct executable Chrome driver executable, right? So here in my
08:16case, it actually matched with the major and minor version till the this dot, right? So
08:23just click on this. And again, you will see a list of files here for each operating system, right?
08:30And I wanted to download this Chrome driver executable for my Windows operating system. So
08:36I'm going to click on this zip file so you can see the zip starts getting downloaded, right?
08:42So in my case, it I already downloaded. I just cancel it. So in your case, you'll just proceed
08:46and allow the download to complete fully. And then you can see here as I have many folders.
08:55So I just created another folder with my Chrome version and copied my zip file here.
09:01So this is Chrome driver executable, right? Let me extract this.
09:10And open this folder you see an executable here, right? This is the Chrome driver executable
09:15and this we need to provide it in the system dot set property value. So we need to provide
09:22the full path and how do we get the full path? If so, just hold hold on shift key and right click
09:29you will get an option as copy as path. And remember you need to hold on shift key. Otherwise
09:34you will not get this option. I'll show you see I didn't hold the shift key so you'll not find
09:39this copy as path now. So only if you press if you hold down shift key and right click only
09:45then you will find this copy as path. Just remember that and click on this copy as path.
09:52Go back copy this path you will get a extra slash here extra quote. Just remove that
10:00at the beginning and end. So what did we do here? We wanted to let the web driver or the let
10:08the program know where the browser executable is present so that we actually specify in the value
10:16and the key will be the driver. So driver variable web driver dot Chrome dot driver. So this will
10:23be assigned the executable so that the program knows how to or the web driver knows from where
10:30to actually pick up the executable and launch the browser. So that will be the first step in the
10:36while writing the automation script. And this browser can be any browser supported by Selenium.
10:43We have just chosen Google Chrome as an example here, right? So the second step will be or the
10:50second line of code. It would be web driver. We'll be creating a object of web driver interface
10:58and will instantiate it to the Google Chrome. Right Chrome driver.
11:07So Chrome driver is a class here which is actually implementing the web driver interface.
11:12So we discussed web driver is an interface, right? So Chrome driver is a class which is
11:16implementing the web driver interface here. So we are getting error. As we need to import this
11:23web driver interface into our project, right? So import web driver from org.openqa.selenium.
11:30Just click on this. So it gets, you know, imported from this package. Same goes for
11:37the Chrome driver class as well. So import it from org.openqa.selenium.chrome. This is
11:42the package where this Chrome driver class is present. That's all we are done with, you know,
11:51writing the first automation script, right? So right click. Run as Java application.
12:00So it should launch the Chrome browser. See it launched the Chrome browser and you can see
12:06a note also here. Chrome is being controlled by automated test software.
12:09This is coming from the Google.