0% found this document useful (0 votes)
26 views22 pages

Test Automation Using Selenium - Report

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
26 views22 pages

Test Automation Using Selenium - Report

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 22

TEST AUTOMATION USING SELENIUM

ABSTRACT

Automation Testing is a software testing technique that performs using special


automated testing software tools to execute a test case suite. On the contrary, Manual
Testing is performed by a human sitting in front of a computer carefully executing the
test steps. The automation testing software can also enter test data into the System
Under Test, compare expected and actual results and generate detailed test reports.
Software Test Automation demands considerable investments of money and
resources. Successive development cycles will require execution of same test suite
repeatedly. Using a test automation tool, it’s possible to record this test suite and re-
play it as required. Once the test suite is automated, no human intervention is
required. This improved ROI of Test Automation. The goal of Automation is to
reduce the number of test cases to be run manually and not to eliminate Manual
Testing altogether. Selenium is a tool for automating testing across many web
browsers. Selenium WebDriver supports a variety of browsers, including Google
Chrome, Mozilla Firefox, Safari, and Internet Explorer, and allows you to simply
automate browser testing across different browsers. We learn various testing types
involved in testing, bug life cycle, advantages in test automation and test automation
using selenium.

INTRODUCTION

Software testing is a method of determining whether the actual software product


meets the expected requirements and ensuring that the software product is free of
defects. It entails running software/system components through their paces using
manual or automated tools to evaluate one or more properties of interest.

The goal of software testing is to find errors, gaps, or missing requirements in


comparison to the actual requirements. When a software development project is going
on, you need to know that errors may appear in any phase of the life cycle.

There are high chances that the final code has errors of functionality and design. For
the identification of the issues before the occurrence in the critical environment, it is a
prerequisite to performing the testing of software.

PRAKASAM ENGINEERING COLLEGE Page 1


Software testing is important because if there are any bugs or errors in the software,
they can be identified early and fixed before the software product is delivered. A
properly tested software product ensures dependability, security, and high
performance, which leads to time savings, cost effectiveness, and customer
satisfaction.

Testing is a vast landscape that consists of several categories like black-box testing,
white box testing, system testing, system integration testing, performance testing, and
load testing. Some of these testing categories perform better with Automation, while
others get desirable results with Manual Testing. Automation testing has been a
buzzword in the world of testing. It has helped companies take new features to market
faster while ensuring a bug-free user experience. It has improved the productivity of
developers and QA testers, while ensuring a massive increase in test coverage, to keep
up with the proliferation of different devices, browsers, and operating systems.
However, manual testing has retained its own special place. We understand software
life cycle, various test types, bug life cycle and test automation using selenium in
following sections.

SOFTWARE DEVELOPMENT LIFE CYCLE (SDLC)

There are six phases in software development life cycle,

1. Initial (or) Requirement phase:

Tasks: Interacting with customer and gathering the requirements.

Roles: Business analyst –BA, Engagement manager – EM

Process:

 First of all business analyst will take an appointment from the customer,
collect the template from the company and meet the customer on appointed
date, gather the requirements with the support of that template and comes back
to the company with the requirement document.
 The engagement manager go through the requirements, if he find any extra
requirements then he will deal with excess cost of the project.
 If at all he finds any confused requirements, then he will ask the concern team
to build a prototype, demonstrate that prototype to the customer, gather’s the

PRAKASAM ENGINEERING COLLEGE Page 2


clear requirements and finally hand over the required documents to the BA
Proof: The proof document of Initial phase is Requirement’s Document (RD).

2. ANALYSIS PHASE:

Tasks:

 Feasibility study
 Tentative planning
 Technology selection and Environment confirmation
 Requirement analysis

Roles: System Analyst – SA, Project Manager – PM, Technical Manager – TM

Process:

a. Feasibility study: It is detailed study conducted on the requirement documents, in


order to confirm whether the given requirements are possible within the given budget,
time and available resources or not.

b. Tentative planning: In this section resource planning and time planning will be
temporarily done. c. Technology selection & Environment confirmation: The list of
all technologies required for accomplishing the project successfully will be analyzed,
the environment suitable for that project will be selected and mentioned here in this
section.

