You are on page 1of 6

SOFTWARE TESTING UNIT-3 [IMP]

AUTOMATION TESTING
Automation Testing means using an automation tool to execute your test case suite. 


Why automation?
• Manual Testing of all work ows, all elds, and all negative scenarios is time and money
consuming.
• It is dif cult to test for multilingual sites manually.
• Automation does not require Human intervention.
• Automation increases the speed of test execution.
• Manual Testing can become boring and hence error-prone.

Bene ts of automated testing


• Faster than the manual testing.
• Reliable in results.
• Saves time and cost.
• Human intervention is not required while execution.
• Increases ef ciency.
• Re-usable test scripts.

What to automate?
Test cases to be automated can be selected using the following criteria:
• High Risk - Business Critical test cases.
• Test cases that are repeatedly executed.
• Test Cases those are very tedious or dif cult to perform manually.
• Test Cases which are time-consuming. 


The following category of test cases is not suitable for automation:


• Test Cases that are newly designed and not executed manually at least once.
• Test Cases for which the requirements are frequently changing.
• Test cases which are executed on an ad-hoc basis.

Tools for Automation Testing


1. Tricentis
Tricentis is the industry’s #1 Automation Testing platform used for DevOps testing
Features:
• Risk-based testing.
• Scriptless end-to-end test automation. 


2. Mabl
Scriptless end-to-end automation for apps
Features:
• ML models identify issues
• Tests update when UI changes

3. Selenium - explained below

4. QTP
Widely used for functional and regression testing
addresses every major software application and environment.
Features:
• Less technical and easy to adapt
• Supports .NET
Prathamesh S Pai
Page 1 of 6
fi
fi
fi
fl
fi
fi
5. Rational functional tester
Object-Oriented automated functional testing tool
Features:
• Supports Java, HTML, NET, Windows, SAP, Visual Basic, etc.
• can record & replay actions on demand 


6. Watir
Open-source regression testing tool
Features:
• supports multiple browsers
• supports all web apps 


7. Silk Test
Used for doing functional and regression testing.
Features:
• consists of source script les.
• converts the script commands into GUI commands.

SELENIUM
Open-source automated testing suite for web applications
Created by Jason Huggins in 2004.

Components of Selenium
1. Selenium IDE
Simple recording and playback tool developed to speed up the creation of automation scripts. 

Features:
Pros:
• Very easy to use and install.
• No programming experience is required
Cons:
• It is available only in Chrome and Firefox.
• Test execution is slow compared to that of Selenium RC and WebDriver.

2. Selenium RC
It is a server, written in Java, that accepts commands for the browser via HTTP
Features:
Pros:
• It supports cross-browser, cross-platform.
• It supports data-driven testing.

Cons:
• Its installation is more complicated than IDE.
• It needs Selenium RC server to be running.

3. Selenium Grid
Tool which is used together with Selenium RC.
Features:
• Used to run tests on different machines against different browsers in parallel.
• Saves time enormously.

4. Selenium WebDriver
Using Selenium Webdriver, test scripts can be developed using any programming language and
can be directly run in most web browsers

Prathamesh S Pai
Page 2 of 6
fi
Features:
Pros:
• It has simpler installation than Selenium RC.
• It has faster execution time than IDE and RC.


Cons:
• Its installation is more complicated than Selenium IDE.
• One must have programming knowledge to use it.

IDE Features:
Toolbar
The toolbar contains buttons for controlling the execution of your test cases, including a step
feature for debugging your test cases.
Speed Control: controls how fast your test case runs.
Run All: Runs the entire test suite when a test suite with multiple test cases is loaded.
Run: Runs the currently selected test.
Pause/Resume: Allows pausing and resuming of the running test case.
Stop: Stops the current running test case.
Step: Allows you to “step” through a test case by running it one command at a time. Use for
debugging test cases.
Record: Records the user’s browser actions.

