How to stop automatically closing browser when wri

2019-03-18 15:32发布

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

        });
      });

标签: protractor
8条回答
不美不萌又怎样
2楼-- · 2019-03-18 16:29

I'm sure there is a change triggered on your page by the button click. It might be something as subtle as a class change on an element or as obvious as a <p></p> element with the text "Saved" displayed. What I would do is, after the test, explicitly wait for this change.

[...]
return protractor.browser.wait(function() {
    return element(by.cssContainingText('p', 'Saved')).isPresent();
}, 10000);

You could add such a wait mechanism to the afterEach() method of your spec file, so that your tests are separated even without the Protractor Angular implicit waits.

查看更多
干净又极端
3楼-- · 2019-03-18 16:29

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.

查看更多
登录 后发表回答