DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Top Automation Testing Tools for 2024
  • 6 of the Best API Testing Tools in the Market
  • Postman for API Testing — Pros, Cons, and Alternative Solutions

Trending

  • Beyond Bytecode: Exploring the Relationship Between JVM, JIT, and Performance
  • OTel Me Why: The Case for OpenTelemetry Beyond the Shine
  • Master SQL Performance Optimization: Step-by-Step Techniques With Case Studies
  • Beyond Web Scraping: Building a Reddit Intelligence Engine With Airflow, DuckDB, and Ollama
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. How to Handle Alerts Using Katalon Studio

How to Handle Alerts Using Katalon Studio

Alerts have become a big part of the way people interact with web pages. Read on to see how to use this free tool to make the process of creating alerts a little easier.

By 
Oliver Howard user avatar
Oliver Howard
·
Mar. 15, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
10.7K Views

Join the DZone community and get the full member experience.

Join For Free

1. What Is an alert?

An alert is a JavaScript function which is used to notify users on a Web page. It displays a dialog with a specified message and OK/Cancel buttons.

The alert is a modal dialog that takes the focus away from the current window and forces the user to take action before performing other actions. It also prevents the user from accessing other parts of the page until the user performs the action presented in the dialog. For example, when the user clicks on the “Delete” button, an alert would be triggered asking the user, ‘Are you sure, you want to delete this?’ The user has to take action on this dialog.

You can handle alerts using Katalon Studio's built-in keywords. This tutorial shows how to do so with HTML examples. You can get the HTML by clicking here.

2. Handle Alerts Using Katalon Studio

2.1. Handle Accept Alert

This alert method is used to confirm an action performed by the user. You can handle this method either in the manual or script mode.

Manual Mode

  • Step 1: Launching the browser and navigating to the Alert present page using the Open Browser method.
  • Step 2: Maximize the window of the browser.
  • Step 3: Click on the button.
  • Step 4: Call the Accept alert method.

Handle Accept Alerts using Katalon StudioScript Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser navigating to Alert present page\r\n'
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\\\How to Handle Alerts.html')

'Maximize the window of the browser'
WebUI.maximizeWindow()

'Clicking on  button'
WebUI.click(findTestObject('Alerts/button_ClickHere'))

'Accepting the Alert'
WebUI.acceptAlert()

2.2. Handle Dismiss Alert

This alert method is used to ask the user to cancel something.

Manual Mode

  • Step 1: Launching the browser and navigating to the Alert present page using the Open Browser method.
  • Step 2: Maximize the window of the browser.
  • Step 3: Click on the button.
  • Step 4: Call the Dismiss alert method.

Handle dismiss alerts using Katalon Studio

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser navigating to Alert present page\r\n'
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\Alerts\\How to Handle Alerts2.html')

'Maximize the window of the browser'
WebUI.maximizeWindow()

'Clicking on  button'
WebUI.click(findTestObject('Alerts/button_ClickHere'))

'Dismiss the Alert '
WebUI.dismissAlert()

2.3. Send data to an alert dialog

We can pass text to an Alert text message by using the sendKeys() method.

Manual Mode

  • Step 1: Launching the browser and navigating to the Alert present page using the Open Browser method. 
  • Step 2: Maximize the window of the browser.
  • Step 3: Click on the button.
  • Step 4: Using the sendKeys method, pass the text to an Alert.

Send data to an alert dialog using Katalon Studio

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser navigating to Alert present page\r\n'
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\Alerts\\How to Handle Alerts2.html')

'Maximize the window of the browser'
WebUI.maximizeWindow()

'Clicking on  button'
WebUI.click(findTestObject('Alerts/button_ClickHere'))

WebDriver driver = DriverFactory.getWebDriver()

'Passing the text in the text box in the Alert\r\n'
driver.switchTo().alert().sendKeys('Testing')

'Dismiss the Alert'
WebUI.dismissAlert()

2.4. Capture the Alert Message

We can see the message used in the Alert by using the getText() method.

Manual Mode

  • Step 1: Launching the browser and navigating to the Alert present page using the Open Browser method.
  • Step 2: Maximize the window of the browser.
  • Step 3: Click on the button.
  • Step 4: Getting the text from the alert and storing it in a variable.
  • Step 5: Verifying the Actual and Expected text used in the Alert.

Capture the alert message using Katalon Studio

Script Mode

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

'Launching the browser'
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\Alerts\\How to Handle Alerts2.html')

'Maximize the window of the browser'
WebUI.maximizeWindow()

'Clicking on the click here button'
WebUI.click(findTestObject('Alerts/button_ClickHere'))

WebDriver driver = DriverFactory.getWebDriver()

'Getting the text from the alert and storing it in Variable'
String AlertText = driver.switchTo().alert().getText()

'Verifying the Actual and Expected text from Alert'
WebUI.verifyEqual(AlertText, 'Please enter your name')

The source code is available to be downloaded here.

For further instructions and help, refer to WebUI Alert and Solving pop-up dialog issue with Katalon Studio.

Katalon Studio

Published at DZone with permission of Oliver Howard. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Top Automation Testing Tools for 2024
  • 6 of the Best API Testing Tools in the Market
  • Postman for API Testing — Pros, Cons, and Alternative Solutions

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: