Selenium WebDriver Tutorial

Selenium WebDriver Tutorial

Selenium Web Driver is a tool for writing automated tests of websites. It aims to mimic the behavior of a real user, and as such interacts with the HTML of the application. In this Selenium WebDriver Tutorial, we will cover all the WebDriver topics.

Selenium is possibly the most widely-used open source solution.

Simon Stewart developed WebDriver API in 2006.

Selenium is not just a single tool but a suite of software’s, each catering to different testing needs of an organization. It has four components.

Selenium can automate only web-based applications. You can handle window popups by using AutoIT. We will discuss more on AutoIT in AutoIT section.

Supported Browsers:

Selenium supports most of the browsers but we should be noted IDE supports only Firefox and RC and Webdriver supports all most all browsers.

Selenium IDE plug-in available only for Firefox. We can record and run any web application.

Selenium RC supports all browsers but every time we need to run the RC server.

Selenium web driver supports all browsers and we no need to run RC server and it will invoke browsers directly and run successfully.

HtmlUnit driver is used to Run in the background and it won’t display UI. The advantage of HTML unit driver is very fast. This is nothing but headless browser testing.

Mozilla Firefox
Internet Explorer
Google Chrome
Safari
Opera
HTML Unit
Ghost Driver……….

Selenium WebDriver supports all browsers and simply we need to download browser driver and we need to create an instance and we can work on it. As selenium web driver directly invokes the browser.

This is one of the biggest advantages of Selenium as it supports all browsers very smoothly.

Selenium supported programming languages:

Selenium supports most of the programming languages. So, no need to depend on any technology so you can work on selenium with the programming language you familiar.

In IDE don’t have any option to write any script, it’s just a record and playback tool. But you have an option to generate a script in the above-mentioned programming language.

Once you got the script you can add in Eclipse IDE

java
.Net
PHP
Python
Ruby
Perl

Note 1: WebDriver is an advanced version of Selenium RC

Note 2: WebDriver is also called Selenium2

Note 3: Web Driver is faster than Selenium RC as it is directly communicating

with browsers.

Note 4: Selenium RC is slower, as it acts as a middleman in between selenium and

Browser. So every time you run RC server ON before running the script.

Note 5: Web Driver is introduced in 2006

Web Driver limitation:

Web Driver has no built-in feature that automatically generates test results

for executed test scripts. ( for this we use TestNG, JUnit frameworks or our customized

programs).

Download and setup java:

Working on Selenium you need one programming language.  You can write selenium scripts in any programming language. For best practice and most powerful open source programming language is java. So, let’s see how to download and set up java.

Step 1:

First, you need to download and setup java from java official website Click here and you will navigate to the downloads section and click new version or java 8 version to download JDK development kit(JDK).

Just click on “Java SE 8u171/8u172” from the below screen

 

 

 

 

 

 

 

 

 

 

 

Step 2:

Once you click on the above-mentioned link then you will navigate to below screen. Click on accept Licence Agreement radio button and then click on download link based on your system environment.

 

 

 

 

 

 

 

 

Step 3:

Suppose if your system is windows operating system and you have 32 bit then you need to click on windows X86 and if your system is 64 bit then you need to click on windows x64.

Once it is downloaded a just open setup file and run and complete the installation until finish button.

Step 4:

Once the installation is done you can confirm whether java is installed in your machine.

Open the command prompt using shortcut Windows+R and type cmd and hit Enter then command prompt will be open.

Now in command prompt type “java -version” and hit Enter then you can able to see java version. Please check below screenshot for reference.

 

 

Download and setup Eclipse:

Once Java is installed successfully in the system you need to write a java program to run selenium script.

So you need an editor where you can write, store and run java programs. Eclipse is an IDE and its open source tool and it is used to write Java programs.

Download Eclipse:

There are a lot of Eclipse flavors are available to download you can choose any one of the flavors. for example, you can try below flavor named mars.

http://www.eclipse.org/downloads/packages/release/Mars/2

In this package select the first option and select 32 or 64 bit based on your operating system.

Once you click it will get downloaded to your machine and here you no need to install anything as it has application exe file. You can open directly and able to work.

Before start writing selenium script, you need to know few things in eclipse. Let’s see one by one.

  • How to start eclipse and what is workspace?
  • How to create a project in eclipse?
  • How to create new packages and why you need a package?
  • How to create a class and what I need to take care when creating a class?
  • How to add selenium jars file to project?

How to start eclipse and what is workspace?

Open the eclipse folder where you have downloaded and double click on eclipse application.exe file like below screenshot and it will get launched successfully and it will ask for workspace.

 

 

 

 

 

Workspace:

Here you will get the question what is workspace? Workspace is nothing but folder where you want to save your projects.

You can give any name for workspace and click OK then it will get saved. Henceforth whatever projects you do it will get saved in the specified workspace. Later you can create multiple workspaces if you need.

As of now let us create a new workspace named as “AutomationTesting”. Please verify below screenshot.

 

 

 

 

 

 

When you click OK button workspace will be created in the name of “AutomationTesting” and eclipse will be launched and it will display welcome screen for the first time.

 

 

 

You can close the welcome screen as of now because it will give overview and sample details about the eclipse.

How to create a project in eclipse?

The project is a collection of artifacts like source code and related files to accomplish the task.

As a tester, you need to create a new java project such that you can work and save your scripts under this project.

To create new java project just click on File–>New–>Java Project. Please verify below screenshot.

 

 

 

When you click on java project you will be prompted with below screenshot where you can give project name and you can give project name as per your wish. Project name sample is given as “DemoTour”. Please verify below screenshot.

 

 

 

 

 

 

 

 

 

 

 

Once a user clicks Finish button you can see the project is created and displayed at project explorer section at left panel and if you expand it will show src and Java Library by default. Please verify below snapshot.

 

 

 

 

 

 

 

How to create new packages and why you need a package?

Package: Package is a collection of similar classes or nothing but a group.

You can create a package by right click on src –>New–>Package

 

 

 

 

 

 

 

 

When you click on “Package” you will be prompted with below screen where you need to enter a package name and click Finish button. Please verify below screenshot.

 

 

 

 

 

 

 

 

 

 

Once you click Finish button you can see the new package is created under src folder.

 

 

 

 

 

 

Note: Package name should start with small letters.

How to create a class and what I need to take care when creating a class?

How to add selenium jars file to project?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You May Also Like

About the Author: Azgar Khan

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *