Best Selenium Tutorial | Quickstart [ 2020 ] - MUST-READ

Best Selenium Tutorial | Quickstart – MUST-READ

Selenium Tutorial

About author

Kavita Srinivas (Senior Test Lead )

Kavita Srinivas is a Senior Test Lead, who guides and monitors the analysis, design, implementation, and execution of the test cases, test procedures, and test suites. She has 9+ years of experience with Selenium-Java, Test NG, Junit and Cucumber, HCM, Payroll, Comp, Absence, and Recruiting, JIRA & PoVs, Selenium, JUnit/TestNG.

Last updated on 04th May 2020| 3605

(5.0) | 19678 Ratings

What is Selenium

Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite.It was originally developed by Jason Huggins in 2004 as an internal tool at Thought Works. Selenium supports automation across different browsers, platforms and programming languages.

Selenium can be easily deployed on platforms such as Windows, Linux, Solaris and Macintosh. Moreover, it supports OS (Operating System) for mobile applications like iOS, windows mobile and android.

Selenium supports a variety of programming languages through the use of drivers specific to each language.Languages supported by Selenium include C#, Java, Perl, PHP, Python and Ruby.Currently, Selenium Web driver is most popular with Java and C#. Selenium test scripts can be coded in any of the supported programming languages and can be run directly in most modern web browsers. Browsers supported by Selenium include Internet Explorer, Mozilla Firefox, Google Chrome and Safari.

selenium

Selenium can be used to automate functional tests and can be integrated with automation test tools such as Maven, Jenkins, & Docker to achieve continuous testing. It can also be integrated with tools such as TestNG, & JUnit for managing test cases and generating reports.

First Glance at Selenium

Selenium is one of the most popular Automated Testing suites. Selenium is designed in such a way to support and encourage Automation Testing of functional aspects of web-based applications and a wide range of browsers and platforms. Due to its existence in the open-source community, it has become one of the most accepted tools amongst the testing professionals.

Selenium supports a broad range of browsers, technologies, and platforms.

Selenium-technologies-and-browsers

Selenium Components

Selenium is not just a single tool or a utility, its rather a package of several testing tools, hence it is referred to as a Suite. Each of these tools is designed to cater to different testing and test environment requirements.

The suite package constitutes of the following set of tools:

  • Selenium Integrated Development Environment (IDE)
  • Selenium Remote Control (RC)
  • Selenium WebDriver
  • Selenium Grid

Selenium RC and WebDriver, combined together are popularly known as Selenium 2. Selenium RC alone is also referred to as Selenium 1.

