0% found this document useful (0 votes)
16 views18 pages

Software testing Unit V (1)

Uploaded by

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

Software testing Unit V (1)

Uploaded by

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

1

UNIT V - TEST AUTOMATION AND TOOLS


Automated software testing, Automate testing of web applications, selenium : Introducing
web driver and Web elements,Locating web elements, Actions on web elements, Different web
drivers, Understanding web driver events, Testing : Understanding Testing.xml, Adding classes,
packages, Methods to test, Test reports.
Automated software Testing:
 Automated software Testing is the implementation of an automation tool to execute test cases.
 Automated testing is the application of software tools to automate a human-driven manual
process of reviewing and validating a software product.
Automate testing of web Application :
The various types of automated Web application testing are mentioned below:
 Functional Testing. ...
 Web Usability Testing. ...
 Performance Testing. ...
 Website Compatibility Testing. ...
 Security Testing. ...
 Katalon Studio. ...
 Cucumber. ...
 Selenium.

Functional Testing

 It is used to ensure that the functionality specified as part of the software requirements works
deliberately from the end user’s perspective.

 Functional testing is a day-to-day knowledge that the test process that uncovers the most bugs
lets the end-user explore the software.

Web Usability Testing

 It can automate the research process, mainly when working with remote participants.
 User testing software aids you to connect with users and automatically gathers data without
any deliberation and then displays who hit their goals or where users struggled, allowing you to
2

build better products for happier customers, you can even call it automated end-user experience
testing. Automating it can save resources, reduce cost, get an overall test coverage, and have an
enhanced return of investment(ROI) for design.
 It's a good idea to have others evaluate your work with fresh eyes, and this is especially true in
user experience and web design.Taken From Article, Guide to Usability Testing

Performance Testing

 Automation and performance monitoring go hand-in-hand.


 Automation permits you to check and monitor the load and performance of the particular
application 24/7, so when things go out of control, it automatically alerts someone, or you
create a ticket in a service desk.
 Not only that, automation allows us to monitor performance in physical servers, virtual hosts,
virtual machines, and applications giving us an enhanced output.

Website Compatibility Testing


To deliver a great enhanced end user experience, web apps and websites should work across various
browsers, browser versions, and devices, including mobile.
It hosts all the possible combinations of browsers, operating systems,and devices in our infrastructure
to support automated web testing.

Security Testing
 Automating web application security testing can help minimize human errors and also decrease
the cost factor. For automating security testing in a web application, we need massive test
coverage, the accuracy of test results, scheduled security tests,
 Choosing appropriate tools and, in the end, to implement and iterate the process.
 Software or hardware conducted on an entire, integrated system to assess the system's
compliance with its specified requirements.Taken From Article, System Testing Types, Best
Practices and Tools
What are the best tools for it?
1) Ketalon studio:

1. It is convenient and accessible to different types of testers(inclusive and exclusive of both


programmings).
2. It is flexible and easy to use with its quick, powerful features(robust).
3. It also supports image-based testing, which is quite an enhanced and new feature.
3

4. It supports integration with Jenkins.


5. It’s known for its hassle-free, customizable execution workflow.
6. It can support web application automation, API Testing, Mobile Testing.
7. It has built-in support for creating test cases, generating test scripts, reporting results, recording
actions. It is famous for its built-in support for groovy(java) scripting languages.
8. It can be integrated with CI/DevOps workflow and other tools.
What do we dislike?

1. It only supports groovy(java). So it is feasible for java users only.


2. It is not an open-source tool. It is closed source code, and it further results in a small
community.
3. There are some performance issues, like more interruption causing the device to slow down.
2) Cucumber:

1. It is a collaborative tool based on behavior-driven development.


2. It is an open-source automated software testing tool.
3. It helps in writing acceptance tests for our web applications.
4. It provides the amalgamation of both test documentation and its specification(specs).
5. It supports multi-languages like python,perl,ruby,.net etc.
6. It is provided with cross-platform compatibility.
7. It can be integrated with DevOps tools like GIT, Jenkins, etc., for better enhancement.