d. Requirement analysis: The list of all the requirements that are required by the
company to accomplish this project successfully will be analyzed and listed out
clearly in this section.

3. DESIGN PHASE:

Tasks:

 High level designing


 Low level designing

Roles:

 High level design is done by chief Architect(CA)

PRAKASAM ENGINEERING COLLEGE Page 3


 Low level design is done by Technical Lead(TL)

Process:

 The chief architect will divide the whole project in to modules by drawing some
diagrams using unified modeling language (UML).
 The Team lead will divide the modules into sub modules by drawing some
diagrams using the same UML.
 In this phase they will also design GUI part of the application, as well as
PSEUDO CODE also developed

4. CODING PHASE (WHITE BOX TESTING):

Tasks:

Programming (or) Coding

Roles: Programmers (or) Developers

Process: The developers will develop the actual source code by following the coding
standards and also with the support of Technical Design Document

5. TESTING PHASE (BLACK BOX TESTING):

Tasks: Testing

Roles: Test Engineer’s.

Process:

 The Testing department will receive the requirement document and the test
engineers will start understanding the requirements.
 While understanding the requirements, if they get any doubts they will list out all
the doubts in Requirement clarification Note and sent it to the author of the
requirement document and wait for the clarification.
 Once the clarification is given and after understanding all the requirements clearly
they will take the test case template and write the Test cases.
 Once the first build is released they will execute the test cases.
 If at all any defects are found they will list out all the defects in the defects profile
and send it to the development department and will wait for the next build.
PRAKASAM ENGINEERING COLLEGE Page 4
 Once the next build is released they will re execute the required test cases.
 If at all any more defects are found they will update the defect profile. Send it to
development department and will wait for the next build.
 This Process continuous till the product is defect free

6. DELIVERY AND MAINTENANCE PHASE:

Delivery:

Tasks: Hand over the Application to the client

Roles: Deployment engineers (or) Installation engineers.

Process: The Deployment engineers will go to the customers place, install the
application in to the customers environment and handover the original software to the
client.

Proof: The final official agreement made between the customer and company is proof
document for Delivery.

Maintenance: Once the application is delivered. The customer will start using it,
while using if at all they face any problems then that particular problem will be
created as tasks. Based on the tasks corresponding roles will be appointed. They will
define the process and solves the problem .This process is known as Normal
Maintenance. But some customers may request for continuous Maintenance, in that
case a team of members will be continuously working in the client site in order to take
care of their Software.

TYPE OF SOFTWARE TESTING

Software Testing is Important because if there are any bugs or errors in the
software, it can be identified early and can be solved before delivery of the software
product. Properly tested software product ensures reliability, security and high
performance which further results in time saving, cost effectiveness and customer
satisfaction. Below are the types of software testing,

1. UNIT LEVEL TESTING:


Unit: Unit is a smallest part of an application (Program).

PRAKASAM ENGINEERING COLLEGE Page 5


In this stage the white box testers will test each and every program and combinations
of programs in order to confirm whether they are working according to the
expectations or not. They test the structural part of a module.

2. MODULE LEVEL TESTING:


Module: Module is defined as a group of related features to perform a major task in
an application.
In this stage the Black Box test engineer’s will test the functional part of a module

3. INTEGRATION LEVEL TESTING: In this stage the developers will develop


interfaces (Linking Prg’s), in order to integrate the modules. The White Box testers
will test whether the interfaces are working fine or not.

4. SYSTEM LEVEL TESTING: In this level the Black Box test engineers will
conduct so many types of testing like load testing, performance testing, stress testing,
compatibility testing, system integration testing etc. These type of Testings are also
conducted:
These type of Testings are also conducted:
1. Usability Testing
2. Functionality Testing
3. Performance Testing
4. Security Testing

IMPORTANT TERMINOLOGY IN TESTING


Project: Project is something that is developed based on particular customer’s
requirements and for their usage only.

Product: Product is something that is developed based on the company specifications


