Search code examples
javascriptseleniumcucumberprotractorgulp-protractor

Protractor + CucumberJS + Gulp-Protractor = When test fails browser does not get closed


Hi!

I'm dealing when trying to close the browser once the test had failed, currently, when it passes it does get closed.

I'm using

"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

My Gulp-protractor looks like:

/**
 * 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;

            });
    };
};

And my protractor.config has:

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

The tests fails, and the browser remains open, this on the CI server causes memory leaks! what do I have to do to solve this?

Please help!!

EDIT my failing step looks like:

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

Solution

  • Maybe you need to write it like...

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

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