11/6/17

Handle Pop Up In Katalon Studio

When performing automation testing, you may sometimes deal with pop-up dialog issue that needs to be handled differently from normal test objects. This tutorial shows you how to deal with pop-up controls.

 What is a pop-up?
A pop-up is a graphical display area, usually in a form of a small window that appears (pop-up) in the foreground of the current interface.
 What are issues with pop-up?
The problem with pop-ups is that they usually show up unexpectedly. There is no certain way to overcome this except that you need to understand the behavior of the application and insert scripts accordingly to handle the situation. Another issue with pop-ups is that they are not from the AUT so you need to handle them with dedicated keywords.
Below are a few commonly used pop-ups which might cause problems in your test web automation:
1. New browser window.
2. Alert: An alert box is often used to make sure that information comes through to the user.
Handle Pop Up Dialog Box in Katalon STudio
 3. Custom modal dialog: A modal dialog is a dialog box/pop-up window that is displayed on top of the current page.
Custom modal dialog
 4. Native Window dialog. This dialog is common in case of testing uploading files
Native Window dialog
 A suggested solution for handling pop-ups using Katalon Studio:
To handle such pop-ups as described, you need to capture them first using the Object Spy feature in Katalon Studio. After that, you use Switch To… keywords of Katalon Studio to set focus to the specified pop-up as needed.
The following screenshot shows simple scripts on how to handle a pop-up using the Switch To Window Title (https://goo.gl/vnf7gH) keyword.

import com.kms.katalon.core.annotation.SetUp as SetUp

import com.kms.katalon.core.annotation.TearDown as TearDown

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

'Open browser and navigate to jQuery UI page'
WebUI.openBrowser('http://jqueryui.com/')

'Maximize current browser window'
WebUI.maximizeWindow()

'Click on \'Draggle\' link'
WebUI.click(findTestObject('Page_jQuery_Homepage/lnk_Draggable'))

'Switch to iframe of Demo panel'

WebUI.switchToFrame(findTestObject('Page_jQuery_Drag and Drop Example/ifr_Demo Frame'),

             GlobalVariable.G_Timeout_Small, FailureHandling.STOP_ON_FAILURE)

'Drag and drop iframe into other position'

WebUI.dragAndDropByOffset(findTestObject('Page_jQuery_Drag and Drop Example/div_Frame_Draggable'),

200, 38)

'Switch back to current window'

WebUI.switchToDefaultContent()

'Click on \'Droppable\' link'

WebUI.click(findTestObject('Page_jQuery_Homepage/lnk_Droppable'))

'Switch to iframe of Demo panel'
WebUI.switchToFrame(findTestObject('Page_jQuery_Drag and Drop Example/ifr_Demo Frame'),

               GlobalVariable.G_Timeout_Small, FailureHandling.STOP_ON_FAILURE)

'Drag the left rectangle and Drop it the right-side one'
WebUI.dragAndDropToObject(findTestObject('Page_jQuery_Drag and Drop Example/div_Frame_Draggable'),

 findTestObject('Page_jQuery_Drag and Drop Example/div_Frame_Droppable'), FailureHandling.STOP_ON_FAILURE)

WebUI.closeBrowser()
Where:
KeywordDescription
Switch To Window Title
https://goo.gl/7tJpbV
Switch to the window identified by a given title.
Switch To Window Index
https://goo.gl/gWU32X
Switch to the window identified by a given index.
Switch To Window Url
https://goo.gl/XhHzhM
Switch to the window identified by a given URL.


If you want to switch back to the default window (parent), use the Switch To Default Content (https://goo.gl/M9SyFB) keyword. For example:

'Open browser and navigate to a site that has an iframe'
WebUI.openBrowser(GlobalVariable.G_SiteURL)
 
'Switch to iframe'
WebUI.switchToWindowTitle(‘Share a link on Twitter’)
 
'Switch back to default content'
WebUI.switchToDefaultContent()
 
'Close browser'
WebUI.closeBrowser()
 Where:

Keyword
Description
Switch To Default Content
https://goo.gl/jJ24RZ
Switch back to the default window, after working with iFrame windows.



  To deal with Windows’ native dialogs such as uploading files, users use the Upload File (https://goo.gl/ybn61v) keyword. For example:

'Open browser and navigate to a site that has upload control'
WebUI.openBrowser(‘http://the-internet.herokuapp.com/upload’)

'Use Upload File keyword to deal with the dialog. Noted that the keyword will proceed to click on the Choose File button as specified'
WebUI.uploadFile(findTestObject('choosefile_button'), 'D:\\test-photo.png')

'Close browser'
WebUI.closeBrowser() 
Where:
KeywordDescription
Upload File
https://goo.gl/BJuVTh
Specify the file for the upload dialog.

Regarding the browser’s popups as mentioned above, you can modify Desired Capabilitiesof the browser to prevent them from displaying. You can refer to this ticket for an example on how to disable the Chrome password manager.

Exceptions

Noted that NoSuchWindowException exception will be thrown when window target to be switched doesn’t exist.

0 comments:

Post a Comment