3) Selenium:

1. It is the most versatile automated software testing tool.


2. This tool is open-source and widely supports all languages and frameworks.
3. It comes with heavy library packages.
4. It supports cross-browser automation, API automation, and database automation.
5. Testers can use it for regression, exploratory testing, and quick reproduction of bugs.
6. It can be beneficial in parallel test execution techniques.
7. It is highly known for its flexibility with ease of implementation.
8. Its integration with gauge automation framework, Galen framework, lambda test, etc., is
trending nowadays.
4

Selenium : Introducing Web driver and Web Elements

Selenium WebDriver is the most important component of Selenium Tool's Suite. The latest release
"Selenium 2.0" is integrated with WebDriver API which provides a simpler and more concise
programming interface.

The following image will give you a fair understanding of Selenium components and the Test
Automation Tools.

Selenium WebDriver performs much faster as compared to Selenium RC because it makes direct calls
to the web browsers. RC on the other hand needs an RC server to interact with the browser.

WebDriver has a built-in implementation of Firefox driver (Gecko Driver). For other browsers, you
need to plug-in their browser specific drivers to communicate and run the test. Most commonly used
WebDriver's include:
o Google Chrome Driver
o Internet Explorer Driver
5

o Opera Driver
o Safari Driver
oHTML Unit Driver (a special headless driver)
LOCATING WEB ELEMENTS:
 Locators in Selenium are very important in the test automation of web applications. It helps
developers and testers locate and interact with the web elements on a web page to conduct
automated testing.
 Using locators, it is easy to locate and identify particular HTML elements, including links,
dropdown menus, buttons, and text boxes. It is very important to understand locators while
utilizing Selenium to build strong, dependable, and maintainable automated tests.
 Locators in Selenium are key to automated software testing, allowing automation tools to
interact with UI elements.
 Types of locators include ID, name, class, tag name, link text, and partial link text locators,
chosen based on the test case's specific needs and the properties of the element located.
 The efficient use of locators can significantly improve the speed and accuracy of test
automation, making it an essential aspect of modern software development.

Method Syntax Description


Locates an element
By ID driver.findElement(By.id(<element ID>)) using the ID
attribute
Locates an element
By name driver.findElement(By.name(<element name>)) using the Name
attribute
Locates an element
By class
driver.findElement(By.className (<element class>)) using the Class
name
attribute
Locates an element
By tag name driver.findElement(By.tagName (<htmltagname>)) using the HTML
tag
6

Method Syntax Description


Locates a link using
By link text driver.findElement(By.linkText (<linktext>))
link text
Locates a link using
By partial
driver.findElement(By.partialLinkText (<linktext>)) the link's partial
link text
text
Locates an element
By CSS driver.findElement(By.cssSelector (<css selector>)) using the CSS
selector
Locates an element
By XPath driver.findElement(By.xpath (<xpath>))
using XPath query

SELENIUM ACTIONS ON WEB ELEMENTS


Web Element states can also be inspected in terms of whether they are enabled or disabled, visible or
hidden on the page. As a result, all these operations make Web Elements in Selenium an incredibly
useful test automation tool for web applications.

In Selenium, actions on web elements typically involve interacting with web elements, such as
clicking buttons, entering text, dragging and dropping, hovering, and more. Selenium provides various
ways to perform these actions directly or through more complex chained actions. Here’s a breakdown
of commonly used Selenium actions for web elements.

Basic Actions

1. Clicking Elements:
python
Copy code
element = driver.find_element(By.ID, "example-id")
element.click()

2. Sending Keys (Typing Text):


python
Copy code
element = driver.find_element(By.NAME, "example-name")
element.send_keys("Hello World")

3. Clearing Text:
python
Copy code
element = driver.find_element(By.NAME, "example-name")
element.clear()

Advanced Actions (Using ActionChains)


7

