0% found this document useful (0 votes)
37 views

Software Testing - Selenium

The document provides an overview of Selenium, including what it is, its main components like WebDriver and IDE, and how to perform basic tasks like installing it and writing automated tests using WebDriver. Selenium is an open-source tool that is used to automate testing of web applications across different browsers. It discusses the Selenium suite and provides details on how to use IDE and WebDriver for recording and writing automated tests.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Software Testing - Selenium

The document provides an overview of Selenium, including what it is, its main components like WebDriver and IDE, and how to perform basic tasks like installing it and writing automated tests using WebDriver. Selenium is an open-source tool that is used to automate testing of web applications across different browsers. It discusses the Selenium suite and provides details on how to use IDE and WebDriver for recording and writing automated tests.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

SELENIUM

09.04.2024

Vijayashri Harini R S - 20Z258


Glory C J - 21Z433
1

Overview
Selenium is an open-source, automated testing tool used to test web applications
across various browsers. Selenium can test web applications against various browsers
like Firefox, Chrome, Opera, and Safari, and these tests can be coded in several
programming languages like Java, Python, Perl, PHP, and Ruby.
Selenium is not just one tool or API; it comprises many tools: Webdriver, IDE, Grid.
● WebDriver uses browser automation APIs provided by browser vendors to control
the browser and run tests. This is as if a real user is operating the browser. Since
WebDriver does not require its API to be compiled with application code, it is not
intrusive.
● IDE (Integrated Development Environment) is the tool you use to develop your
Selenium test cases. It’s an easy-to-use Chrome and Firefox extension and is
generally the most efficient way to develop test cases. This is not only a
time-saver but also an excellent way of learning Selenium script syntax.
● Selenium Grid allows you to run test cases in different machines across different
platforms. After the development of the WebDriver tests, you may face the need
to run your tests on multiple browsers and operating system combinations. This
is where Grid comes into the picture.

Selenium removes the need for manual testing by automating regression tests.
This saves testers several days of effort that goes into manually testing every
functionality of the software whenever a change is made to the source code. It is one of
the few testing tools that support a wide range of browsers. It can support all the recent
versions of Google Chrome, Internet Explorer, Opera, Safari, and Mozilla Firefox.

However, Selenium has a few shortcomings, which includes the following.

● Selenium is open-source so it doesn’t have a developer community and hence


doesn’t have reliable tech support.
● Selenium cannot test mobile or desktop applications
● Selenium offers limited support for image testing
2

Selenium Suite
Selenium has a dedicated suite that facilitates easy testing of web applications,
comprising the following tools.
● Selenium IDE
● Selenium WebDriver
● Selenium Grid

Selenium IDE
Selenium IDE is part of the Selenium suite and was developed to speed up the
creation of automation scripts. It’s a rapid prototyping tool and can be used by
engineers with no programming knowledge whatsoever. IDE is an easy-to-use interface
that records user interactions on the browser and exports them as a reusable script.

I. Installation
Step 1: Open the Chrome browser.
Step 2: Click on the menu in the top right corner.
Step 3: Click on Extensions in the drop-down menu.
Step 4: Click on Visit Chrome Web Store and type Selenium IDE.
Step 5: Click on Add to Chrome.
3

Once installed, the Selenium IDE icon appears on the top right corner of the
browser. When clicked, a Welcome message appears.

II. Testing using IDE


IDE works in three stages: recording, playing back and saving.
Recording
IDE allows the user to record all of the actions performed in the browser.
These recorded actions as a whole are the test script.
Step 1: Launch Chrome menu and open the Selenium IDE plugin.
Step 2: Select “Record a test in a new project.” Provide the name for your test.
Step 3: Provide the base link of the website to be tested and click the Record
button.
4

Step 4: The IDE launches the website. Then Sign in to your account and use the
functionality that has to be tested in the website.
Step 5: The Assert command can be used to verify the title or other functionality
of the website.
Step 6: Go back to the IDE window and stop recording.

Playing back
The recorded script can now be executed to ensure that the browser is
working accordingly. Now, the user can monitor the stability and success rate.
5

The commands successfully executed are color-coded in green, and the


log at the bottom indicates any errors that occurred during the execution. If the
script runs successfully, it indicates this by displaying a message.
Saving
Once the test script is successfully executed, you can then save or export
it. The recorded script is saved with a “.side” extension for future runs and
regressions.

You can export a test to WebDriver code by right-clicking on a test or a suite,


selecting Export, choosing your target language, and clicking Export.
6

Selenium WebDriver
Selenium WebDriver was the first cross-platform testing framework that
could configure and control the browsers on the OS level. It served as a
programming interface to create and run test cases. WebDriver performs actions
on web elements. It supports various programming languages like Java, C#, PHP,
Python, among others. It can also be integrated with frameworks like TestNG and
JUnit for test management.

