How to close my browser after each test in a suite for protractor?

SUPARNA SOMAN picture SUPARNA SOMAN · May 11, 2017 · Viewed 11.2k times · Source

I was trying to run my tests as a suite. There are three tests in a suite, how can I make my browser close after each test ?

suites:
        {
          one: 'one.js',
          two: 'two.js',
          three: 'three.js'
        };

The problem is that each of this test is used to load a separate url, and each test checks whether the correct url is loaded. But my test fails each time as all the urls are different.

Answer

hitesh jani picture hitesh jani · May 12, 2017

You can use below method in you spec.js

afterEach(() => {
         browser.close(); (or browser.driver.close();)
        console.log('afterEach');
    });