Welcome to the Selenium-Java series. This is the first tutorial in this sereis. In this tutorial we are going to study about selenium-webdriver overview plus how to download and configure selenium-java jars in eclipse from scratch!!
What you will Learn (Ctrl+Click to follow link):
Selenium Webdriver overview
Selenium Webdriver Architecture
Java API document
Limitations of WebDriver
Create Java project in eclipse
First Java class
Add Selenium java jars in eclipse
Selenium Web driver overview:
Selenium is a browser automation tool which interacts with browser and automate end to end tests of a web application.It is a suite of tools: Selenium IDE (for record and playback), Selenium grid (to execute tests in parallel in different browsers/machines) and Selenium web driver.We will be using selenium web driver for automation.
- Selenium Web Driver is a browser automation framework that accepts commands and sends them to a browser. It is implemented through a browser-specific (chrome, Mozilla, IE) driver. It controls the browser by directly communicating with it. Selenium Web Driver supports Java, C#, PHP, Python, Perl, Ruby.
- Operation System Support – Windows, Mac OS, Linux, Solaris
- Browser Support – Mozilla Firefox, Internet Explorer, Google Chrome, Safari, Opera, Android, iOS, HtmlUnit
Selenium Web driver Architecture:
See figure 1. There are 4 components of Selenium architecture:
1) Selenium client library/Language bindings:- Selenium Developers have developed language bindings to allow Selenium to support multiple languages libraries such as Java, Ruby, Python, etc.
2) JSON Wire Protocol over HTTP:- JSON stands for JavaScript Object Notation. It is used to transfer data between HTTP server and a client on the web. Each Browser Driver (such as Firefox Driver, Chrome Driver etc.,) has its own HTTP server.
3) Browser Drivers:-Each browser has its own separate browser driver. Browser drivers communicate with respective browser. When a browser driver receives any command then that command will be executed on the respective browser and the response will go back in the form of HTTP response.
4) Real Browsers:-Selenium supports multiple browsers such as Firefox, Chrome, IE, Safari etc.
Java API document:
Go to the website https://www.seleniumhq.org/download/& click the API docs seen against Java
The below page comes up. On the left hand panel, search for Web Driver. Since Web Driver is an interface, it is seen in italics. As can be seen on the right hand panel, all the web browers (example, chrome driver etc) implement this interface. We will study more about this interface in further tutorials.
Limitations of WebDriver:
WebDriver Cannot Readily Support New Browsers. Remember that WebDriver operates on the OS level. Also, remember that different browsers communicate with the OS in different ways. If a new browser comes out, it may have a different process of communicating with the OS as compared to other browsers. So, you have to give the WebDriver team quite some time to figure that new process out before they can implement it on the next WebDriver release.However, it is up to the WebDriver’s team of developers to decide if they should support the new browser or not.
Create Java project in eclipse:
File >New >Java project
Enter java project name
Next, you see that, DAY1 project would be created that will contain src folder
Finish. Now, right click on DAY1 project
Click ‘Properties’>click ‘Java Build Path’>click ‘Libraries’ tab. You will see that java libraries are already added, see below
First Java class:
Create first java class having the main method. To do that, expand DAY1 folder & right click ‘src’ folder > click ‘New’ > click ‘Other’, see below
The below window comes up. Expand ‘Java’ & select ‘Class’, see below
Click ‘Next’, below window comes up. Enter class name ‘Demo’ & select the checkbox
‘public static void main(String[] args)
Click Finish. Write the print statement System.out.println(“Welcome!”); as seen below
Right click on the program > Run As > Java Application, see below
You would see ‘Welcome!’ gets printed in console.
Add Selenium Java jars in eclipse:
Now this java project DAY1 that we have created does NOT have any knowledge about selenium. So let us add that knowledge by adding selenium jars.Selenium is not a tool. It’s a jar file package.Go to official website https://selenium.dev/> Downloads >you will see the current version of selenium-java jars is 3.141.59
Click ‘Download’ link >unzip jars
Go inside selenium-java-3.141.59 folder. You will see few jars outside ‘libs’ folder
Go inside ‘libs’ folder. You will see few jars inside ‘libs’ folder
Go to java build path (Right click on DAY1 project >Click ‘Properties’ >click ‘Java Build Path’ >click ‘Libraries’ tab)
Click ‘Add External jars’, the below window comes up. Browse to the location in your machine where you have downloaded the selenium jars, see below. Select all the jars outside ‘libs’ folder
Click ‘Open’. The jars should be seen as added in the ‘Java Build Path’ like seen below
Click ‘Add External jars’. Select all the jars inside ‘libs’ folder like seen below
Click ‘Open’. So we should see all the jars added in the ‘Java Build Path’ like seen below (7 jars in this case)
Click ‘Apply and close’. So we have now made a connection between selenium & java project
In the next tutorial, we would study about how to inspect elements in various web browsers.
Thank you for reading!!!