how to close selenium webdriver at end of test?

2019-08-02 07:50发布

问题:

I have created a e2e test for my angular app. I would like to close down the selenium webdriver at the end of the test:

describe('Selenium end', function () {
    it("close down selenium server", function () {
        browser.get('http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
        var text = element(by.css('pre')).getText(function (text) {
            expect(text).toEqual('OKOK');
        });
    });
});

When I run this i get:

 Message:     Error: Error while running testForAngular: ECONNREFUSED connect ECONNREFUSED

How can I stop the selenium webdriver or assert it is closed based on the info above?

回答1:

Protractor can start up and shut down a selenium server for you, if you use the seleniumServerJar and seleniumPort fields in the configuration file. See https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L23