Locators in Selenium IDE
Locator is a command that tells Selenium IDE which GUI elements its needs to operate on.

Selenium Commands
open: Opens a URL and waits for the page to load before proceeding.
set window size: Set the browser's window size,

click: Clicks on a target element
type: Sets the value of an input eld, as though you typed it in.
pause: Wait for the speci ed amount of time.

assert text: Con rm that the text of an element contains the provided value.
assert value: Con rm the value of an input eld
assert title: Con rm the title of the current page contains the provided text.
verify element present: Soft assert that the speci ed element is somewhere on the page.
verify element not present: Soft assert that the speci ed element is not somewhere on the page.
verify text: Soft assert the text of an element is present
verify title: Soft assert the title of the current page contains the provided text.
verify value: Soft assert the (whitespace-trimmed) value of an input eld.
select: Select an element from a drop-down menu using an option locator.

Prathamesh S Pai
Page 3 of 6
fi
fi
fi
fi
fi
fi
fi
fi
fi
Summary for locating elements
nds elements based on the value of the ndElement(By.className("someClassName
By.className
"class" attribute "))
nds elements based on the driver's
By.cssSelector ndElement(By.cssSelector("input#email"))
underlying CSS Selector engine
locates elements by the value of their "id"
By.id ndElement(By.id("someId"))
attribute
nds a link element by the exact text it
By.linkText ndElement(By.linkText("REGISTRATION"))
displays
locates elements by the value of "name"
By.name ndElement(By.name("someName"))
attribute
locates elements that contain the given link
By.partialLinkText ndElement(By.partialLinkText("REG"))
text
By.tagName locates elements by their tag name ndElement(By.tagName("div"))

By.xpath locates elements by xpath ndElement(By.xpath(“ ”)

Common Elements
Instantiating Web Elements
Instead of using the long "driver. ndElement(By.locator())" syntax every time you will access a particular
element, we can instantiate a WebElement object for it.

Clicking on an Element
The click() method is used to simulate the clicking of any element.

Get Commands 

Get commands fetch various important information about the page/element. 


Command Description

get() It automatically opens a new browser and fetches the page that you specify inside
its parentheses

getTitle() Fetches the title of the current page

getPageSource() Returns the source code of the page

getCurrentUrl() Fetches the current URL that the browser is looking at.

getText() Fetches the inner text of the element that you specify.

Here is a sample code that locates an element by its id. Facebook is used as the Base URL.

package newproject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium. refox.FirefoxDriver;

public class PG2 {



public static void main(String[] args) {
System.setProperty("webdriver. refox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://www.facebook.com";
String tagName = "";

Prathamesh S Pai
Page 4 of 6
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
driver.get(baseUrl);

tagName = driver. ndElement(By.id("email")).getTagName();
System.out.println(tagName);

driver.close();

System.exit(0);
}}

TestNG
TestNG is an automation testing framework in which NG stands for "Next Generation".

Features:
• TestNG simpli es the way the tests are coded.

• Using testng, you can execute multiple test cases on multiple browsers

• The testing framework can be easily integrated with tools like Maven, Jenkins, etc.

• TestNG can generate the report in a readable format

• The same test case can be executed multiple times without loops just by using keyword called
'invocation count.' 


There are three major advantages of TestNG over JUnit:


• Annotations are easier to understand
• Test cases can be grouped more easily
• Parallel testing is possible 


Let us now create our rst Test Case that will check if Mercury Tours' homepage is correct. Type your code
as shown below.

Prathamesh S Pai
Page 5 of 6
fi
fi
fi
Scenario TestNG:
• Go to the homepage and verify its title.
• Click REGISTER and verify the title of its target page.
• Go back to the homepage and verify if it still has the correct title.
• Click SUPPORT and verify the title of its target page.
• Go back to the homepage and verify if it still has the correct title.


Prathamesh S Pai
Page 6 of 6

You might also like