and used by multiple customers. Note: The product based company will first have
general survey in the market. Gather’s clear requirements from different customers,
and based on common requirements of so many customer`s. They will decide the
specifications (Requirements).

Quality: Classical Definition of Quality: Quality is defined as justification of all the


requirements of a customer in a product. Quality is defined as not only the

PRAKASAM ENGINEERING COLLEGE Page 6


justification of all the requirements but also the presence of the value (User
friendliness).

Defect: Defect is defined as a deviation from the Requirements

Testing: Testing is a process in which defects are identified, isolated, subjected for
rectification and ensure that the product is defect free, in order to produce the quality
product and hence the customer satisfaction. (or) Verification & Validation of
software is called Testing.

SOFTWARE TESTING LIFE CYCLE (STLC)


STLC contains 6 phases:
1. Test Planning.
2. Test Development.
3. Test Execution.
4. Result Analysis.
5. Bug Tracking.
6. Report
Test planning:
Plan is strategic document which describes how to perform a task in an effective,
efficient and optimized way. Test plan: Test plan is strategic document, which
contains some information that describes how to perform testing on an application in
an effective, efficient and optimized way. Optimization: It is process of utilizing the
available resources to their level best and getting maximum possible output.

2. Test Development
THE GUIDE LINES TO BE FOLLOWED BY A TEST ENGINEER, SOON AFTER
THE USE CASE DOCUMENT IS RECEIVED:
1. Identify the module to which the use case belongs to.
A: Security module.
2. Identify the functionality of the use case with the request of total functionality. A:
Authentication.
3. Identify the actors involved in the use case. E.g.: Normal user/Admin user.
4. Identify the inputs required for testing. E.g.: Valid and invalid user names and
passwords.

PRAKASAM ENGINEERING COLLEGE Page 7


5. Identify whether the use case is linked with other use case or not. E.g.: It is linked
with Home page and Admin page use cases.
6. Identify the pre conditions. E.g.: LOGIN Screen must be available.
7. Identify the post conditions. E.g.: Either Home page/Admin page for valid users,
and error messages for invalid users.
8. Identify the functional points and prepare the functional point document.
UNDERSTAND: 9. Understand the main flow of the application.
10. Understand the alternative flow of the application.
11. Understand the special requirements. DOCUMENT:
12. Document the test cases for main flow.
13.Document the test cases for alternative flow.
14. Document the test cases for the special requirements.
15. Prepare the cross reference metrics or traceability metrics.

FUNCTIONALITY TESTING: It is a type of testing in which one will perform


testing the functionality of an application, functionality means behaviour of the
application. Guidelines for writing the GUI Test Cases:
1. Check for the availability of all the objects.
2. Check for the consistency of the objects.
3. Check for the alignment of the objects, in case of customer requirement only.
4. Check for the spellings and grammar.
from the above guidelines any idea we get with which we can test something in the
application, just by look and feel without doing any actions, and then all those ideas
also can be considered as GUI Test Cases.
Guidelines for writing the Positive Test Cases:
1. A Test engineer should have positive mind set.
2. He should consider the positive flow of the application.
3. He should use only valid inputs from the point of the functionality.

Guidelines for writing the Negative Test Cases:


1. A Test engineer should have negative mind set.
2. He should consider the negative flow of the application.
3. He should use at least one invalid input for each set of data.
Guidelines for writing Test Cases:
1. Feel like Boss.

PRAKASAM ENGINEERING COLLEGE Page 8


2. Action should be possible and expected value should be related to the actions based
on the requirements.
3. Test Case should be clear and understandable.
4. It should be Simple, Easy and Powerful.
3. Test Execution: In this phase the test engineer will do the following:
1. They will perform the action as it is described in the Description column.
2. They will observe the actual behavior of the Application.
3. They will write the observed value in the Actual value column.

4. Result Analysis: In this phase the test engineer will compare the actual value with
the expected value. If both are matching, then he will decide the result as PASS
otherwise FAIL. Note: If at all the Test case is not executed in any reason, then the
test engineer will specify BLOCKED in the result column.
Ex: If application has 5 pages, in each page a next button will be available, when we
click on next button, we will enter into next page, if next page button of 4th page is
not working, we can’t enter into 5th page and all the test cases related to that 5th page
can’t test. The result to all that test cases will be BLOCKED.

5. Bug Tracking: It is a process of identifying, isolating and managing the defects.


DEFECT ID: The sequence of defect no’s will be mentioned here in this section.
TEST CASE ID: The test case id based on which defect is found will be mentioned
here in this section.
ISSUE DISCRIPTION: What exactly the defect is will be clearly described here in
this section. REPRODUCABLE DEFECTS: The list of all the steps followed by the
test engineer, to identify the defects will be listed out here in this section
Test Case Design

PRAKASAM ENGINEERING COLLEGE Page 9


Bug Life Cycle

AUTOMATION TESTING
Automation Testing is a software testing technique that performs using special
automated testing software tools to execute a test case suite. On the contrary, Manual
Testing is performed by a human sitting in front of a computer carefully executing the
test steps.
Following steps are followed in an Automation Process
1) Test Tool Selection
2) Define scope of Automation
3) Planning, Design and Development
4) Test Execution
5) Maintenance

Manual vs Automation

Parameter Automation Testing Manual Testing


Definition Automation Testing uses automation In manual testing, test cases are

PRAKASAM ENGINEERING COLLEGE Page 10


Parameter Automation Testing Manual Testing
tools to execute test cases. executed by a human tester and
software.
Processing Automated testing is significantly Manual testing is time-consuming
time faster than a manual approach. and takes up human resources.
Exploratory Automation does not allow random Exploratory testing is possible in
Testing testing Manual Testing
The initial investment in the
The initial investment in the Manual testing is comparatively
Initial
automated testing is higher. Though lower. ROI is lower compared to
investment
the ROI is better in the long run. Automation testing in the long
run.
Automated testing is a reliable
Manual testing is not as accurate
method, as it is performed by tools
Reliability because of the possibility of the
and scripts. There is no testing
human errors.
Fatigue.
For even a trivial change in the UI of Small changes like change in id,
the AUT, Automated Test Scripts class, etc. of a button wouldn’t
UI Change
need to be modified to work as thwart execution of a manual
expected tester.
Investment is required for testing Investment is needed for human
Investment
tools as well as automation engineers resources.
Cost- Not cost effective for low volume Not cost effective for high volume
effective regression regression.
With automation testing, all Manual Tests are usually recorded
Test Report stakeholders can login into the in an Excel or Word, and test
Visibility automation system and check test results are not readily/ readily
execution results available.
Automated testing does not involve The manual testing method allows
Human human consideration. So it can never human observation, which may be
observation give assurance of user-friendliness useful to offer user-friendly
and positive customer experience. system.
Performance Performance Tests like Load Performance Testing is not
Testing Testing, Stress Testing, Spike feasible manually

PRAKASAM ENGINEERING COLLEGE Page 11


Parameter Automation Testing Manual Testing
Testing, etc. have to be tested by an
automation tool compulsorily.
This testing can be executed on Manual tests can be executed in
Parallel different operating platforms in parallel but would need to increase
Execution parallel and reduce test execution your human resource which is
time. expensive

Automated Testing Tools Available in Market


 Selenium
 Appium
 Katalon Studio
 Cucumber
 HPE Unified Functional Testing (UFT)
 SoapUI
 TestComplete
 Rest Assured

 IBM Rational Functional Tester (RFT)

INTRODUCTION TO SELENIUM
Selenium is a free (open-source) automated testing framework used to validate web
applications across different browsers and platforms.
You can use multiple programming languages like Java, C#, Python, etc to create
Selenium Test Scripts. Testing done using the Selenium testing tool is usually referred
to as Selenium Testing.

Selenium Tool Suite:

Selenium Software is not just a single tool but a suite of software, each piece catering
to different Selenium QA testing needs of an organization. Here is the list of tools
 Selenium Integrated Development Environment (IDE)
 Selenium Remote Control (RC)
 WebDriver
 Selenium Grid

PRAKASAM ENGINEERING COLLEGE Page 12


History of Selenium:
Since Selenium is a collection of different tools, it also had different developers.
Below are the key persons who made notable contributions to the Selenium Project
 Selenium was created by Jason Huggins in 2004 and named
JavaScriptTestRunner
 Paul Hammantis who made Selenium RC
 Selenium Grid was developed by Patrick Lightbody
 Shinya Kasataniof Japan created Selenium IDE
 Simon Stewart created WebDriver circa 2006

WebDriver:

The WebDriver proves to be better than Selenium IDE and Selenium RC in many
aspects. It implements a more modern and stable approach in automating the
browser’s actions. WebDriver, unlike Selenium RC, does not rely on JavaScript for
Selenium Automation Testing. It controls the browser by directly communicating
with it.
The supported languages are the same as those in Selenium RC.
 Java
 C#
 PHP

PRAKASAM ENGINEERING COLLEGE Page 13


 Python
 Perl
 Ruby

Selenium Architecture

Selenium installation is a 3 step process:

PRAKASAM ENGINEERING COLLEGE Page 14


1. Install Java SDK
2. Install Eclipse
3. Install Selenium Webdriver Files
Reference: https://www.guru99.com/installing-selenium-webdriver.html
Selenium WebDriver commands can be categorized as follows:

1. Commands for the Browser


2. Commands for Navigation
3. Commands for Web Element
4. Action Commands
5. Result Commands

1. Commands for Browser:


Browser commands are those that can be used to execute operations on the browser
itself, such as opening a browser, shutting down a browser, retrieving page source,
and so on.

 get() : This command opens a new browser instance and navigates to the URL

 getTitle() : This command retrieves the title of the webpage on which the user
is currently working.

 getCurrentUrl():This command retrieves the URL of the webpage that the user
is presently viewing.

 close():This function closes the WebDriver-controlled browser window that is


currently open.

 Quit(): End all open browser Instances, whereas the Close() method closes
current browser instance

2. Commands for Navigation:


Navigation commands can be used by testers to move throughout the website. For
example, open a web page URL, go to another web page by clicking any element, and
use the browser's history to Back, Forward, or Refresh the web page.

 to(): This method is used to load a new web page in the existing browser
window.
PRAKASAM ENGINEERING COLLEGE Page 15
 navigate() : This method opens a new browser window with a new web page.
It accepts a String parameter as well as a void return type.

 back() and forward() : To navigate back and forth on a Selenium WebDriver


open window, utilise the forward() and backward() functions. The behaviour
of these techniques is identical to that of a web browser's back and forward
buttons.

 findElement() :For Selenium WebDriver, any object on the website, such as a


button, textbox, Listbox, radio buttons, headings, web tables, and so on, is a
WebElement. In a nutshell, a WebElement is any HTML element. Before we
can take any action on a WebElement, we must first obtain that WebElement.
To acquire the required WebElement, utilize the findElement method.
 refresh() : The current web page in the current browser window is refreshed or
reloaded using this approach. It doesn't take anything and doesn't give it back.

3. Commands for Web Element:


WebElement is an HTML element that allows users to run automation tests with ease.
Selenium Webdriver uses WebElements to enable well-organized web page
interactions, such as identifying elements, getting attribute properties, asserting text in
WebElement, and more. To interact with hidden elements in a web page, however,
you must first unhide the hidden elements and then locate the element in the web
page.

 element.clear():if the element is a text entry, its value will get cleared,
and nothing is passed as a parameter to this procedure.

 element.sendKeys():It allows the user to automatically type input into an


editable field while running tests. These are web elements that can be
recognized by locators such as element id, name, class name, and so on. This
command receives CharSequence as an argument and returns nothing.

 element.click():This command allows you to interact with web elements such


as text, links, and radio buttons, among others.

PRAKASAM ENGINEERING COLLEGE Page 16


 element.isEnabled(): This command determines whether or not the element is
currently enabled. This function takes no parameters and produces a boolean
value (true/false).

 element.submit(): If the current element is a form or an element within a form,


this command performs well/better than click(). It takes no parameters and
returns nothing.

 element.getAttribute(): This command returns the value of the element's


specified attribute. It takes a String as input and outputs a String value.

4. Action Commands
The Actions class has a number of methods that return an action object, unless
otherwise stated. In general, the methods of the actions class can be classified into two
groups:

1. Mouse Based Actions


2. Keyboard Based Actions

Mouse Based Actions

 click() :The method is used to perform a click operation at the current mouse
position. This approach has no idea what it's clicking on or where it's clicking.
It only makes a single click on the current place. It does not take any
parameters and returns a self-reference.

 doubleClick() : This approach is used to double-click the mouse cursor where


it is currently located. It takes no input parameters and returns an instance of
the actions class. The moveToElement(element) method was used in the
preceding syntax to move the mouse cursor to the element's location and
double-click it.

 contextClick() :To do a right-click at the current mouse position, use this


method. This technique is also known as the right-click technique.

 dragAndDrop(WebElement,WebElement):This method is used to drop an


element onto another element's position. The source element will be dragged
and dropped in the dragAndDrop() function of the actions class.

PRAKASAM ENGINEERING COLLEGE Page 17


Keyboard Based Actions:
There are three possible keyboard actions to choose from: are keyDown, keyUp, and
sendKeys.

 keyDown(): To test the action of pressing and holding a key, use this
approach. The keys that can be used are Shift, Ctrl and Alt. It takes one of
three input parameters: Keys.SHIFT, Keys.CONTROL, or
Keys.ALT. Selenium will throw an error as IllegalArgumentException if the
passed key isn't one of those.

 keyUp() : This method is used to release a key that was pressed previously
with the keyDown() method, meaning it's just opposite to keyDown. If you try
to use this method on an unpressed key, it will result in undefined behaviour.
 sendKeys(CharSequence): This method is used to enter alphanumeric and
special character keys into WebElements like textareas and textboxes. The
preceding method differs from WebElement's sendKeys(CharSequence)
method. if the provided keys are null it will through
IllegalArgumentException

CODE EXAMPLES FOR PRACTICE

package com.sel.practice;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
import org.openqa.selenium.chrome.ChromeDriver;
public class SampleTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\bujji\\OneDrive\\D
ocuments\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://demo.guru99.com/test/newtours/";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Fire fox and direct it to the Base URL
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");

PRAKASAM ENGINEERING COLLEGE Page 18


} else {
System.out.println("Test Failed");
}
//close Fire fox
driver.close();
}
}
package com.sel.practice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
public class SampleTest2 {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver","C:\\Users\\bujji\\OneDrive\\Documen
ts\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://demo.guru99.com/test/login.html";
driver.get(baseUrl);
// Get the WebElement corresponding to the Email Address(TextField)
WebElement email = driver.findElement(By.name("email"));
// Get the WebElement corresponding to the Password Field
WebElement password = driver.findElement(By.xpath("//*[@id='passwd']"));
email.sendKeys("abcd@gmail.com");
password.sendKeys("abcdefghlkjl");
System.out.println("Text Field Set");
// Deleting values in the text box
email.clear();
password.clear();
System.out.println("Text Field Cleared");
// Find the submit button
WebElement login = driver.findElement(By.id("SubmitLogin"));

// Using click method to submit form


email.sendKeys("abcd@gmail.com");
password.sendKeys("abcdefghlkjl");
login.click();
System.out.println("Login Done with Click");
//using submit method to submit the form. Submit used on password field
driver.get(baseUrl);
driver.findElement(By.id("email")).sendKeys("abcd@gmail.com");

driver.findElement(By.name("passwd")).sendKeys("abcdefghlkjl");

PRAKASAM ENGINEERING COLLEGE Page 19


driver.findElement(By.id("SubmitLogin")).submit();

System.out.println("Login Done with Submit");


driver.close();

}
}
package com.sel.practice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
public class SampleTest3 {
public static void main(String[] args) throws InterruptedException {

// declaration and instantiation of objects/variables


System.setProperty("webdriver.chrome.driver","C:\\Users\\bujji\\OneDrive\\D
ocuments\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://demo.guru99.com/test/radio.html");

WebElement radio1 = driver.findElement(By.id("vfb-7-1"));

WebElement radio2 = driver.findElement(By.id("vfb-7-2"));

//Radio Button1 is selected


radio1.click();
System.out.println("Radio Button Option 1 Selected");

Thread.sleep(5000);
//Radio Button1 is de-selected and Radio Button2 is selected
radio2.click();
System.out.println("Radio Button Option 2 Selected");

// Selecting CheckBox
WebElement option1 = driver.findElement(By.id("vfb-6-0"));

// This will Toggle the Check box


option1.click();
// Check whether the Check box is toggled on
if (option1.isSelected()) {
System.out.println("Checkbox is Toggled On");

} else {
System.out.println("Checkbox is Toggled Off");
}
PRAKASAM ENGINEERING COLLEGE Page 20
driver.close();

}
}
packagecom.sel.practice;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;

publicclassElementLocators {
publicstaticvoidmain(String[] args) {
String baseUrl = "http://demo.guru99.com/test/link.html";
System.setProperty("webdriver.chrome.driver","C:\\Users\\bujji\\OneDrive\\D
ocuments\\chromedriver\\chromedriver.exe");
WebDriver driver = newChromeDriver();
driver.get(baseUrl);
driver.findElement(By.linkText("click here")).click();
System.out.println("title of page is: " + driver.getTitle());
driver.quit();
}

}
AlertBoxes:
packagecom.sel.practice;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
importorg.openqa.selenium.NoAlertPresentException;
importorg.openqa.selenium.Alert;
publicclassAlertBox {
publicstaticvoidmain(String[] args)
throwsNoAlertPresentException,InterruptedException {

System.setProperty("webdriver.chrome.driver","C:\\Users\\bujji\\OneDrive\\D
ocuments\\chromedriver\\chromedriver.exe");
WebDriver driver = newChromeDriver();
// Alert Message handling
driver.get("http://demo.guru99.com/test/delete_customer.php");
driver.findElement(By.name("cusid")).sendKeys("53920");
driver.findElement(By.name("submit")).submit();
// Switching to Alert
Alert alert = driver.switchTo().alert();
// Capturing alert message.
String alertMessage= driver.switchTo().alert().getText();
// Displaying alert message
System.out.println(alertMessage);
PRAKASAM ENGINEERING COLLEGE Page 21
Thread.sleep(5000);

// Accepting alert
alert.accept();
}

}
File Upload:
packagecom.sel.practice;
importorg.openqa.selenium.*;
importorg.openqa.selenium.chrome.ChromeDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
publicclassFileUpload {
publicstaticvoidmain(String[] args) throwsInterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\bujji\\OneDrive\\D
ocuments\\chromedriver\\chromedriver.exe");
String baseUrl = "http://demo.guru99.com/test/upload/";
// WebDriver driver = new FirefoxDriver();
WebDriver driver = newChromeDriver();
driver.get(baseUrl);
WebElementuploadElement = driver.findElement(By.id("uploadfile_0"));
Thread.sleep(5000);
// enter the file path onto the file-selection input field
uploadElement.sendKeys("C:\\newhtml.html");

// check the "I accept the terms of service" check box


driver.findElement(By.id("terms")).click();

// click the "UploadFile" button


driver.findElement(By.name("send")).click();
}
}
CONCLUSION

Selenium is the most effective test automation tool for qa due to its wide range of
features such as open source, supports many languages, integrates easily with many
platforms, has cross browser support and is best suited to test web applications.
Hence, businesses need to prefer selenium tool as a promising test automation tool for
web applications testing. Automated selenium testing services by a next-gen testing
services provider can be leveraged to achieve faster time to market, quicker ROI and
get flawless applications. We have learned the most intriguing features of selenium
and ability to test applications across various web browsers.

PRAKASAM ENGINEERING COLLEGE Page 22

You might also like