Selenium's ActionChains class allows you to perform more complex actions, such as hovering,
double-clicking, right-clicking, and even drag-and-drop operations. First, you’ll need to import it:
python
Copy code
from selenium.webdriver.common.action_chains import ActionChains

1. Hovering Over an Element:


python
Copy code
element = driver.find_element(By.CSS_SELECTOR, "example-css-selector")
action = ActionChains(driver)
action.move_to_element(element).perform()

2. Double-Clicking:
python
Copy code
element = driver.find_element(By.ID, "example-id")
action = ActionChains(driver)
action.double_click(element).perform()

3. Right-Clicking (Context Click):


python
Copy code
element = driver.find_element(By.ID, "example-id")
action = ActionChains(driver)
action.context_click(element).perform()

4. Drag and Drop:


python
Copy code
source = driver.find_element(By.ID, "source-element-id")
target = driver.find_element(By.ID, "target-element-id")
action = ActionChains(driver)
action.drag_and_drop(source, target).perform()

5. Click and Hold:


python
Copy code
element = driver.find_element(By.ID, "example-id")
action = ActionChains(driver)
action.click_and_hold(element).perform()

6. Releasing a Click:
python
Copy code
action.release().perform()

7. Typing a Key Combination (e.g., CTRL+A):


python
8

Copy code
from selenium.webdriver.common.keys import Keys

element = driver.find_element(By.NAME, "example-name")


action = ActionChains(driver)
action.click(element).key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).
perform()

Scrolling Actions

1. Scrolling to an Element:
python
Copy code
element = driver.find_element(By.ID, "example-id")
driver.execute_script("arguments[0].scrollIntoView();", element)

2. Scrolling to the Bottom of the Page:


python
Copy code
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Waiting for Actions to be Ready

To ensure actions are performed on elements that are ready, you can use WebDriverWait:
python
Copy code
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "example-id")))


element.click()

These actions are fundamental for building reliable, interactive tests with Seleni
DIFFERENT WEB DRIVERS
 Drivers are required for different types of browsers. Selenium WebDriver refers to both the
language bindings and the implementations of the individual browser controlling code. This is
commonly referred to as just WebDriver.

 Selenium WebDriver is a web framework that permits you to execute cross-browser tests. This
tool is used for automating web-based application testing to verify that it performs expectedly.
Selenium WebDriver also allows you to choose a programming language to create test scripts.

TYPES OF SELENIUM WEB DRIVER


9 classes implements WebDriver interface:
9

1. ChromeDriver: For Google Chrome. This is supported by chromium project. ChromeDriver is


a standalone server that implements the W3C WebDriver standard. ChromeDriver is available
for Chrome on Android and Chrome on Desktop (Mac, Linux, Windows and ChromeOS).

2. ChromiumDriver: A WebDriver implementation that controls a Chromium browser running


on the local machine. Do not confuse it with Chrome, Chromium is an open-source browser
project that forms the basis for the Chrome web browser. It is used as the base class for
Chromium-based browser drivers (Chrome, Edgium). ChromeDriver class extends
ChromiumDriver.
3. EdgeDriver: For Microsoft Edge Browser. It extends ChromiumDriver.
4. EventFiringWebDriver: For webdriver listener event. EventFiringWebDriver is a JavaClass,
basically it is a wrapper around an arbitrary WebDriver instance which supports registering of
WebDriverEventListener.
5. FirefoxDriver: For Firefox browser. FirefoxDriver is implemented and supported by Mozilla.
6. InternetExplorerDriver: The InternetExplorerDriver is a standalone server which implements
WebDriver's wire protocol. This driver has been tested with IE 7, 8, 9, 10, and 11 on
appropriate combinations of Vista, Windows 7, Windows 8, and Windows 8.1. As of 15 April
2014, IE 6 is no longer supported. The driver supports running 32-bit and 64-bit versions of the
browser. It extends RemoteWebDriver.
7. OperaDriver: For Opera Browser. It is supported by Opera Software.
8. RemoteWebDriver: Used with Selenium Grid. The RemoteWebDriver class implements the
WebDriver interface to execute test scripts through the RemoteWebDriver server on a remote
machine. It implements WebDriver, JavaScriptExecutor and several other interfaces.
9. SafariDriver: For Mac Safari Browser. SafariDriver is supported directly by Apple. To
support WebDriver without sacrificing a user’s privacy or security, Safari’s driver provides
extra safeguards to ensure that test execution is isolated from normal browsing data and from
other test runs. The driver is available in Safari 10 or later. It extends RemoteWebDriver.

