量角器+ CucumberJS + Gulp-Protractor =当测试失败时,浏览器不会关闭

时间:2015-12-29 15:06:28

标签: javascript selenium cucumber protractor 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

我的Gulp-protractor看起来像:

/**
 * 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();
});

1 个答案:

答案 0 :(得分:1)

也许你需要把它写成......

.be.equal(attrVal).notify(done)

https://github.com/domenic/chai-as-promised/blob/master/README.md