How to stop automatically closing browser when writing protractor test cases

Viewed 18994

I am new to writing test cases using protractor for non angular application. I wrote a sample test case.Here the browser closes automatically after running test case.How can I prevent this. Here is my code

var submitBtnElm = $('input[data-behavior=saveContribution]');

      it('Should Search', function() {
        browser.driver.get('http://localhost/enrollments/osda1.html');   
        browser.driver.findElement(by.id('contributePercentValue')).sendKeys(50);
        submitBtnElm.click().then(function() {

        });
      });
9 Answers

I found Gleeson's solution is working, and that really helped me. The solution was...

  1. Go to %APPDATA%Roaming\npm\node_modules\protractor\built\driverProviders\
  2. Find driverProviders.js
  3. Open it in notepad or any other text editor
  4. Find and Replace return driver.Quit() to return 0
  5. Save the file

Restart your tests after that.

I am using node v8.12.0 npm v6.4.1 protractor v5.4.1

This solution will work, only if you installed npm or protractor globally; if you have installed your npm or protractor locally (in your folder) then, you have to go to your local protractor folder and do the same.

Protractor will close browsers, that it created, so an approach that I am using is to start the browser via the webdriver-reuse-session npm package.

DISCLAIMER: I am the author of this package

It is a new package, so let me know if it solves your problem. I am using it with great success.

Related