10. Apart from above list, you might have listen some name like:

 Ghost Driver, Which is pure JavaScript implementation of WebDriver Wire protocol.


 HTMLUnitDriver: HtmlUnitDriver is a WebDriver compatible driver for the HtmlUnit
headless browser. You need to include Maven or Gradle dependency to work with it.
 Selenium2Driver Which is used with PHP Mink and provides bridge for Selenium2
Webdriver.
UNDERSTANDING WEB DRIVER EVENTS
Selenium WebDriver provides an API for tracking the various events that happen when test scripts are
executed using WebDriver. Many navigation events get fired before and after a WebDriver internal
event occurs (such as before and after navigating to a URL, and before and after browser back-
navigation) and these can be tracked and captured.
There are two ways in which we can implement the Webdriver Event Listeners:
1. WebDriverEventListener which is an interface that has some predefined methods for tracking
Webdriver events. It requires us to implement ALL the methods predefined in the Interface.
10

2. AbstractWebDriverEventListener Class provides us with the facility of implementing only


those methods in which we are interested.

WebDriverEventListener Interface

Predefined Methods used to implement the WebDriverEventListener Interface are enlisted below:
(i) void beforeChangeValueOf(WebElement arg0, WebDriver arg1,CharSequence[] arg2)
This method is triggered when we perform either the sendKeys() or clear() operation on the Web
Element. [For instance, driver.findElement(By.id(“Login”)).clear()], and is
triggered BEFORE performing the operation on the Web Element.
Parameters:
arg0= Web Element
arg1=driver

(ii) void afterChangeValueOf(WebElement arg0, WebDriver arg1,CharSequence[] arg2)


This method is triggered when we perform either the sendKeys() or clear() operation on the Web
Element. [For instance, driver.findElement(By.id(“Login”)).clear()], and is
triggered AFTER performing the operation on the Web Element.
Parameters:
arg0= Web Element
arg1=driver

(iii) void beforeClickOn(WebElement arg0, WebDriver arg1)


This method is triggered BEFORE we click on any Web Element.
Parameters:
arg0= Web Element
arg1=driver

(iv) void afterClickOn(WebElement arg0, WebDriver arg1)


This method is triggered AFTER we click on any Web Element.
Parameters:
arg0= Web Element
arg1=driver

(v) void beforeNavigateTo(String arg0, WebDriver arg1)


