I'am running an E2E test for an angular app. I did edit the protractor.conf.js in order to use SeleniumStandalone. It looks good, and I can run the test using: ng e2e.

protractor.conf.js:

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
    // location of the Selenium JAR file and chromedriver, use these if you installed protractor locally
    seleniumServerJar: './node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.8.1.jar',
    chromeDriver: './node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.34',
    seleniumPort: '4444',
    allScriptsTimeout: 11000,

    capabilities: {
        browserName: 'chrome',
        name: 'Unnamed Job',
        specs: ['./e2e/**/*.e2e-spec.ts']
    },
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000,
        print: function() {}
    },
    onPrepare() {
        require('ts-node').register({
            project: 'e2e/tsconfig.e2e.json'
        });
        jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
    }
};

My issue is that selenium server get shut down automatically and immediately after the test is done. How to prevent this behavior? Is there an option to add in protractor.conf.js to fix this?

Here is the output in terminal after I run: ng e2e:

webpack: Compiled successfully.
[16:10:36] I/update - chromedriver: file exists /Users/kvincent/PROJECT - DECEMBER/UserApp/19_12-t-04_16/consumer-app/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.34.zip
[16:10:36] I/update - chromedriver: unzipping chromedriver_2.34.zip
[16:10:36] I/update - chromedriver: setting permissions to 0755 for /Users/kvincent/PROJECT - DECEMBER/UserApp/19_12-t-04_16/consumer-app/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.34
[16:10:36] I/update - chromedriver: chromedriver_2.34 up to date
[16:10:36] I/launcher - Running 1 instances of WebDriver
[16:10:36] I/local - Starting selenium standalone server...
[16:10:37] I/local - Selenium standalone server started at http://192.168.0.4:4444/wd/hub
Jasmine started

Executed 0 of 0 specs SUCCESS in 0.003 sec.
[16:10:38] I/local - Shutting down selenium standalone server.
[16:10:38] I/launcher - 0 instance(s) of WebDriver still running
[16:10:38] I/launcher - chrome #01 passed
aminkasbi@Amins-MacBook-Pro.local:~/PROJECT - DECEMBER/UserApp/19_12-t-04_16/consumer-app$

As you can see in the following line: [16:10:38] I/local - Shutting down selenium standalone server. the selenium-standalone is being shut down and it looks like it's a normal behavior.

up vote 4 down vote accepted

Shutting Selenium is useful default for headless testing. I am not familiar with Protractor, but there should be a configuration parameter to keep browser open after run. And why you want browser to hang around after test, especially successful test?

  • Great hints and helpful answers! I'll go for the headless testing as I don't need a browser hanging around as Peter Masiar said. – k.vincent Dec 22 '17 at 17:25

When you are specifying seleniumServerJar and seleniumPort you are instructing protractor to take care of controlling a selenium server. Protractor would then start it as a child process before executing your tests and then shut it down after.

If you want it to connect to running Selenium server, use seleniumAddress configuration option instead - Protractor would then try to connect to this running selenium server instead.

  • Agree. I had this option before: seleniumAddress: 'http://localhost:4444/wd/hub', I started the selenium server from terminal: webdriver-manager start and was able to reach it. I did run the test: ng e2e and terminal says: [09:14:19] I/hosted - Using the selenium server at http://localhost:4444/wd/hub Jasmine started Executed 0 of 0 specs SUCCESS in 0.003 sec. [09:14:21] I/launcher - 0 instance(s) of WebDriver still running. But I might be a kind of confused as I'am expecting to see the output also on: http://localhost:4444/wd/hub/static/resource/hub.html, but it' still blank – k.vincent Dec 22 '17 at 8:22

Since Protractor is a test framework build on top of WebdriverJS, Protractor handles certain aspects of the webdriver for you. For example, it automatically starts a browser (no need to call something like driver = builder.build()) and automatically closes a browser (no need to call driver.quit()). Protractor makes the decision to close a browser/end a session at the end of a test suite for you. Other answers have mentioned that the conf.js file allows you to choose where your Webdriver instance connects to or how the browser is started up.

However, there are some helpful setup/teardown utilities such as onComplete() that allow execution of actions at various stages before and after a test suite.

  • Great! good one. The reference is helpful... helps me to understand what‘s really happens behind the scenes when unsing beforeEach, afterEach etc. – k.vincent Dec 28 '17 at 21:11

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.