Katalon Studios-验证浏览器是否启动下载



Katalon Studios有没有办法检查浏览器是否启动下载?和/或下载的文件之后是否在系统中?

也许这是不可能的,因为它超出了浏览器的范围。

非常感谢

以下是如何检查从文档下载的文件的示例:

import org.openqa.selenium.By as By
import org.openqa.selenium.WebDriver as WebDriver
import org.testng.Assert as Assert
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

'Define Custom Path where file needs to be downloaded'
String downloadPath = 'D:\FileDownloadChecking'

'Launch a browser and Navigate to URL'
WebUI.openBrowser(GlobalVariable.FileDownloadCheckingURL)

WebDriver driver = DriverFactory.getWebDriver()

'Clicking on a Link text to download a file'
driver.findElement(By.linkText('smilechart.xls')).click()
'Wait for Some time so that file gets downloaded and Stored in user defined path'
WebUI.delay(10)

'Verifying the file is download in the User defined Path'
Assert.assertTrue(isFileDownloaded(downloadPath, 'smilechart.xls'), 'Failed to download Expected document')

boolean isFileDownloaded(String downloadPath, String fileName) {
long timeout = 5 * 60 * 1000
long start = new Date().getTime()
boolean downloaded = false
File file = new File(downloadPath, fileName)
while (!downloaded) {
KeywordUtil.logInfo("Checking file exists ${file.absolutePath}")
downloaded = file.exists()
if (downloaded) {
file.delete() // remove this line if you want to keep the file
} else {
long now = new Date().getTime()
if (now - start > timeout) {
break
}
Thread.sleep(3000)
}
}
return downloaded
}