How to download a file with Katalon and with Edge browser navigator?

Hello, I’m using a private website, trying to count the number of pages of a PDF file.
I have come to the conclusion that I need to download the file and then to count it’s pages using PDFBox :

File file = new File(pdfFilePath)

PDDocument pdfDoc = PDDocument.load(file)

int pageCount = pdfDoc.getNumberOfPages()

The fact is, I don’t know how to download the file, when I click on download button on the Website, it opens the pdf in a new browser tab (that’s the problem). Also I’d like to download directly to my Project data files to keep portability of my project.
So I tried doing “ctrl + S” to open register manager, but it doesn’t work apparently :

WebUI.delay(10)

WebDriver driver = DriverFactory.getWebDriver()

Actions actions = new Actions(driver)

actions.keyDown(Keys.CONTROL).sendKeys("s").keyUp(Keys.CONTROL).perform()

Thanks by advance.

Geoffroy

For the above issue, have you tried the below. Just a note that others suggest putting a WAIT, or delay, just before you switch to allow time for the statement to determine the new tab’s existence and index.

'Switch to new browser tab'
WebUI.switchToWindowIndex(1)
1 Like

Also you can switch tab using tab name title @gdaumer
with this keyword

WebUI.switchToWindowTitle('Put The Tab Title Name Here')
1 Like

Hi.
For chrome, there are desired capabilities you can set to make the browser do the download action instead of opening the pdf in a new tab. Here was an example to do that: Is it possible to add relative path in Desired Capabilities - #2 by joost.degeyndt

I would assume a similar example works for edge, to be run in proper test listener Before testcase (so before the browser is opened). Note that there might also be some deviations in setting these in Katalon v10.0.0 (see Migrate Katalon Studio from 9.x to 10.0.0 | Katalon Docs ).

import com.kms.katalon.core.configuration.RunConfiguration

// Get the current project directory
String projectDir = RunConfiguration.getProjectDir()

// Set the relative path for the download directory
String downloadDir = projectDir + "/Downloads"

// Set the desired capabilities for Edge
Map<String, Object> edgePrefs = new HashMap<String, Object>()
edgePrefs.put("download.default_directory", downloadDir)
edgePrefs.put("download.prompt_for_download", false)
edgePrefs.put("plugins.always_open_pdf_externally", true)

Map<String, Object> edgeOptions = new HashMap<String, Object>()
edgeOptions.put("prefs", edgePrefs)

RunConfiguration.setWebDriverPreferencesProperty("edgeOptions", edgeOptions)