Running headless Firefox WebDriver on Jenkins (Windows OS)

1.5k Views Asked by At

My test cases involve export/download the excel files from web pages. For which I am using Firefox profile to accept the downloads when the download dialog popup on windows. The following code is working when I execute my test on local windows.

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);

I want to run the tests on Jenkins and I have been running into the issues. I receive Nullpointer exception on the line right after I initialize the firefox profile. Which means the firefox profile did not pickup. Following is the error.

enter image description here

enter image description here

I am wondering if Jenkins is not understanding the firefox profile "Selenium" which I created through Firefox Profile section.

Note: I can run my tests from the windows command line but not through the Jenkins.

Any help is highly appreciated.

1

There are 1 best solutions below

0
On

Instead of using capabilities, use FirefoxOptions

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