I. Installation
Step 1: Download and install Python3. Once the download is completed,
the Python executable file gets saved in our system. Click on this file, and
the Python installation landing page gets opened. Then, click on Install
Now.
Step 2: Download Pycharm (community edition). Once the download is
complete, click on the executable file. This will open the installation page.
Then, configure according to the system needs and let the installation
finish.
Step 3: Use pip to install the selenium package. Python 3 has pip available
in the standard library. Using pip, you can install selenium using the
following command
pip install selenium
Step 4: Selenium requires a driver to interface with the chosen browser. All
supported browsers will have their own drivers available. For Chrome, the
browser driver can be installed by following the below URL.

https://sites.google.com/chromium.org/driver/
Step 5: Create a new Python package within a new Python project in
Pycharm. Create a new file within the package and start writing your
script.
7

II. Testing using WebDriver

Testcase: Login Automation


Before performing automation testing for the login functionality,
there are a couple of basic steps that need to be followed for the test case
to be written:
● Create a Selenium WebDriver instance
● Configure browser if required
● Navigate to the required webpage
● Locate the relevant web element
● Perform action on the web element
● Verify and validate the action

1. Create a Selenium WebDriver instance: To launch the website in the


desired browser, set the system properties to the path of the driver for the
required browser. This example will use ChromeDriver for Login
Automation using Selenium Webdriver. The syntax for the same will be

Webdriver driver = new ChromeDriver();


System.setProperty("webdriver.chrome.driver", "Path of the chrome
driver");

2. Configure browser if required: Usually, the web page will be in a


minimized format when the test case is run. Maximize the browser for a
clear picture of the test cases executed. Use the command below to do
the same:

driver.get("https://www.browserstack.com/users/sign_in");
8

3. Navigate to the required webpage: Open the browser with the desired
URL. Use the command below to open the URL in the desired instantiated
browser:

driver.get("https://www.browserstack.com/users/sign_in");

4. Locate the relevant web element: For example, let’s try to locate the email
and password field of the login form of Browserstack sign in page.Inspect
the email field to locate the element using the ID locator, as shown in the
image below:
9

Locate it via the ID locator in Selenium WebDriver. Since this returns a


webelement, store it in webelement variable:
WebElement username=driver.findElement(By.id("user_email_login"));

5. Perform action on the web element: After locating the element, testers
need to perform the desired action. In this case, the action is entering text
in the email and password fields and hitting the login button. For this, the
script uses sendKeys and click methods, as shown below:

username.sendKeys("abc@gmail.com");

password.sendKeys("your_password");

login.click();

6. Verify and validate the action: To validate the results, use assertion.
Assertions are important for comparing the expected results to the actual
results. If it matches, the test case passes. If not, then the test case fails.
The syntax below will help to assert the outcome from actions by
performing login automation:

Assert.assertEquals(actualUrl, expectedUrl);

After the test script is complete, it is run from PyCharm to automate the
browser.

Similarly, the login functionality is tested in bstackdemo website which


contains dummy usernames and a single password for all the dummy
usernames. Now, after successful login, the test is asserted with the
display of the logout button.
10

Selenium code for login automation

Home page of bstackdemo


11

After entering username and password

After logging in
12

Selenium Grid
Selenium Grid allows to run test cases in different machines across
different platforms. The control of triggering the test cases is on the local
machine, and when the test cases are triggered, they are automatically executed
by the remote machine. It supports distributed test execution. Test cases can be
made to run in parallel in multiple machines on Selenium Grid.

I. Installation
Step 1: Download and install the Java SDK from the official website.
Step 2: Install all the necessary browsers and browser drivers.
Step 3: Download Eclipse IDE to run WebDriver scripts.
Step 4: Download the Selenium Standalone Server from the official
website to run Remote Selenium webdriver.

Step 5: Open Command prompt and type the following command to start
the Selenium server.
java -jar selenium-server-4.19.1.jar standalone
13

Step 6: Create a new project in Eclipse IDE. Then create a new package
and a new class, within which we will write WebDriver scripts. Also add the
downloaded Selenium server jar file while configuring Build Path.

II. Testing

● After starting the selenium server, a local host URL will be created. By
default it is, http://localhost:4444.
● Copy the URL and paste it in your browser to see the sessions that are
running and how many instances of the browser have been created.
14

● Write a WebDriver script that can be used to test to parallely on the


different instances.

● Here, the script contains the validation of a web page’s title.


● From Eclipse, the script is made to run as a Java application. This allows
the browser to automatically open the webpage and display its title.
15

● Now, you can view the current sessions that are running in the browser, its
start time, the duration and also the node URL.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy