簡體   English   中英

在Jenkins(Windows OS)上運行無頭Firefox WebDriver

[英]Running headless Firefox WebDriver on Jenkins (Windows OS)

我的測試案例涉及從網頁導出/下載excel文件。 當Windows上出現下載對話框時,我正在使用Firefox概要文件為此目的接受下載。 在本地窗口上執行測試時,以下代碼有效。

ProfilesIni profile = new ProfilesIni();
    FirefoxProfile fProfile = profile.getProfile("Selenium");

    fProfile.setPreference("browser.download.folderList", 2); 
    fProfile.setPreference("browser.download.manager.showWhenStarting", false);
    fProfile.setPreference("browser.download.dir", "C:\\temp\\reports\\");
    fProfile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
    fProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
    fProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
    fProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    fProfile.setPreference("browser.download.manager.focusWhenStarting", false);
    fProfile.setPreference("browser.download.manager.useWindow", false);
    fProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
    fProfile.setPreference("browser.download.manager.closeWhenDone", false);

    fProfile.setAcceptUntrustedCertificates(true);
    fProfile.setAssumeUntrustedCertificateIssuer(true);
    fProfile.setPreference("security.insecure_field_warning.contextual.enabled", false);        
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(FirefoxDriver.PROFILE, fProfile);
    capabilities.setCapability("marionette", true);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setAcceptInsecureCerts(true);
     driver = new FirefoxDriver(capabilities);

我想在詹金斯上進行測試,並且一直遇到問題。 初始化firefox配置文件后,我在行上收到Nullpointer異常。 這意味着Firefox配置文件沒有拾取。 以下是錯誤。

在此處輸入圖片說明

在此處輸入圖片說明

我想知道詹金斯是否不了解我通過Firefox Profile部分創建的firefox配置文件“ Selenium”。

注意:我可以從Windows命令行運行測試,但不能通過Jenkins運行。

非常感謝您的幫助。

代替使用功能,使用FirefoxOptions

FirefoxOptions options = new FirefoxOptions();
options.addArgument("--headless");
WebDriver driver = new FirefoxDriver(options);

暫無
暫無

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

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