Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop automatically closing browser when writing protractor test cases

Tags:

protractor

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() {

        });
      });
like image 776
Balu Avatar asked Mar 11 '16 06:03

Balu


1 Answers

I was also struggling with a similar issue where i had a test case flow where we were interacting with multiple application and when using Protractor the browser was closing after executing one conf.js file. Now when I looked into the previous response it was like adding delay which depends on how quick your next action i performed or it was hit or miss case. Even if we think from debugging perspective most of the user would be performing overnight runs and they would want to have browser active for couple of hours before they analyze the issue. So I started looking into the protractor base code and came across a generic solution which can circumvent this issue, independent of any browser. Currently the solution is specific to requirement that browser should not close after one conf.js file is executed, then could be improved if someone could add a config parameter asking the user whether they want to close the browser after their run.

The browser could be reused for future conf.js file run by using tag --seleniumSessionId in command line.

Solution:

  • Go to ..\AppData\Roaming\npm\node_modules\protractor\built where your protractor is installed.
  • Open driverProvider.js file and go to function quitDriver
  • Replace return driver.quit() by return 0

As far as my current usage there seems to be no side effect of the code change, will update if I came across any other issue due to this change. Snapshot of code snippet below.

Thanks Gleeson

Snapshot of code snippet: Snapshot of code snippet

like image 182
Gleeson Avatar answered Oct 25 '22 21:10

Gleeson