簡體   English   中英

Katalon Studios - 驗證瀏覽器是否啟動下載

[英]Katalon Studios - Verify if browser launch download

Katalon Studios 有沒有辦法檢查瀏覽器是否啟動下載? 和/或之后下載的文件是否在系統中?

也許這是不可能的,因為它脫離了瀏覽器的 scope。

非常感謝

以下是如何從文檔檢查文件下載的示例:

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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM