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

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

本文关键字:浏览器 Protractor 测试 失败 Protractor+CucumberJS+Gulp      更新时间:2023-09-26

我正在处理测试失败后试图关闭浏览器的问题,目前,当它通过时,它确实会关闭。

我正在使用

"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量角器看起来像:

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

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

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

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