Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

Selenium Introduction

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.
• Selenium supports various operating systems, browsers and programming languages.
Following is the list:
• Programming Languages: C#, Java, Python, PHP, Ruby, Perl, and JavaScript
• Operating Systems: Android, iOS, Windows, Linux, Mac, Solaris.
• Browsers: Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari, etc.
• It also supports parallel test execution which reduces time and increases the efficiency
of tests.
Selenium components
Selenium is not just a single tool but a suite of software, each with a different approach to
support automation testing. It comprises of four major components which include:
• Selenium Integrated Development Environment (IDE)
• Selenium Remote Control
• WebDriver
• Selenium Grid
Selenium Integrated Development Environment
Selenium Integrated Development Environment (IDE) is the simplest in the Selenium suite and is the
easiest one to learn. You can install it easily as you can do with other plugins.
Selenium IDE is implemented as Firefox extension which provides record and playback functionality
on test scripts.
It allows testers to export recorded scripts in many languages.
The following are the different browsers supported by the latest version of Selenium IDE (Which got
released by Selenium into the market in August 2018)
• Chrome Browser
• Firefox Browser
Selenium Remote Control (Selenium RC)
Selenium RC is the first automated web testing tool that allowed users to use a
programming language they prefer. RC can support the following programming languages:
Java, C#, PHP, Python, Perl, Ruby.
Selenium RC’s architecture has proven to be complicated for the following reasons:
• One needs to install and launch a separate application called Selenium Remote Control
Server before running test scripts
• The RC server acts as a mediator between the browser and Selenium commands
Selenium WebDriver
Selenium WebDriver is by far the most important component of Selenium Suite.
Selenium WebDriver provides a programming interface to create and execute test cases.
Test scripts are written in order to identify web elements on web pages and then desired
actions are performed on those elements.
Selenium WebDriver performs much faster as compared to Selenium RC because it makes
direct calls to the web browsers.
WebDriver directly calls the methods of different browsers hence we have separate driver
for each browser. Some of the most widely used web drivers include: (Mozilla Firefox
driver – Gecko driver, Google Chrome Driver, Internet Explorer Driver, Opera Driver,
Safari Driver)
Selenium Grid
Selenium Grid is also an important component of Selenium Suite which allows us to run
our tests on different machines against different browsers in parallel.
In simple words, we can run our tests simultaneously on different machines running
different browsers and operating systems.
Selenium Integrated Development
Environment (IDE)
Selenium IDE
• Selenium IDE (Integrated Development Environment) is an open source web
automation testing tool under the Selenium Suite.
• Unlike Selenium WebDriver and RC, it does not require any programming logic to
write its test scripts rather you can simply record your interactions with the browser to
create test cases.
• Subsequently, you can use the playback option to re-run the test cases.
Selenium IDE Download and Install
• Launch Chrome browser.
• Write Selenium IDE extension.
• Click Add to Chrome.
• Go to the top right corner on your browser and look for the Selenium IDE icon.
Selenium IDE-Features
Selenium IDE is divided into different components, each having their own features and
functionalities. We have categorized seven different components of Selenium IDE, which includes:
• Menu Bar
• Tool Bar
• Address Bar
• Test Case Pane
• Test Script Editor Box
• Start/Stop Recording Button
• Log, Reference Pane
Selenium IDE-Features
Selenium IDE- Login Test
• Launch browser.
• Click on the Selenium icon present on the top right corner on your browser.
• It will launch the default interface of Selenium IDE.
• Go to your browser and open URL: https://www.testandquiz.com/
• Enter the project name as Login Test.
• Enter the test case name as Test Case 1.
• Click on the Start Recording button to start the recording of the test case.
• Go to your browser and right click on any blank space within the page and select the
Selenium IDE option.
Selenium IDE- Login Test
• Click on Selenium IDE > Assert Title. The Assert Title command makes sure that the
page title is correct.
• Now click on Login button.
• Enter wrong username and password. Click Login.
• Warning message will appear, right click on warning message click on Selenium IDE
and choose Verify Text.
• Go back to Selenium IDE and stop recording.
Playing Back
Click on the Run Current Test button present on the tool bar menu of the IDE. It will
execute all of your interactions with the browser and gives you an overall summary of the
executed test script.
The Log pane displays the overall summary of the executed test scripts.
Saving the test suite
Click on the save button present on the extreme right corner of the menu bar.
Save your test with name Login Test.
Selenium IDE- Commands
Selenium commands are set of commands used in Selenium IDE that run your tests. Using them, one
can perform activities like:
• Testing the existence of UI elements based on their HTML tags.
• Test for specific content.
• Test for broken links.
• Testing input fields, selection list options, submitting forms and table data among other things.
• Testing of window size, mouse options, pop-up windows, event handling and many other web
application features.
A sequence of Selenium commands together is known as test script.
Types of Selenium Commands
Selenium commands are basically classified in three categories:
• Actions - These are commands that directly interact with page elements.
• Accessors - They are commands that allow you to store values to a variable.
• Assertions - They are commands that verify if a certain condition is met.
Types of Selenium Commands
There are three types of Assertions
• Assert. When an "assert" command fails, the test is stopped immediately.
• Verify. When a "verify" command fails, Selenium IDE logs this failure and continues with the test
execution.
• WaitFor. Before proceeding to the next command, "waitFor" commands will first wait for a certain
condition to become true.
• If the condition becomes true within the waiting period, the step passes.
• If the condition does not become true, the step fails. Failure is logged, and test execution
proceeds to the next command.
• By default, the timeout value is set to 30 seconds. You can change this in the Selenium IDE
Options dialog under the General tab.
Common Commands
open (url) - Opens a page using a URL.
click(locator)- Clicks on a specified element.
doubleClick (locator) - This command enables double clicks on a web element
type(locator, value) - It sets the value of an input field, similar to user typing action.
verifyTitle/assertTitle - Compares the actual page title with an expected value.
verifyTextPresent - Checks if a certain text is found within the page.
verifyElementPresent - Checks the presence of a certain element.
waitForPageToLoad - Pauses execution until the page is loaded completely
waitForElementPresent - Pauses execution until the specified element becomes present.
Selenium IDE- Locating Strategies
In Selenium IDE, a target works on specifying location of a particular web element which
are:
• Id
• Name
• CSS selector (tag and Id; tag and class; tag and attribute; tag, class and attribute)
• XPath
• DOM(Document Object Model)
Selenium IDE- Locating by Id
This is the most common way of locating elements since ID's are supposed to be unique
for each element.
id=id of the element
https://www.rediff.com/
Locator for Username filed: id=“login1”
Locator for Password field id="password“
Selenium IDE- Locating by Name
Locating elements by name are very similar to locating by ID, except that we use
the "name=" prefix instead
name=name of the element
https://mail.rediff.com/cgi-bin/login.cgi
Locator for Go button: name="proceed“
Locator for Password: name="passwd“
Locator for Username: name="login"
Selenium IDE- Locating by CSS
CSS Selectors have many formats, but we will only focus on the most common ones.
• Tag and ID
• Tag and class
• Tag and attribute
• Tag, class, and attribute
Locating by CSS Selector - Tag and ID
Syntax:
css=tag#id
• tag - the HTML tag of the element being accessed
• # - the hash sign. This should always be present when using a CSS Selector with ID
• id - the ID of the element being accessed
https://mail.rediff.com/cgi-bin/login.cgi
css=input#login1
css=input#password
Locating by CSS Selector - Tag and Class
Syntax:
css=tag.class
• tag - the HTML tag of the element being accessed
• . the dot sign. This should always be present when using a CSS Selector with class
• class - the class of the element being accessed
https://www.testandquiz.com/user-login
Locator for username: css=input.form-control
Locator for password: css=input.form-control
(input#password.form-control)
Locating by CSS Selector - Tag and Attribute
Syntax:
css=tag[attribute=value]
• tag - the HTML tag of the element being accessed
• [ and ] - square brackets within which a specific attribute and its corresponding value
will be placed
• attribute - the attribute to be used. It is advisable to use an attribute that is unique to the
element such as a name or ID.
• value - the corresponding value of the chosen attribute.
Locating by CSS Selector - Tag and Attribute
https://www.testandquiz.com/user-login
Locator for username: css=input[name="email_id"]
Locator for password: css=input[name="password"]
Locating by CSS Selector - tag, class, and attribute
Syntax:
css=tag.class[attribute=value]
css=tag#id[attribute=value]
• tag - the HTML tag of the element being accessed
• . the dot sign. This should always be present when using a CSS Selector with class
• class - the class of the element being accessed
• [ and ] - square brackets within which a specific attribute and its corresponding value will be placed
• attribute - the attribute to be used. It is advisable to use an attribute that is unique to the element such as a name
or ID.
• value - the corresponding value of the chosen attribute.
Locating by CSS Selector - tag, class, and attribute
https://www.testandquiz.com/user-login
Locator for username: css=input.form-control[placeholder="Email"]
Locator for password: css=input.form-control[name="password"]
Locator for Login button: css=button.btn.btn.btn-primary[type="submit"]
Locating by XPath
• Advantage: It can access almost any element, even those without class, name, or id attributes.
• Disadvantage: It is the most complicated method of identifying elements because of too many
different rules and considerations.
https://mail.rediff.com/cgi-bin/login.cgi
Right click on element you want to inspect, choose Copy XPath.
In Selenium IDE, type one forward slash "/" in the Target box then paste the XPath that we copied
in the previous step. The entry in your Target box should now begin with two forward slashes
"//".
Click on the Find button. Selenium IDE should be able to highlight the orange box as shown below.
Selenium IDE- Creating Test Cases Manually
We will create our first test case on search operation. We will search our text on Google
search engine.
Selenium IDE- Log in test
We will generate a test case based on login feature.
https://www.rediff.com/

http://demo.guru99.com/test/newtours
(username, password)

You might also like