How to open a new tab with generated report on click of button

Hello,

I am using Katalon to execute a functionality in which,

On click of “View Report”, it generates a report in PDF format and displays it in New Tab.

How to capture this in recording?

OR

How to write a script for the above functionality?

I have tried following code, but it does not work

WebUI.switchToWindowIndex(1) — The Test Case failed, showing an error as an index not found.

WebUI.switchToWindowIndex(0) — Test case showing the result as Pass but does not open the report in a new tab

1 Like

I have used the above statement several times, so I am surprised it does not work and gives you an error. Is your web page slow to open, in which you might want to put in a delay of a few seconds? Maybe try it and see if that could be the issue.

WebUI.delay(3)
WebUI.switchToWindowIndex(1)
1 Like

Hi,

Thank you for the reply.

Yes, it takes time to open a report in the PDF format in a new tab.

As you suggest I have tried the following code,

WebUI.delay(3)

WebUI.switchToWindowIndex(1)

Also, I tried with a Delay of 5 seconds, still getting the following error,

=============== ROOT CAUSE =====================

Caused by: com.kms.katalon.core.exception.StepFailedException: Cannot find window with index: ‘1’

How about try to Tab to the new tab? Use one of your objects on the “default” page to tab to your “new” page.

import org.openqa.selenium.Keys

WebUI.sendKeys(findTestObject(...), Keys.chord(Keys.CONTROL, Keys.TAB))

Edit: Or by using the Robot:

import java.awt.Robot
import java.awt.event.KeyEvent

Robot robot = new Robot()
robot.keyPress(KeyEvent.VK_CONTROL)
robot.keyPress(KeyEvent.VK_TAB)
robot.keyRelease(KeyEvent.VK_CONTROL)
robot.keyRelease(KeyEvent.VK_TAB)
WebUI.delay(0.5)

Hi Thanks For the reply,

I have tried the solution you have provided, but it still does not work, that means pass status I am getting, but my report is not opening in a new tab

WebUI.verifyElementClickable(findTestObject('Master Reports/Page_Tracet - Fixed asset management system/button_View report'))

WebUI.click(findTestObject('Object Repository/Master Reports/Page_Tracet - Fixed asset management system/button_View report'))

WebUI.sendKeys(findTestObject('Object Repository/Master Reports/Page_Tracet - Fixed asset management system/button_View report'), Keys.chord(Keys.CONTROL, Keys.TAB))

Robot robot = new Robot()

robot.keyPress(KeyEvent.VK_CONTROL)

robot.keyPress(KeyEvent.VK_TAB)

robot.keyRelease(KeyEvent.VK_CONTROL)

robot.keyRelease(KeyEvent.VK_TAB)

WebUI.delay(5)

Okay, I think I misunderstood what you wanted. I was under the impression that if you clicked on the “View Report” button that a new tab would appear and you wanted to move to that new tab. The way you state this above is that the report is not appearing at all. If the report is not showing, then you need to either review your “click” object pathway or check if it works manually.