2015-12-29 48 views
3

嗨!量角器+ CucumberJS + Gulp-Protractor =當測試失敗時瀏覽器未關閉

我正試圖關閉瀏覽器,一旦測試失敗,目前,它通過它時,它會關閉。

我使用

"cucumber": "^0.9.2", 
"gulp": "~3.9.0", 
"gulp-protractor": "^2.1.0", 
"protractor": "3.0.0", 
"protractor-cucumber-framework": "^0.3.2", 
"selenium-standalone": "4.8.0", 

$ node --version 
v5.3.0 
$ npm --version 
3.5.2 

我咕嘟咕嘟,量角器樣子:

/** 
* run protractor 
*/ 


var args = require('yargs').argv; 


module.exports = function(gulp, plugins) { 
    return function (done) { 
     var protractorConfig = '', 
      testConfig = '', 
      environment = args.environment || 'devel', 
      tag = args.tag || '@Sanity', 
      baseUrl; 

     if (!args.baseUrl) { 
      baseUrl = 'http://test.me/frontend-build-tests/'; 
     } else if (args.baseUrl.match(/^(?:https?\:)?\/\//)) { 
      baseUrl = args.baseUrl; 
     } else { 
      baseUrl = 'http://test.me/frontend-build-tests/' + args.baseUrl + '/'; 
     } 

     switch(environment) { 
      case 'devel' : 
       protractorConfig = 'e2e/protractor.config.devel.js'; 
       testConfig = '../config/devel'; 
      break; 
      case 'live' : 
       protractorConfig = 'e2e/protractor.config.live.js'; 
       testConfig = '../config/live'; 
      break; 
      case 'remote' : 
       protractorConfig = 'e2e/protractor.config.remote.js'; 
       testConfig = '../config/live'; 
      break; 
      default: 
      case 'build' : 
       protractorConfig = 'e2e/protractor.config.build.js'; 
       testConfig = '../config/build'; 
      break; 
     } 

     gulp.src([ 
      'e2e/features/*.feature' 
     ]) 
     .pipe(plugins.protractor.protractor({ 
      configFile: protractorConfig, 
      args: [ 
       '--verbose', 
       '--no-stackTrace', 
       '--params.test.config', testConfig, 
       '--baseUrl', baseUrl, 
       '--cucumberOpts.tags', tag 
      ] 
     })) 
     //.on('end', function(){ 
     //  console.log('E2E Testing complete'); 
     //  process.exit(); 
     // }) 
     .on('error', function() { 
      done(); 
       //protractor.driver.quit(); 
       process.exit(1); 
       //var protractor = require("gulp-protractor").protractor; 
       //console.log("ON Error"); 
       //protractor.browser.quit(); 
       //throw e; 

      }); 
    }; 
}; 

而且我protractor.config有:

exports.config = { 
    //seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.47.1.jar', 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    //directConnect: true,//To run test directly against Chrome/FFs 
    specs: [ 
     'e2e/features/*.feature' 
    ], 
    multiCapabilities: [ 
     { 
      'browserName': 'chrome', 
      'chromeOptions': { 
       'args': ['show-fps-counter=true','enable-logging','v=1','net-log-level=0'] 
      } 
     }, 
     // { 
     // 'browserName': 'firefox' 
     // }, 
     // { 
     // 'browserName': 'safari' 
     // }, 
     // { 
     // 'browserName': 'phantomjs', 
     // 'phantomjs.binary.path':'./node_modules/phantomjs/bin/phantomjs', 
     // 'phantomjs.cli.args':'--debug=true --loglevel=DEBUG --webdriver --webdriver-loglevel=DEBUG' 
     // } 
    ], 
    framework: 'custom', 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    cucumberOpts: { 
     require: 'features/step_definitions/**/*.js', 
     format: 'json' 
     //tags: "@Sanity" 

    }, 

    resultJsonOutputFile: 'report.json', 
    //count: 2, 
    //shardTestFiles: true, 
    //maxInstances:2, 

    onPrepare: function() { 

     browser.getCapabilities().then(function (capabilities) { 
      browser.capabilities = capabilities; 
     }); 
     browser.driver.manage().window().maximize(); 

     browser.ignoreSynchronization = true; //This is set for non-Angular apps 

     browser.manage().timeouts().implicitlyWait(20000); 


    } 
    //, 
    //onCleanUp: function(exitCode) { 
    // if (exitCode ==1){ 
    //  console.log("Getting out"); 
    //  browser.quit(); 
    // }; 
    //}, 
}; 

測試失敗,瀏覽器保持打開狀態,這在CI服務器上導致內存泄漏!我需要做些什麼來解決這個問題?

請幫助!

編輯 我失敗的步驟是這樣的:

this.Then(/^I see that the slider has moved/, function (done) { 
    browser.sleep(500); 
    sliderWidgetPage.getImageAndAttribute(0,'data-url').then(function (attrVal) { 
     expect(attrAtX1Time).to.eventually.not.be.equal(attrVal); 

    }); 
    done(); 
}); 

回答

相關問題