0

私のテストケースでは、WebページからExcelファイルをエクスポート/ダウンロードする必要があります。 Firefoxのプロファイルを使用して、ダウンロードダイアログをポップアップウィンドウに表示するときにダウンロードを受け入れます。ローカルウィンドウでテストを実行すると、次のコードが動作します。Jenkins(Windows OS)上でヘッドレスFirefox WebDriverを実行しています

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

私はJenkinsでテストを実行したいが、私は問題に取り組んでいる。私はfirefoxプロファイルを初期化した直後に、ライン上でNullpointer例外を受け取ります。これは、Firefoxのプロファイルがピックアップされなかったことを意味します。以下はエラーです。

enter image description here

enter image description here

ジェンキンスさんは、私はFirefoxのプロファイル部を介して作成されたFirefoxのプロファイル「セレン」を理解していない場合、私は疑問に思って。

注:Windowsのコマンドラインからテストを実行できますが、Jenkinsではテストを実行できません。

ご協力いただきまして誠にありがとうございます。

+0

'FirefoxProfile'は、従来のクラスがドライブ上のプロファイルを構築することです。代わりに 'FirefoxOptions'を使用して設定を行います。 –

+0

ありがとうFlorent B、これは働いた:)私はあなたの答えをどう受け入れるのですか? – Ophelia

答えて

0

代わりの機能を使用しての、使用FirefoxOptions

FirefoxOptions options = new FirefoxOptions(); 
options.addArgument("--headless"); 
WebDriver driver = new FirefoxDriver(options); 
関連する問題