2017-02-14 58 views
0

測試是通過單擊下載模板鏈接來下載文件。當我在本地機器上執行腳本時,它運行得很完美。能夠創建下載文件夾,並且下載的文件存儲在新創建的「下載」文件夾中。 但是,當我將它集成到詹金斯管道時,沒有創建文件夾,也沒有下載文件。 注意:在jenkins管道中,腳本是在硒網格中使用chrome執行的。請參閱chrome驅動程序中的配置。Selenium:無法在Jenkins管道中創建要下載的文件夾和文件

HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); 
chromePrefs.put("profile.default_content_settings.popups", 0); 
chromePrefs.put("download.default_directory", System.getProperty("user.dir") + "\\src\\main\\resources\\downloads"); 
ChromeOptions options = new ChromeOptions(); 
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>(); 
options.setExperimentalOption("prefs", chromePrefs); 
options.addArguments("--test-type"); 
DesiredCapabilities cap = DesiredCapabilities.chrome(); 
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap); 
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 
cap.setCapability(ChromeOptions.CAPABILITY, options); 
driver = new RemoteWebDriver(new URL(seleniumGridUrl), cap); 

回答

0

如果你不打算在你的測試中檢查下載文件的內容,我想建議使用一種旁路方法。使用HTTP庫,您可以執行Head http調用資源,您需要下載。在響應中你會得到文件類型和大小。在你的測試中,你只要聲明他們來驗證訪問下載文件的正確性。 我認爲你得到的問題與權限連接,不允許在環境中創建文件夾/文件,執行測試。