2017-12-15 11 views
0

E2E 테스트를 위해 각도기를 사용하고 있습니다. 자동화 중에는 시스템의 C : \ Automation 폴더에 파일을 다운로드해야합니다. 그러나 아래 코드는 작동하지 않습니다.각도기를 사용하여 Firefox에서 지정된 절대 경로로 파일을 다운로드

참고 : 자동화 실행 중에 다른 이름으로 저장 팝업이 열리 며 (나중에 비활성화해야 함) 수동으로 "저장"옵션을 클릭합니다. 그것은 기본 위치 즉 다운로드 폴더에 저장합니다. 어떻게하면 내 지정된 경로에 저장하게 할 수 있습니다.

let profile = require('firefox-profile');   
let firefoxProfile = new profile(); 

//_browser = 'chrome'; 
_browser = 'firefox'; 
// _browser = 'internet explorer'; 

firefoxProfile.setPreference("browser.download.folderList", 2); 
firefoxProfile.setPreference('browser.download.dir', "C:\\Automation"); 

exports.config = { 
framework: 'custom', 
frameworkPath: require.resolve('protractor-cucumber-framework'), 
capabilities: { 
    'browserName': _browser, 
    'shardTestFiles': false, 
    'maxInstances': 1, 
    'acceptInsecureCerts': true, 
    'moz:firefoxOptions': { 
    'profile': firefoxProfile 
    }}, 
beforeLaunch: function() {...} 
} 

답변

0

파이어 폭스와 작동하는 데 몇 가지 기본 설정이 누락 된 것처럼 보입니다. 추가해보고 도움이되는지 확인하십시오.

profile.setPreference("browser.download.manager.showWhenStarting", false); 
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", 
    /* A comma-separated list of MIME types to save to disk without asking goes here */); 
0

이것은 프로젝트 내의 다운로드 폴더에 저장됩니다. 원하는 폴더에 저장하기 위해 조정할 수 있습니다. 프롬프트없이 다운로드 할 파일 유형을 지정해야합니다. JSON과 CSV는 이미 있습니다.

var q = require('q'); 
var path = require('path'); 
var sh = require("shelljs"); 
var cwd = sh.pwd().toString(); 

var FirefoxProfile = require('selenium-webdriver/firefox').Profile; 

var makeFirefoxProfile = function(preferenceMap) { 
    var profile = new FirefoxProfile(); 
    for (var key in preferenceMap) { 
     profile.setPreference(key, preferenceMap[key]); 
    } 
    return q.resolve({ 
     browserName: 'firefox', 
     marionette: true, 
     firefox_profile: profile 
    }); 
}; 

exports.config = { 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    framework: 'jasmine2', 
    getMultiCapabilities: function() { 
     return q.all([ 
      makeFirefoxProfile(
       { 
        'browser.download.folderList': 2, 
        'browser.download.dir': (path.join(cwd, 'downloads')).toString(), 
        'browser.download.manager.showWhenStarting': false, 
        'browser.helperApps.alwaysAsk.force': false, 
        'browser.download.manager.useWindow': false, 
        'browser.helperApps.neverAsk.saveToDisk': 'application/octet-stream, application/json, text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext, text/plaintext' 
       } 
      ) 
     ]); 
    }, 
    allScriptsTimeout: 1000000, 
    specs: ['./tmp/**/*.spec.js'], 

    jasmineNodeOpts: { 
     defaultTimeoutInterval: 1000000, 
     showColors: true 
    }, 
    onPrepare: function() { 
     browser.driver.getCapabilities().then(function(caps) { 
      browser.browserName = caps.get('browserName'); 
     }); 

     setTimeout(function() { 
      browser.driver.executeScript(function() { 
       return { 
        width: window.screen.availWidth, 
        height: window.screen.availHeight 
       }; 
      }).then(function(result) { 
       browser.driver.manage().window().setPosition(0,0); 
       browser.driver.manage().window().setSize(result.width, result.height); 
      }); 
     }); 
    } 
};