Selenium-packages

    Subscribe For Free Demo

    [custom_views_post_title]

    Brief Introduction To Selenium Versions

    Selenium Core

    Selenium is a result of the continuous efforts by an engineer named Jason Huggins from ThoughtWorks. Being responsible for the testing of an internal Time and Expenses application, he realized the need for an automation testing tool in order to get rid of repetitive manual tasks without compromising quality and accuracy.

    As a result, he built a JavaScript program, named as “JavaScriptTestRunner” in early 2004 that could automatically control the browser’s actions which seemed very much similar to that of a user communicating with the browser.

    Henceforth, Jason started demoing the tool to a vast audience. Eventually, the discussions were laid out to categorize this tool in an open-source category and its potential to grow as a re-usable testing framework for other web-based applications.

    The tool was later acclaimed with the name “Selenium Core”.

    Selenium IDE (Selenium Integrated Development Environment)

    Selenium IDE was developed by Shinya Kasatani. While studying Selenium Core, he realized that this JavaScript code can be extended to create an integrated development environment (IDE), which can be plugged into Mozilla Firefox. This IDE was capable of recording and playing back the user actions on a Firefox instance to which it was plugged-in. Later on, Selenium IDE became a part of Selenium Package in the year 2006. Later this tool turned out the great value and potential to the community.

    Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback features make it exceptionally easy to learn with minimal acquaintances to any programming language. With several advantages, a few disadvantages accompanied Selenium IDE, thus making it inappropriate to be used in case of more advanced test scripts.

    Adv-and-disadv-of-selenium

    Advantages and Disadvantages of Selenium IDE:

    The disadvantages of IDE are really not disadvantages of Selenium, in reality. Rather they are just limitations to what IDE could achieve. These limitations can be overcome by using Selenium RC or WebDriver.

    Can I learn Selenium on my own?

    Yes, if you have basic programming knowledge, you can learn Selenium on your own, just start from chapter-1 of our course. Our course is completely free and designed for complete beginners.

    Can I learn Selenium without knowing Java?

    In order to learn Selenium WebDriver, you need to have knowledge of the languages supported by Selenium like – Java, Python, Ruby, etc. If you have no programming language knowledge then you can either start learning any language or you can pick an automation tool that requires no or minimal coding like – Katalon Studio.

    How many days it will take to learn Selenium?

    You can learn basic website automation in a couple of days only but for complete Selenium features and test automation framework knowledge, it will take you about 2-3 weeks of consistent study and practice.

    Getting Started with Selenium using Java

    To kickstart Selenium Webdriver with Java, one needs to bring the different components together, to start coding.

    Selenium is compatible with multiple operating systems like Windows, Linux, Solaris, Macintosh. It also supports multiple browsers like Chrome, Safari, IE, Edge, Firefox. It is used to automate functional tests. Also, Selenium is easy to integrate with tools like Jenkins, Maven, and Docker to achieve a continuous testing approach. Tools like TestNG and JUnit further help in structuring the selenium tests for easy maintainability and generating reports.

    In this section, we explain how to set up and run a simple test through Selenium with Java bindings.

    Pre-requisites for Setup Configuration

    The following components are required to get started with automation:

    • Java(JDK)
    • Eclipse
    • Selenium Client and WebDriver Language bindings
    • Configuring Selenium Webdriver with Eclipse
    • Creating and Running the first test

    Step:1 – Install Java

    A Java development kit which includes the JRE (Java Runtime Environment) is required to write and run Java programs. JRE is a child of JDK, which comes along with JDK installation. Even for running applications that need the dependency of Java, one needs to install JDK. One such application is Eclipse IDE. Download Java, install it and set the environment path. Once the path is set, one can verify the installation by typing java -version on the command prompt, which provides the details of the installed java version. Refer to the following image for better understanding.

    Selenium-Java-Tutorial-cmd

    Step:2 – Install Eclipse

    Eclipse is a platform for Java developers to write their code and run it. Download Eclipse from their office page. Based on the OS, one can go with the required option. Once downloaded, extract the downloaded file. Once completed, one can see the eclipse .exe in the eclipse folder:

    Selenium-Java-Tutorial-Install-eclipse
    Course Curriculum

    Get Advanced Selenium Training for Beginners to Enhance Their Career

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    Step:3 – Selenium Client and WebDriver Language Bindings

    Selenium Webdriver supports multiple languages, and each language has its client driver. As we are using Selenium with Java, we need to have ‘Selenium Java Client Driver’. One can download the client driver from the official Selenium website. One can see the multiple language client drivers provided by Selenium:

    Selenium-Client-and-WebDriver-Language-Bindings

    Once downloaded, extract the contents of the downloaded file and then move to the next step, which is configuring Selenium Webdriver with Eclipse.

    Step:4 – Configuring Selenium WebDriver With Eclipse

    This is a vital step of starting with Selenium. To configure Eclipse with Selenium Webdriver client,

    • Double click on the eclipse.exe file to launch it
    • Create a workspaceThink of it just like any other folder, which stores all the scripts in one place. One can choose to create as many workspaces as required. Click on Launch to launch the workspace.
    • Create a new java project by clicking on File-> New-> Java Project and name the project
    • Create a package under this project, by right-clicking on the ‘src’ folder
    • Once the package is created, right-click on the package and create a class. Once the class is created, go ahead with adding the Selenium Jars to the project.
    • To add the Selenium Jars, right-click on the project folder and go to Properties:

    From the Properties window, navigate to ‘Java Build Path’ and click on ‘Add External JAR’s

    Selenium-Properties-for-Browser-stack

    Add the downloaded Selenium Jars and click on ‘Apply and Close.’ Selenium with Eclipse is configured now. Now Eclipse is ready to execute the first script.

    Step:5 – Creating and Running the first test using Selenium and Java

    As the first test, we will write a script to open ‘google.com’ on the Chrome browser. To use Chrome, it is mandatory to have the driver executable. To download the driver executable, visit the Selenium website. In the third-party driver browser section, one can download the executable file for a specific browser.

    Post downloading, below is the code snippet to run the first test:

    • import java.util.concurrent.TimeUnit;
    • import org.openqa.selenium.WebDriver;
    • import org.openqa.selenium.chrome.ChromeDriver;
    • public class FirstTestInSelenium {
    • public static void main(String[] args) {
    • // TODO Auto-generated method stub
    • //setting the driver executable
    • System.setProperty(“webdriver.chrome.driver”, “.\\Driver\\chromedriver.exe”);
    • //Initiating your chromedriver
    • WebDriver driver=new ChromeDriver();
    • //Applied wait time
    • driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    • //maximize window
    • driver.manage().window().maximize();
    • //open browser with desried URL
    • driver.get(“https://www.google.com”);
    • //closing the browser
    • driver.close();
    • }
    • }

    In the code snippet above, we have used the Selenium keyword driver.get(“URL to open in browser”) to open URL in the desired browser. Other keywords like driver.close help to close the browser window, as a cleanup part.

    So, this was a quick start guide to start using Selenium with Java. One should keep in mind the best practices to be incorporated while writing Selenium tests.

    Running Test Cases in Selenium IDE

    Running test cases in Selenium IDE is just as simple as setting them up. There are many options for running a test case including:

    • Running a test case: Simply click the “Run” button to begin running the currently displayed test case.
    • Running a test suite: Click the “Run All” button to run all test cases in the test suite currently loaded.
    • Stop and start: Use the “Pause” button to stop a test case currently running.
    • Stop in the middle: This option enables you to set a specific breakpoint that stops a running test at a particular command. Setting a breakpoint is easy; just select a command, right-click, and then choose “Toggle Breakpoint” from the context menu.
    • Start from the middle: Similar to stopping a test at a certain command, you can also set a test to begin running from a specific command. The process for setting this point is the same, but instead of choosing “Toggle Breakpoint,” you’ll select “Set/Clear Start Point” from the context menu.
    • Running a single command: Double-click on any command to run it by itself, a useful tool for testing a command while you’re constructing it.

    With Selenium IDE, you can also use a base URL to run test cases in different domains by specifying a relative URL instead of an absolute URL as the argument to open a test case.

    To define a test suite, a collection of test cases that you want to run as a continuous batch job, you can use a simple HTML file to define your list of tests. Each row in your HTML file should define the file system path to the tests you want to include in the suite.

    Once you’ve mastered the basics of Selenium, you’ll find tons of ways you can put these tools to use to improve your development and testing processes. With many advanced features and functionality, yet being quite simple for beginners to begin using and master, Selenium is a valuable suite of tools for novices and experienced developers alike. The Selenium Wiki on GitHub is a useful source for learning about many advanced capabilities this tool offers. Selenium is a great tool to help with software testing and load testing.

    Course Curriculum

    Enroll in Selenium Training & Certification Course By Selenium Experts

    Weekday / Weekend BatchesSee Batch Details

    About this Course

    Selenium is the most popular web browser automation tool and is an essential skill for both web developers, testers and quality professionals. Selenium automates browsers and if you can use selenium to create powerful scripts to run across systems and environments. You can also create powerful scripts for exploratory testing.

    Our Course in Selenium covers the following

    • Selenium Web Testing Basics Learn to setup the system and learn about the web automation testing fundamentals.
    • Selenium Web Elements – Learn how to use web elements in selenium web driver to quickly create powerful scripts.
    • Selenium Automation Features – Learn all about the automation features required for generating robust test suites.
    • Advance Features – Learn advance techniques and selenium use with Eclipse.
    • TestNG – We also cover TestNg as part of this course. Learn to use this powerful framework in quick and easy steps
    • Log4J and Other frameworks – Learn powerful testing frameworks like Log4J and Jenkins along with Selenium to complete your automation testing knowhow.

    The course covers the latest tools and professional use cases and will be helpful for anyone wants to automate web app testing. Join us and starting creating powerful test scripts for your web projects.

    What is selenium tutorial?

    Selenium is an open-source automation licensed under Apache License 2.0. Selenium is more applicable to test only web applications. This tutorial provides in-depth understanding of Selenium and its related tools with practical usage.

    Audience

    This tutorial is developed for software testing professionals who wish to learn the basics of Selenium. It covers the concepts to work with Selenium to go to the expert level.

    Prerequisites

    To learn this tutorial one must have basic understanding of Java or any other object-oriented programming language. Having knowledge on the fundamentals of testing concepts will be an added advantage.

    Selenium Tutorial: List of Topics

    • Getting Started With Selenium Ide
    • Browser Installation
    • What Is Selenium Ide
    • Time For Action – Installing Selenium Ide
    • Selenium Ide

    Important Note: Rules For Automation

    • Time For Action – Recording Your First Test With Selenium Ide
    • Updating A Test To Assert Items Are On The Page
    • Time For Action – Updating A Test To Verify Items On The Page
    • Comments – Selenium 2 Testing Tools
    • Time For Action – Adding Selenium Ide Comments
    • Multiplying Windows
    • Time For Action – Working With Multiple Windows
    • Time For Action – Complex Working With Multiple Windows
    • Selenium Tests Against Ajax Applications
    • Time For Action – Working On Pages With Ajax
    • Time For Action – Working With Ajax Applications
    • Storing Information From The Page In The Test
    • Time For Action – Storing Elements From The Page
    • Debugging Tests
    • Time For Action – Debugging Tests
    • Test Suites
    • Time For Action – Creating Test Suites
    • Saving Tests
    • What You Cannot Record

    Locators

    Important Points About Relevant Applications

    • Locating Elements By Id
    • Time For Action – Finding Ids Of Elements On The Page With Firebug
    • Time For Action – Finding Elements By Id
    • Moving Elements On The Page
    • Time For Action – Finding Elements By Name
    • Adding Filters To The Name
    • Time For Action – Finding Elements By Link Text
    • Time For Action – Finding Elements By Accessing The Dom Via Javascript
    • Time For Action – Finding Elements By Xpath
    • Time For Action – Finding Elements By Direct Xpath
    • Using Xpath Axis To Find Elements
    • Time For Action – Using Xpath Axis
    • Css Selectors
    • Time For Action – Finding Elements By Css
    • Time For Action – Finding The Nth Element With Css

    Overview Of Selenium Webdriver

    Main Points To Consider

    • History Of Selenium
    • The Webdriver Architecture
    • How To Set Up Your Java Environment
    • Time For Action – Setting Up Intellij Idea Project

    Design Patterns

    Important Points To Remember

    • Page Objects
    • Time For Action – Setting Up The Test
    • Time For Action – Moving Selenium Steps Into Private Methods To Make Tests Maintainable
    • Time For Action – Using The Page Object Pattern To Design Tests
    • Using Page Factories With Page Objects
    • Time For Action – Using Pagefactory
    • Loadablecomponent
    • Time For Action – Changing Our Page Object To Use Loadable Component
    Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    Finding Elements

    • Prior Points To Consider
    • Finding Elements
    • Time For Action – Using Findelementbyid()
    • Time For Action – Using Findelementsbyid()
    • Time For Action – Using Findelementbyname()
    • Time For Action – Using Findelementsbyname()
    • Time For Action – Using Findelementbyclassname()
    • Time For Action – Using Findelementsbyclassname()
    • Time For Action – Using Findelementbyxpath()
    • Time For Action – Using Findelementsbyxpath()
    • Time For Action – Using Findelementbylinktext()
    • Time For Action – Using Findelementsbylinktext()
    • Finding Elements Using A More Generic Method
    • Time For Action – Using Findelement()
    • Time For Action – Using Findelements()
    • Tips And Tricks To Find An Element
    • Time For Action – Using Implicit Waits
    • Time For Action – Using Explicit Waits With Selenium Webdriver


    How Selenium works:

    • Uses JavaScript and Iframes in the browser
    • Core runs the tests and interrogates the DOM
    • RC server and Core communicate via AJAX
    • Language hooks communicate with the RC server.

    Advantages of  SELENIUM

    • Open source, Free software
    • Easy Installation
    • Easy Record and Play back
    • Supports Multiple operating systems
    • Supports Multiple Browser Testing
    • Can convert scripts in to other languages (Java, C#, Python, Pearl etc…)
    • Easy to learn
    • Script once, Run on multiple browsers
    • Testing tool for browser?based testing of web applications. It can be used both for functional, compatibility (it has extensive cross?browser support) and regression testing.

    Disadvantages of SELENIUM

    • The selenium IDE plays back recordings as JavaScript inside the browser. JavaScript inside the browser is subject to the follow restrictions:
    • JavaScript cannot read from or write to files on the client machine,
    • JavaScript cannot close a window if it did not open it,
    • JavaScript cannot access web pages hosted on another domain,
    • Selenium IDE is only available on the Firefox browser.
    • Selenium is the best open source tool for doing automation for web based application and it does not have any cost attached to it. The only cost is the effort which will go for designing and developing the script for the application.There are Huge Openings in selenium because companies are trying to migrate from QTP or commercial tools to Selenium – Open source tool.
    • There are a set of Selenium tools which when combined provides you the power to automate simple to complex web application

    What is the difference between Selenium and QTP

    SeleniumQTP
    Open sourceCommercial
    Works on all OSWorks on Windows only
    Tests only Web applicationsTests web and desktopapplications
    Code can be converted to any one of languages such asJava, C#, Ruby, Python, pearl, php etc.Uses VB script
    No object repositoryHas got an object repository
    IDE sometimes does not record some fieldsRecording is a little reliableevents
    Name Date Details

    14-Oct-2024

    (Mon-Fri) Weekdays Regular

    16-Oct-2024

    (Mon-Fri) Weekdays Regular

    12-Oct-2024

    (Sat,Sun) Weekend Regular

    12-Oct-2024

    (Sat,Sun) Weekend Fasttrack