Scientech Easy Selenium Tutorial | Components of Selenium | Example | Scientech Easy

Friday, November 16, 2018

Selenium Tutorial | Components of Selenium | Example

In this tutorial, we will learn the basic introduction of Selenium and components of selenium with real-time examples in an easy way. Real-time examples will help you to understand the selenium more easily and you will not get any problem to learn the concepts.

What is Selenium?

Selenium is a free and open source functional automation testing tool which is used to test the functionality of the web-based application. It is originally developed by Jason Huggins in 2004. It is one of the most popular and well-known testing frameworks in the world that is in use. Selenium has been built using JavaScript which can work in any browser that supports the JavaScript. 
Basically, Testing is mainly divided into two categories. First is Functional testing and second is Non-functional testing. In functional, we have two kinds of testing: Manual testing and Automation Testing.
In manual testing, our main activity is to write the test cases. These test cases will be executed manually by some resources but when comes to automation testing, all the manual test cases will be converted into the test scripts with the help of some automation tools like Selenium, QTP, RFT etc. Thus, The process of converting manual test cases to the test scripts with the help of some automation tool is called automation testing. The main advantage of using these tools are we can save time. 

Let's see a simple real-time example:
Suppose you have to go from place A to place B which is 1 km apart. There are multiple ways to go from A to B. Manually, you can go by walk but it will take more time. Another way is by using some vehicles like a bike, car,  bus etc. It will save time. Here, the vehicle is nothing but the automation tool. 

Another real-time example:
Suppose you are working for an IT company and you have to execute around 500 test cases manually then how many test cases can you execute manually? You can execute 50 to 60 test cases manually per day. Here, per day means 8 hours working in the company.  Thus, to execute all these 500 test cases will take time around 9 to 10 days. Now suppose Technical Lead came and says that you will have to execute all these 500 test cases in 4 to 5 days then what will you do? In this case, you will have to go for automation testing but it is not possible to execute entire testing. Means 100% testing is not possible using automation but the majority of test cases can be executed.

Suppose 400 test cases can be automated and the remaining 100 test cases is not applicable for automation. In this case, we will use manual testing. So, it will take around 2 days manually where 400 test cases will take time 0 days because once test scripts are ready and working fine then we will put all these test cases in run mode at any time (day or night) and leave them to execute all test cases. When the execution process is completed, we will check results that how many test cases are passed or failed by taking screenshots? That's why it will take 0 days but take sometimes to execute all test cases. Thus, we have taken around two days to execute all test cases and saved time.

Selenium Components

There are four components available in selenium suite to automate the web application. They are as follows:
Selenium tutorial, Components of selenium, Selenium tutorial for beginners,selenium, selenium training, Selenium java tutorial.
Components of Selenium

1. Selenium IDE
➤ IDE stands for Integrated Development Environment. It is a tool to develop test cases. 
➤ Selenium IDE was developed by Shinya Kasatani of Japan who donated Selenium IDE to the main Selenium project in 2006.
➤ It is an easy-to-use Firefox plugin which supports the only Mozilla Firefox. It does not support any other browser.
➤ You can create and edit test cases and test suite.
➤ It is based on Javascript framework that is not a pure object-oriented tool. 
➤ Selenium IDE supports record and playback features for generating and executing the test scripts in Firefox browser. Let's take one real-time example to understand the concept.

Real-time Example
Suppose you have a mobile. In the mobile, you have an option like audio recording features. How will you record your voice for 1 min? For recording, you will put your mobile in the audio recording mode and start to speak something for one minute. When one minute is completed, you will playback it to check the recording. 
The same kind of actions occurs in the Selenium IDE. In the Selenium IDE, we record our test cases like logging, send email, compose, register etc depending on the applications. Once the recording is completed, we can playback to execute them. If required, we can also execute in other browsers with the help of Selenium RC  and web driver. By default, it will record in the HTML language only but you can convert the recorded language into other languages also.
Selenium IDE is accountable for user actions. That means whatever the actions you are performing like opening URL, clicking on some button, selection value from the drop-down etc, All these actions are recorded and generated into the scripts. Initially, it will give you in the HTML language. After recording, It is played-back again and again to reperform that actions. Recording, as well as execution, can be done in the Firefox only.


2. Selenium RC
➤ It's full name Selenium Remote Control. It is also known as Selenium 1.0. It was designed by Paul Hammant.
➤ Selenium RC is an open-source automated testing software to test web-based applications.
➤ It is based on Javascript framework and a semi-object-oriented tool. 
➤ In 2007-08, the Test Automation Engineer could be able to control and automate the entire application by using Selenium RC. He can perform the actions like clicking on a button, entering text into a TextBox, selecting the value from drop-down box etc and test the whole functionality of web application. That's a reason that the given name with the selenium is remote control.
➤ Selenium RC requires a server to be started before the execution of the test script. A server is responsible to serve your request in the selenium RC. 
For example, Suppose you have a Gmail account. You have entered a user id and password. After entering credential, it will send your request to the server and the server will send your request to the database then server will take the response from that database and the response will be given back to the application. 
Serving request