This method is triggered when we use navigate().to(String URL)[ For instance,
navigate().to(“https://www.google.com”) ], and is triggered BEFORE navigating to the URL.
Parameters:
arg0= URL
arg1=driver

(vi) void afterNavigateTo(String arg0, WebDriver arg1)


This method is triggered when we use navigate().to(String URL)[ For instance,
navigate().to(“https://www.google.com”) ], and is triggered AFTER navigating to the URL.
Parameters:
arg0= URL
arg1=driver
11

(vii) void beforeNavigateBack(WebDriver arg0)


This method is triggered when we use the command navigate().back(). It takes
place BEFORE redirecting the user to the previous page.
Parameters:
arg0=driver
(viii) void afterNavigateBack(WebDriver arg0)
This method is triggered when we use the command navigate().back(). It takes
place AFTER redirecting the user to the previous page.
Parameters:
arg0=driver
(ix) void beforeNavigateForward(WebDriver arg0)
This method is triggered when we use the command navigate().forward(). It takes
place BEFORE redirecting the user to the next page.
Parameters:
arg0=driver
(x) void afterNavigateBack(WebDriver arg0)
This method is triggered when we use the command navigate().forward(). It takes
place AFTER redirecting the user to the next page.
Parameters:
arg0=driver
(xi) void beforeNavigateRefresh(WebDriver arg0)
This method is triggered when we use the command navigate().refresh(). It takes
place BEFORE refreshing the current page.
Parameters:
arg0=driver
(xii) void afterNavigateRefresh(WebDriver arg0)
This method is triggered when we use the command navigate().refresh(). It takes
place AFTER refreshing the current page.
Parameters:
arg0=driver
(xiii) void beforeFindBy(By arg0, WebElement arg1, WebDriver arg2)
This method is triggered when we use the command driver.findElement(By.id(“Some id or any
other locator”)). It takes place BEFORE finding the Web Element.
Parameters:

UNDERSTANDING TESTING .XML


 In Testing framework, we need to create Testng xml file to create and handle multiple test
classes. We do configure our test run, set test dependency, include or exclude any test, method,
class or package and set priority etc in the xml file.

 TestNG.xml file is an XML file which contains all the Test configuration and this XML file
can be used to run and organize our test.
The testng.xml file has the numerous uses as listed below

 Test cases are executed in groups.


 Test methods can be included or excluded in the execution.
 The execution of multiple test cases from multiple java class files can be triggered.
 Comprises names of the folder, class, method.
12

 Capable of triggering parallel execution.


 Test methods belonging to groups can be included or excluded in the execution.
There are two methods to create a TestNG XML file, feel free to use either of them-
Method 1:

 Right-click on the project folder & towards the bottom of the list, select TestNG and then
“Convert to TestNG.”
 Click on Next
 The next window that pops up will have the refactored source code, which would be applicable
after you click Finish.
 A new addition to your project directory would be displayed named as testng.xml.
 Double click on testng.xml to open the xml file
Method 2:

 Right-click on Project, then New, and finally select File.


 Next, enter the following file name “testng.xml” and then click on Finish.
 In this step, you will have to enter the XML code manually. That is how the two methods differ
from each other. After entering the XML code, you can select a name for your liking suite and
class. This is what a basic XML file looks like-
Adding classes,Packages and Methods to test

Code on testing XML file :

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">

<test name="Test">

<classes>

<class name="testng.TestNGTestOne"/>

</classes>

</test> <!-- Test -->

</suite> <!-- Suite -->

TestNG XML file is for running parallel tests in a Selenium Grid, it is time to learn how to create a
TestNG XML file.
13

<?xml version = "1.0" encoding = "UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name = "Cycle1">

<test name = "QAblepoint">

<classes>

<class name = "Test1" />

<methods>

<exclude name= “Login.*”/>

</methods>

</classes>

</test>

</suite>

package com.test.firstpackage;

import org.testng.annotations.Test;
14

public class FirstClassInFirstPackage


{

@Test
public void firstTestCase()
{
System.out.println("First TestNG test in First Package");
}

@Test
public void secondTestCase()
{
System.out.println("Second TestNG test in First Package");
}

@Test
public void thirdTestCase()
{
System.out.println("Third TestNG test in First Package");
}
}
TEST REPORTS
Testing Reports are the default HTML reports which are generated once the test cases are executed
using TestNG. These reports help you to identify the information about test cases and the status of a
project. TestNG reports in Selenium have three methods passTest, failTest, and skipTest to check the
data about test cases.
15

Consider the scenario in where you are intentionally failing the test case i.e. DemoB class.
Then convert both the classes into testng.xml suite file and run it. Then the result will look like this. It
will show the failed test cases.
This is result for DemoB class:

In software testing, reports are essential to track the progress, quality, and outcomes of tests. Test
reports help teams understand what passed, failed, or needs further investigation, making them vital
for decision-making. Here’s an overview of the main types of test reports and how you can create
them.

1. Types of Test Reports


a) Execution Reports

 Purpose: Show test execution details for a particular run.


 Contents: Contains results of each test case (pass, fail, skipped), timestamps, and error logs.
 Tools: Many testing frameworks (JUnit, NUnit, TestNG, etc.) generate these reports
automatically.
b) Defect Reports

 Purpose: Track defects found during testing.


 Contents: Defect ID, severity, steps to reproduce, environment details, and status (new, in-
progress, closed).
 Tools: Bug-tracking tools like JIRA, Bugzilla, and Azure DevOps.
c) Coverage Reports

 Purpose: Provide information on code or feature coverage.


 Contents: Percentage of code lines, statements, or features covered by tests.
 Tools: Coverage tools like JaCoCo, Istanbul, and Clover generate coverage reports for code.
16

d) Summary Reports

 Purpose: Give a high-level view of test results for stakeholders.


 Contents: High-level summary of test cases executed, passed, failed, and blocked tests, along
