Lesson 9
Lesson 9
paramtech.com.tr
©2024. Tüm hakları saklıdır.
Contents
3 Introduction to Selenium
4 Selenium Components
1 - Introduction to Test Automation
1- Introduction to Test Automation
01 Test Automation
Test automation involves using automated tools to perform tests that check the functionality of
software applications. This approach saves time and reduces human errors.
Error Risk Higher risk of human error. Lower risk of human error.
1
1- Introduction to Test Automation
1
1- Introduction to Test Automation
Advantages Disadvantages
Fast Test Execution: Tests are executed quickly. High Initial Cost: Requires investment in
tools and software development.
Reduced Human Error: Human errors are Ongoing Maintenance Needed: Tests and
minimized. tools require maintenance over time.
Time Saving: Saves time, especially for large test Only for Repetitive Tests: Automation
sets. may not cover all types of tests.
Early Bug Detection: Bugs are detected earlier Incompatibility with Software Changes:
in the development process. Changes in the software may invalidate
automation tests.
1
1- Introduction to Test Automation
Selenium: A widely used open-source tool for testing web applications. It supports multiple
programming languages (Java, Python, C#, etc.).
Cypress: A modern tool for testing web applications, especially designed for JavaScript-based web
applications, offering fast and efficient testing.
Playwright: A powerful test automation tool for web applications. It supports multiple browsers
and is used for testing modern web applications.
Appium: An open-source automation testing tool for mobile applications on both Android and iOS
platforms.
Espresso: A test automation tool for Android applications developed by Google. It is specifically
designed for Android UI testing.
1
1- Introduction to Test Automation
RestAssured: A Java-based library used to test REST APIs. It is commonly used for API validation
tests.
Karate: A tool for testing APIs, supporting both RESTful and SOAP APIs. It uses Gherkin syntax for
writing tests.
TestNG: A testing framework similar to JUnit, but with more advanced features like parallel test
execution.
Postman: A popular tool for API testing, especially for validating RESTful APIs.
1
1- Introduction to Test Automation
Jenkins: An open-source continuous integration (CI) and continuous delivery (CD) tool that facilitates the
automated testing and deployment of software projects.
GitHub Actions: A tool that integrates directly with GitHub to automate continuous integration and
continuous delivery workflows, triggering actions based on changes made in the GitHub repository.
GitLab CI/CD: A continuous integration and continuous delivery platform that integrates with GitLab,
automating tests and deployments throughout the software development lifecycle.
Azure Pipeline: A CI/CD tool that runs on the Microsoft Azure platform, automating the build, test, and
deployment processes for projects hosted on Azure, GitHub, or other repositories.
1
1- Introduction to Test Automation
01 Report Tools
Allure Report:
Allure is a tool that generates stylish, interactive test reports with detailed visuals, including test
steps, screenshots, and success/failure statuses.
Extent Reports:
Extent Reports is a comprehensive HTML reporting tool that visualizes test results with rich details,
such as success rates, failure logs, and screenshots, often used with Selenium and Appium.
1
1- Introduction to Test Automation
1
1- Introduction to Test Automation
1
1- Introduction to Test Automation
● Data-Driven Framework
1
1- Introduction to Test Automation
● Keyword-Driven Framework
1
1- Introduction to Test Automation
● Hybrid Framework
Key Features:
1
1- Introduction to Test Automation
Page Object Model (POM) is a design pattern in test automation. Each page of the application is
represented as a class, and this class contains the page elements and methods used to interact with
those elements.
Advantages:
● Ease of Maintenance: When the UI changes, only the corresponding class needs to be updated.
● Reusability: The same page objects can be reused across different test cases.
● Less Code Duplication: Code becomes modular, following the DRY principle.
● Readability: Test scripts are cleaner and more understandable.
Structure:
02 Rest Assured
Rest Assured is a Java-based framework used for testing RESTful web services. It allows you to easily make
HTTP requests and validate responses with a simple API. It is an ideal tool for automation testing, particularly
to verify the functionality and accuracy of an API.
● Ease of Use: It allows testing of RESTful APIs with minimal code writing.
● Java-Based: It integrates well with popular Java test frameworks like JUnit or TestNG.
● Versatility: It can work with both JSON and XML-based data.
● Validation: It provides built-in methods to easily validate HTTP responses and data.
● CI/CD Integration: It can be integrated with tools like Jenkins to automate API testing.
2
2 - RestAssured and API Automation
User Interface GUI-based with no coding required Code-based, Java library for automation
Scripting Capabilities JavaScript scripting for testing Java-based, offers full programming flexibility
Manual Testing Ideal for manuel testing Primarily focused on automated testing
Integration It integrates with CI/CD tools It can be integrated into CI/CD pipelines
(Jenkins, GitHub Actions) and through the CLI (Newman) but offers limited
testing frameworks (JUnit, TestNG). flexibility.
Complex Testing Suitable for basic to intermediate Provides advanced options for handling
Scenarios scenarios complex scenarios
Reporting Comprehensive reporting can be Basic reporting can be done using collection
done using frameworks like reports and CLI (Newman).
JUnit/TestNG.
2
2 - RestAssured and API Automation
When performing manual It is not suitable for manual Ideal for manual testing.
testing testing.
When writing automated Suitable for complex and Can be used for simple
test scenarios automation-focused automation scenarios.
scenarios.
When CI/CD integration is Provides strong and flexible Can be integrated via CLI
required CI/CD integration. but is less flexible.
2
2 - RestAssured and API Automation
Advantages Disadvantages
Readable Code: Its simple and understandable Java Dependency: It can only be used in Java-based
syntax makes it user-friendly. projects, not suitable for other languages.
Wide Format Support: Easily works with data Lack of GUI: It does not offer a user-friendly
formats like JSONPath and XMLPath. graphical interface; it works entirely through code.
Integration: Being Java-based, it easily integrates Learning Curve: Learning Java and API testing
with popular frameworks like JUnit, TestNG, and concepts can take time for beginners..
Maven
Validation and Reporting: It provides powerful tools Limited Features: Rest Assured is focused only on
for validating HTTP response codes, response times, HTTP-based API testing, offering limited support for
and JSON/XML. other types of protocols or APIs.
2
2 - RestAssured and API Automation
EXAMPLE :
Summary:
2
2 - RestAssured and API Automation
> @Test
> RestAssured.baseURI
2
2 - RestAssured and API Automation
2
2 - RestAssured and API Automation
> when()
2
2 - RestAssured and API Automation
> then()
> statusCode(200)
2
2 - RestAssured and API Automation
> extract()
> response()
2
2 - RestAssured and API Automation
2
2 - RestAssured and API Automation
> JSONObject
2
2 - RestAssured and API Automation
> post()
2
3 - Introduction to Selenium
3 - Introduction to Selenium
03 Selenium
3
3 - Introduction to Selenium
Advantages Disadvantages
Open-source and free to use Installation and setup process can be time-consuming.
Supports multiple programming languages (Java, Lacks a built-in reporting mechanism; requires integration
Python, C#, etc.). with third-party tools.
Compatible with multiple platforms (Windows, macOS, Does not provide direct support for visual validation (e.g.,
Linux). image-based testing).
Works with most browsers (Chrome, Firefox, Edge, Limited integration with mobile devices; additional tools like
Safari, etc.). Appium are needed.
Allows parallel test execution. Prone to errors caused by external factors like network
delays.
Has an active community and is constantly updated. Capturing dynamic web elements can be complex and
time-consuming.
3
4 - Selenium Components
4 - Selenium Components
04
4
4 - Selenium Components
4
4 - Selenium Components
Find by ID: The fastest and most reliable method when elements have a unique ID attribute.
For Example:
4
4 - Selenium Components
For Example:
● #menu_load_money
● [id='menu_login']
● .btn-uyeol
4
4 - Selenium Components
For Example:
Attribu
te
Name
Like input,
div, img value of
etc. the
attribute
XPath=//tagname[@Attrib
attribute
ute='value']
//a[@id='menu_login'] Select
attribute
tagname value
4
4 - Selenium Components
4
4 - Selenium Components
Usage: element.click()
4
4 - Selenium Components
Example:
gsmNumber.sendKeys("55555");
password .sendKeys("1234");
WebElement loginButton =
driver.findElement(By.id("loginButton"));
loginButton.click();
4
4 - Selenium Components
4
4 - Selenium Components
4
4 - Selenium Components
Usage: driver.getTitle();
Usage: driver.getCurrentUrl();
element.isEnabled();
4
4 - Selenium Components
Usage: element.clear();
Usage: element.isSelected();
Example:
4
4 - Selenium Components
● quit(): Closes all browser windows and ends the WebDriver session.
Usage: driver.quit();
Usage: driver.close();
4
4 - Selenium Components
04 WebDriver Wait
When testing web applications, it’s essential to wait for dynamic elements to
load before interacting with them. Selenium provides three main types of
WebDriver Waits to handle such scenarios effectively:
1. Implicit Wait
2. Explicit Wait
3. Fluent Wait
4
4 - Selenium Components
Usage:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
4
4 - Selenium Components
4
4 - Selenium Components
Wait Time Fixed for all elements. Varies based on conditions. Fully customizable
timeout and polling.
Performanc May wait unnecessarily More efficient as it targets Efficient and precise for
e long. specific conditions. dynamic elements.
Best Use Static elements with Dynamic elements or Highly dynamic content
Cases predictable load times. conditions requiring with variable load times.
precision.
4
4 - Selenium Components
The annotations provided by TestNG allow tests to run in a specific order or under
certain conditions. Here are the most commonly used TestNG annotations and
examples.
4
4 - Selenium Components
04
Example:
Integration with Test Frameworks
@Test(priority = 1)
4
4 - Selenium Components
@BeforeMethod
@AfterMethod
4
4 - Selenium Components
@BeforeClass
driver.manage().window().maximize();}
@AfterClass
4
4 - Selenium Components
@BeforeSuite
@AfterSuite
4
4 - Selenium Components
Summary Table:
Annotation Purpose
@Test Defines a test method.
04 Selenium Grid
Selenium Grid is a tool that allows you to execute parallel tests on different browsers,
devices, and operating systems simultaneously. It enables distributed testing, reducing
execution time and testing compatibility across various environments.
4
4 - Selenium Components
04 Selenium Grid
● Hub:
○ The central server of Selenium Grid.
○ Receives test commands and routes
them to the appropriate Node.
○ Only one Hub is required.
● Node:
○ Machines connected to the Hub.
○ Hosts browsers where the tests are
executed.
○ Multiple Nodes can be added.
4
4 - Selenium Components
04 Selenium Grid
How It Works
4
4 - Selenium Components
4
4 - Selenium Components
4
4 - Selenium Components
04 Selenium IDE
4
4 - Selenium Components
04 Selenium IDE
4
Useful Information
Example Contents:
https://github.com/nursensinc/RestAssuredExample
https://github.com/nursensinc/SeleniumExample
6
7
50
Java Selenium
https://www.java.com/tr/download/manual.jsp
https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html
https://www.jetbrains.com/idea/download/other.html
6
8
Visual : https://prnt.sc/Ic6Icmd4w6fm
51
THANK YOU
param.com.tr