Whatever the test cases we create, these test cases are converted into the test script. After that, the Test script is compiled and ran against the selenium server(Selenium RC) that uses a series of Javascript libraries to perform the actions such as clicking on a button, entering the text into the Textbox, selecting a value from a drop-down etc. against web browser. Selenium RC can run against all major web browsers that are javascript enabled(e.g Chrome, Firefox, IE, Safari). 
➤ It supports several programming languages like Java, C#, Ruby, Python, PHP, Perl, and Javascript to create the test script.
➤ It does not support record and playback feature.

3. Selenium Webdriver
➤ Selenium web driver is a latest, free, and open source library to automate the web applications. It is a pure object-oriented tool.
➤ In 2008, Selenium RC was merged with another testing framework called WebDriver to develop a more powerful tool called Selenium 2. That's why it is called Selenium WebDriver. It was developed to support the dynamic web pages and advanced web application testing. Selenium 2.0 was released in July 2011.  
➤ The main aim of selenium web driver is to automate the web applications and make sure that the website is working as expected. It contains a variety of classes and methods to meet our requirement. 
➤ It supports different programming languages such as Java, Ruby, Perl, PHP, Python, and .Net to create the test scripts. 
➤ It supports different browsers like Firefox, Chrome, Internet Explorer, Safari etc.

4. Selenium Grid 
The Selenium grid was developed by Dan Fabulich and Nelson Sproul with the help of Patrick Lightbody in 2005 to minimize the test execution times as much as possible. 
It provides a cross-browser testing environment with several different browsers (such as Firefox, Google Chrome, Internet Explorer etc) and different platform(Window, Mac, and Linux) to execute a test.    
Selenium grid uses the hub-and-nodes concept. The hub acts as a central point which has the information of all different testing platform, known as nodes. All nodes are connected to a hub that enables simultaneous execution of tests in multiple browsers. It provides parallel execution of tests to save a lot of time. Let's see an example to understand the concept.
For example
Suppose we have automated 100 scripts in 2 hours by using web driver in Firefox browser. Now my plan is to run all these 100 scripts in different browsers such as internet explorer, Firefox, and chrome. Suppose each browser is taking 2 hours to execute all 100 test scripts. So all three browsers will take time 6 hours to execute.
If we use selenium grid, we can execute all my 100 test scripts parallelly on all three browsers. Thus, the main advantage of using selenium grid is that we can launch all browsers parallelly and the script can be executed in all browsers at the same time so that we can save time. We can use total 5 browsers by using the grid.

Selendroid 
➤ Selendroid is one of the best and most powerful testing tools for Android application. It is an automation testing framework to test multiple types of mobile application like native, hybrid, and web.
➤ Since Selendroid uses the Selenium WebDriver framework so we can write the test scripts using the Selenium 2 client APIs.
➤ Using the Selendroid, you can run tests in parallel on multiple devices.
For example
Suppose we have a Gmail web application and have tested on my system. Now we want to test the same Gmail web application on the android mobile. So this test can be performed by using the Selendroid to test the web application on the android device.  

Appium 
➤ Appium is an open source mobile automation framework which is used to test the native, hybrid, and web mobile application on iOS and Android operating system with the help of Selenium web driver. 
➤ It replaces the Android driver and iPhone driver APIs in the selenium 2 that were used for testing mobile applications. 
➤ Since Appium uses Selenium WebDriver to drive the tests so we can use any programming languages like Java, JavaScript, C#, Ruby, Python etc to create tests. 
➤ It provides cross-platform mobile application testing.

How to choose the Right Selenium Tool for your Need

You do not need to learn all the above selenium tools but knowing the basics of each component will be helpful and it will boost your confidence in selenium. Generally, We have to work with the most powerful tool WebDriver because WebDriver is the main driving tool to automate user actions on different browsers and different operating system. Each browser provides their own driver such as Firefox driver, Chrome driver etc to automate actions. 

If you have enough number of tests to automate and want to run all tests in parallel then you may use Selenium Grid to run your tests on different browsers in parallel. Selenium IDE is just a record and playback features tool which you can use to record your scripts and replay to execute. RC is basically selenium 1 where the core components were written in Javascript. Selendroid and Appium are used for used for testing mobile web application. As far as learning is concerned, You can learn WebDriver, selenium grid, Selendroid, and Appium. You do not need to learn selenium 1 in order to learn selenium 2 or 3.

Difference between Selenium & QTP

SN Selenium QTP
1. Selenium supports almost all popular browser such as Firefox, Chrome, IE, Opera etc QTP supports only Chrome, Firefox, and Internet Explorer browser.
2. Selenium supports operating system like windows, Linux, and Mac. QTP supports only the Windows operating system.
3. Free open source tool. Licensed tool(Commercial tool)
4. It supports only testing of the web-based application. QTP supports both web and windows based application.
5. Object repository needs to be created in selenium QTP automatically creates and maintains object repository.
6. It supports multiple programming languages like C#, Java, Python, Ruby etc. QTP supports only VB script.
7. We can execute tests in parallel. In case of QTP, we can execute tests in parallel only using Quality Center which is again paid product.

Note: QTP stands for Quick Test Professional which is the product of Hewlett-Packard. It uses Visual Basic Scripting (VB Script) for automating web and windows based applications. 

Final words 
We hope that this basic selenium tutorial article will help you to learn selenium and its components with real-time examples. Real-time examples will help you to understand the basic concept of selenium.



Popular