UNIT-V - Notes
UNIT-V - Notes
UNIT-V - Notes
Functional Testing
A single end-user can make the whole system crash in minutes, even after
unit, integration, and performance tests have passed. This usually happens
because the user does something the developers did not expect. The purpose
of functional testing is therefore to ensure that the functionality of the
software works as intended for an end-user. It tests this through the UI of
the application. As opposed to non-functional testing, it doesn’t deal with
the underlying source code, and doesn’t evaluate things like speed,
scalability, and reliability. There are many types of functional tests.
Examples of functional tests in a web application UI include testing that:
The login to your web application is successful across browsers and
devices
The web application is interacting as intended with external
databases and syncing successfully
Invoices are being sent and received with the correct information and
securely
Buttons, text fields, menus, etc., are working as per the requirements
Usability Testing
Usability testing focuses on design aspects rather than functional aspects,
assessing the user experience, and how intuitive and user-friendly the web
application is.
Key aspects include:
User Interface Evaluation: Analyzing the layout, design, and navigability.
User Experience Testing: Assessing the ease of learning and using the
application.
Accessibility Testing: Ensuring the application is accessible to all
users, including those with disabilities.
Regression Testing
Regression testing is critical whenever updates or changes are made to the
application. It ensures that new code doesn't negatively impact existing
functionality, and typically includes functional tests as part of its scope.
This type of testing:
Verifies Existing Functionality: Ensures that previous functions still
operate as intended after modifications.
Identifies Unintended Consequences: Catches any new bugs
introduced by recent changes.
End-to-End Testing
End-to-end testing examines the complete functionality of the web
application from start to finish, emulating real user scenarios. It aims to
ensure that all components of the application work together seamlessly.
Panimalar Engineering College 6
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
End-to-end testing is typically applied to a business’ most important or
common business processes, to reduce the risk that these key flows break.
This involves:
Workflow Testing: Ensuring all the integrated parts of the application
interact correctly.
Data Integrity Testing: Confirming that data maintains its integrity
throughout all transactions.
Cross-Browser Testing
With the variety of browsers available, browser-based testing ensures that
the web application performs consistently across different browsers and
their versions. This testing type:
Ensures Compatibility: Verifies that the application functions
correctly on various browsers.
Identifies Browser-Specific Issues: Highlights any layout or functional
issues unique to certain browsers.
Related reading: How to automate web testing across browsers and
devices
Performance Testing
Performance testing evaluates the web application’s stability and responsiveness
under various conditions. This includes:
Load Testing: Assessing the application's ability to handle high volumes of
users.
Stress Testing: Determining the application's breaking point and how
it recovers from failure.
Speed Testing: Measuring response times and the speed of page
loading under normal conditions.
Disadvantages:
It only supports groovy(java). So it is feasible for java users only.
It is not an open-source tool. It is closed source code, and it further
results in a small community.
There are some performance issues, like more interruption causing the device to
slow down.
Cucumber
Advantages:
It is a collaborative tool based on behavior-driven development.
It is an open-source automated software testing tool.
It helps in writing acceptance tests for our web applications.
It provides the amalgamation of both test documentation and its
specification(specs).
It supports multi-languages like python,perl,ruby,.net etc.
Panimalar Engineering College 8
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
It is provided with cross-platform compatibility.
It can be integrated with DevOps tools like GIT, Jenkins, etc., for better
enhancement.
Disadvantages:
Integration and its dependency on generating reports through
plugins can be challenging enough.
Every time a new attribute or feature undergoes it, we have to ensure all
current steps
and validate them to see if they can be used.
Selenium
Advantages:
It is the most versatile automated software testing tool.
This tool is open-source and widely supports all languages and
frameworks.
It comes with heavy library packages.
It supports cross-browser automation, API automation, and database
automation.
Testers can use it for regression, exploratory testing, and quick
reproduction of bugs.
It can be beneficial in parallel test execution techniques.
It is highly known for its flexibility with ease of implementation.
Its integration with gauge automation framework, Galen framework,
lambda test, etc., is trending nowadays.
Disadvantages:
Test Maintenance in selenium can become cumbersome and even
expensive sometimes.
Selenium requires coding skills, if not exceptional but above average,
though.
It is only supported for web applications, though.
Technical support and its reliability can cause problems, though.
Flaky tests can be a big problem as they generate false negatives and
false positives or vice versa.
to Selenium.
We can use Selenium WebDriver to do the following:
Create robust, browser-based regression automation
Scale and distribute scripts across many browsers and platforms
Create scripts in your favourite programming language.
2. Selenium Server
Selenium Server allows us to run tests on browser instances running
on remote machines and in parallel, thus spreading a load of testing across
several machines. We can create a Selenium Grid, where one server runs as
the Hub, managing a pool of Nodes. We can configure our tests to connect to
the Hub, which then obtains a node that is free and matches the browser we
need to run the tests. The hub has a list of nodes that provide access to
browser instances, and lets tests use these instances similarly to a load
balancer.
Selenium Grid enables us to execute tests in parallel on multiple
machines by managing different types of browsers, their versions, and
operating system configurations centrally.
3. Selenium IDE
Selenium IDE is a Firefox add-on that allows users to record, edit, debug,
Panimalar Engineering College 10
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
and play back tests captured in the Selenese format, which was introduced
in the Selenium Core version. It also provides us with the ability to convert
these tests into the Selenium RC or Selenium WebDriver format. We can use
Selenium IDE to do the following:
Create quick and simple scripts using record and replay, or use
them in exploratory testing
Create scripts to aid in automation-aided exploratory testing
Create macros to perform repetitive tasks on Web pages
5.3.2 WebElements
A web page is composed of many different types of HTML elements, such as
links, textboxes, dropdown buttons, a body, labels, and forms. These are
called WebElements in the context of WebDriver. Together, these elements
on a web page will achieve the user functionality. For example, let's look at
the HTML code of the login page of a website:
<html>
<body>
<form id="loginForm">
<label>Enter Username: </label>
<input type="text" name="Username"/>
<label>Enter Password: </label>
<input type="password" name="Password"/>
<input type="submit"/>
</form>
<a href="forgotPassword.html">Forgot Password ?</a>
</body>
</html>
In the preceding HTML code, there are different types of WebElements, such
as <html>,
<body>, <form>, <label>, <input>, and <a>, which together make a web page
provide the Login feature for the user. Let's analyze the following WebElement:
<label>Enter Username: </label>
Here, <label> is the start tag of the WebElement label. Enter Username: is the
text present on the label element. Finally, </label> is the end tag, which
indicates the end of a WebElement. Similarly, take another WebElement:
<input type="text" name="Username"/>
In the preceding code, type and name are the attributes of the WebElement
input with the text and Username values, respectively.
UI-automation using Selenium is mostly about locating these
WebElements on a web page and executing user actions on them.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
As you can see, there are three new things that are highlighted, as follows:
WebElement subbtn = driver.findElement(By.id("nav-search-submit-
button")); They are the findElement() method, the By.id() method, and the
WebElement interface. The findElement() and By() methods instruct
WebDriver to locate a WebElement on a web page, and once found, the
findElement() method returns the WebElement instance of that element.
Actions, such as click and type, are performed on a returned WebElement
using the methods declared in the WebElement interface.
In the preceding code, the last four lines of code use the getAttribute()
Panimalar Engineering College 15
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
method to fetch the attribute values of the name, id, class, and placeholder
attributes of the WebElement search box. The output of the preceding code
will be following:
Name of the box is: q
Id of the box is: search
Class of the box is: input-text required-
entry Placeholder of the box is: Search
entire store here...
Going back to the By.tagName() method of the previous section, if the
search by a locating mechanism, By.tagName, results in more than one
result, you can use the getAttribute() method to further filter the results and
get to your exact intended element.
1. Firefox Driver
The new driver for Firefox is called Geckodriver. The Geckodriver
provides the HTTP API described by the W3C WebDriver Protocol to
communicate with Gecko browsers, such as Firefox. It translates calls into
the Firefox Remote Protocol (Marionette) by acting as a proxy between the
local and remote ends.
Using GeckoDriver:
First of all, we need to download the Geckodriver executable from
https://github.com/ mozilla/geckodriver/releases. Download the
appropriate version of Geckodriver based on the Firefox version installed on
your computer as well as the operating system. Copy the executable file into
the /src/test/resources/drivers folder.
Provide the path of the Geckodriver binary in the
webdriver.gecko.driver property, and instantiate the FirefoxDriver class:
WebDriver driver;
System.setProperty("webdriver.gecko.driver","./src/test/resources/drivers/
geckodriver
.exe");
driver = new FirefoxDriver();
driver.get("http://demo-store.seleniumacademy.com/");
Using Headless Mode
Headless mode is a very useful way to run Firefox for automated testing
with Selenium WebDriver. In headless mode, Firefox runs as normal only
you don't see the UI components. This makes Firefox faster and tests run
more efficiently, especially in the CI (Continuous Integration) environment.
We can run Selenium tests in headless mode by configuring the
FirefoxOptions class, as shown in the following code snippet:
WebDriver driver;
System.setProperty("webdriver.gecko.driver",
"./src/test/resources/drivers/geckodriver 2"); FirefoxOptions
firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(true);
driver = new FirefoxDriver(firefoxOptions);
During the execution, you will not see the Firefox window on the screen but
the test will be executed in headless mode.
2. Chrome Driver
The ChromeDriver works similar to the Geckodriver and implements
the W3C WebDriver protocol. First of all, we need to download the chrome
driver executable from https://chromedriver.chromium.org/downloads.
Download the appropriate version of chromedriver based on the Chrome
version installed on computer as well as the operating system. Copy the
executable file into the /src/test/resources/drivers folder.
Provide the path of the chromedriver binary in the
Panimalar Engineering College 19
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
webdriver.chrome.driver property, and instantiate the ChromeDriver class:
System.setProperty("webdriver.chrome.driver","C:\\seleniumwebdriver
\\chromedrive r-in64 \\chromedriver.exe");
WebDriver driver=(WebDriver) new
ChromeDriver();
driver.get("https://www.amazon.in");
4. Edge Driver
Microsoft Edge is the latest web browser launched with Microsoft Windows
10. Microsoft Edge was one of the first browsers to implement the W3C
WebDriver standard and provides built-in support for Selenium WebDriver.
Similar to Internet Explorer, in order to execute test scripts on the
Microsoft Edge browser, we need to use the EdgeDriver class and a
standalone Microsoft WebDriver Server executable. The Microsoft WebDriver
Server is maintained by the Microsoft Edge development team. You can find
more information at https://docs.microsoft.com/en- gb/microsoft-
edge/webdrive.
Panimalar Engineering College 20
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
We need to download and install Microsoft WebDriver Server on
Windows 10 (https://developer.microsoft.com/en-us/microsoft-
edge/tools/webdriver/):
WebDriver driver;
System.setProperty("webdriver.edge.driver","./src/test/resources/drivers/
MicrosoftWe bDriver.exe");
EdgeOptions options = new
EdgeOptions();
options.setPageLoadStrategy("eager
"); driver = new
EdgeDriver(options);
driver.get("http://demo-store.seleniumacademy.com/");
5. Safari Driver
With Selenium 3.0 and WebDriver becoming the W3C standard, Apple now
provides SafariDriver built into the browser. We do not have to download it
separately. However, in order to work it with Selenium WebDriver, we have
to set a Develop | Allow Remote Automation option from Safari's main
menu. This is as straight forward. The following is the test script using the
Safari Driver:
WebDriver driver;
driver = new SafariDriver();
driver.get("http://demo-store.seleniumacademy.com/");
Implementing WebDriverEventListener
The WebDriverEventListener interface has all the event methods declared.
The EventFiringWebDriver class, as soon as it realizes an event has
occurred, invokes the registered method of WebDriverEventListener. Here,
we have created an IAmTheEventListener named class and have
implemented WebDriverEventListener.
Extending AbstractWebDriverEventListener
The second way to create a listener class is by extending the
AbstractWebDriverEventListener class. AbstractWebDriverEventListener is
an abstract class that implements WebDriverEventListener. Though it
doesn't really provide any implementation for the methods in the
WebDriverEventListener interface, it creates a dummy implementation such
that the listener class that you are creating doesn't have to contain all the
methods, only the ones that you, as a test-script developer, are interested
in. The following is a class we have created that extends
AbstractWebDriverEventListener and provides implementations for a couple
of methods in it. This way, we can override only the methods that we are
interested in rather than all of the methods in our class:
package com.example;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.support.events.AbstractWebDriverEventList
ener; public class IAmTheEventListener2 extends
AbstractWebDriverEventListener { @Override
public void beforeNavigateTo(String url, WebDriver
driver) { System.out.println("Before Navigate To "+
url);
}
@Override
Panimalar Engineering College 23
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
public void beforeNavigateBack(WebDriver driver) {
System.out.println("Before Navigate Back. Right now I'm at "
+ driver.getCurrentUrl());
}
}
5.8 TESTNG
#1) A Suite is represented by one XML file. It can contain one or more tests
and is defined by the <suite> tag.
Example: <suite name=”Search Suite”>
TestNG.xml Example:
#4) A Test method is a Java method annotated by @Test methods in the source
file.
package com.example;
import org.testng.annotations.Test;
import
org.testng.annotations.BeforeMethod
; import org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDrive
r; import org.testng.Assert;
import org.testng.annotations.AfterMethod;
public class
SearchTest {
WebDriver
driver;
@BeforeMethod
public void setup()
{
System.setProperty("webdriver.chrome.driver","C:
\\selenium webdriver\\chromedriver-
win64\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://demo-store.seleniumacademy.com/");
}
@Test
@AfterMethod
public void
tearDown() {
driver.quit();
}
}
#5) Run the test by right clicking on the TestNG xml file and select Run As -
> TestNG Suite. Once the testng.xml file has run, we can see the test
reports in the console as shown below:
===============================================
Suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
Sample Project:
a. Open Eclipse.
b. create a project MutiTest .
c. In MultiTest create a package firstpackage.
d. In firstpackage create a class
FirstTestClass {
@Test
public void firstTest(){
System.out.println(firstTest);
Panimalar Engineering College 28
21IT1904 UNIT-V SOFTWARE TESTING AND AUTOMATION
assertEquals("My First Test",
firstTest);
}
@Test
public void secondTest(){
System.out.println(secondTest);
assertEquals("My Second Test",
secondTest);
}
}
1. Adding Packages:
Using 'Package' configuration option TestNG will execute all the test inside
specified Package. Let us add packages to the test suite.
Output:
Running the proceeding xml file will give
output: “My First Test”
“My Second Test”
===============================================
Suite
Total tests run: 2, Passes: 2, Failures: 0, Skips: 0
===============================================
Now we have successfully executed TestNG test Suite by adding test packages
to the suite.
2. Adding Classes:
Using 'Class' configuration option TestNG enables us to run only specified
class name along with its package name. Let us add specified class/classes to
the test suite.
</test>
</suit
e> Output:
Running the proceeding Xml file will output:
“My First Test”
“My Second
Test”
===============================================
Suite
Total tests run: 2, Passes: 2, Failures: 0, Skips: 0
===============================================
Now we have successfully executed TestNG test Suite by adding class to a
test. Similarly, we can add multiple classes by adding required number of
Class tags in xml file.
3. Adding Methods:
Using this option TestNG enables us to run only specified method in a
test class.
Reporting is the most important part of any test execution, as it helps the
user understand the result of the test execution, point of failure, and the
reasons for failure. Logging, on the other hand, is important to keep an eye
on the execution flow or for debugging in case of any failures. TestNG, by
default, generates a different type of report for its test execution. This
includes an HTML and an XML report output. TestNG also allows its users
to write their own reporter and use it with TestNG. There is also an option to