with major defects and observations.
 Tools: Reports can be generated manually or using test management tools like TestRail and HP
ALM.
e) Continuous Integration Reports

 Purpose: Report on tests executed within the CI/CD pipeline.


 Contents: Automated test results, build status, and logs for each deployment stage.
 Tools: CI/CD tools like Jenkins, GitLab CI, and CircleCI.

2. Test Report Structure

Here's a typical structure of a detailed test report:

1. Header:
o Title: Name of the test report
o Date: Execution date
o Environment: Details about the environment (staging, production, etc.)
o Prepared by: Tester’s name or team

2. Summary of Execution:
o Total test cases
o Passed, failed, skipped test cases
o Key highlights and observations

3. Test Case Details:


o Test Case ID: Identifier for the test case
o Description: Brief description of the test case
o Status: Pass, fail, or skipped
o Logs or Screenshots: For failures or anomalies

4. Defects Summary:
o List of bugs, defect IDs, severity, and current status

5. Coverage Information:
o Coverage percentage and details on areas tested/not tested

6. Observations and Recommendations:


o Any important observations made during testing, along with suggested next steps or
focus areas for improvement.

3. Generating Test Reports


17

Using Testing Frameworks

Most frameworks have built-in reporting capabilities or plugins that can generate detailed reports.

 JUnit and TestNG (Java): Use plugins like Allure or ExtentReports for detailed HTML or
XML reports.
java
Copy code
@AfterSuite
public void generateReport() {
// Code to integrate with reporting plugin
}

 Pytest (Python): Pytest has built-in reporting, and you can use plugins like pytest-html or
pytest-allure:
bash
Copy code
pytest --html=report.html --self-contained-html
Using Continuous Integration Tools

CI/CD tools often generate reports as part of the deployment pipeline:

 Jenkins: Use plugins like JUnit or Allure to generate and visualize reports.
 GitLab CI and CircleCI: Configure YAML files to store and share reports.
Using Custom Scripts

In some cases, custom scripts (Python, JavaScript) can parse results and create custom reports in
HTML, JSON, or CSV format.

4. Tools for Generating Reports

 Allure Report: A popular tool for generating HTML reports across multiple languages and
frameworks.
 ExtentReports: Offers beautiful HTML reports with dashboards, logs, and screenshots.
 ReportPortal: For real-time reporting, integrations with CI/CD pipelines, and log aggregation.
 TestRail: Comprehensive test case management and reporting tool for large teams.

5. Best Practices for Test Reports

 Automate Reports: Use automated scripts or CI/CD tools to generate reports after every test
run.
 Use Visual Elements: Include charts and graphs to make the reports easier to interpret.
 Include Screenshots for Failures: Screenshots for failed tests help with debugging.
 Summarize for Different Audiences: Have a summary at the top for stakeholders and detailed
sections for technical teams.
 Highlight Key Defects and Risks: Identify the most critical issues, their impact, and any
potential risks.
18

Creating informative test reports helps streamline testing and debugging, making it easier for teams to
address issues and ensure quality in software development.

You might also like